From 55138b7f9dc2169293b621a33060f313c27e5d69 Mon Sep 17 00:00:00 2001 From: Daniel Mackey Date: Mon, 23 Feb 2015 15:58:52 -0600 Subject: [PATCH 1/3] Provide list of previous carrier lookups --- lib/telapi/carrier.rb | 11 +++++++++++ spec/telapi/carrier_spec.rb | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/telapi/carrier.rb b/lib/telapi/carrier.rb index 46ec3fc..f0fb713 100644 --- a/lib/telapi/carrier.rb +++ b/lib/telapi/carrier.rb @@ -3,6 +3,17 @@ module Telapi class Carrier < Resource class << self + # Returns a resource collection containing Telapi::Carrier objects + # See http://docs.telapi.com/v2/docs/carrier-lookup-list + # + # Optional params is a hash containing: + # +Page+:: integer greater than 0 + # +PageSize+:: integer greater than 0 + def list(optional_params = {}) + response = Network.get(['Lookups', 'Carrier'], optional_params) + ResourceCollection.new(response, 'carrier_lookups', self) + end + # Returns a Telapi::Carrier object given a phone number # See http://www.telapi.com/docs/api/rest/carrier-services/carrier-lookup/ def lookup(phone_number) diff --git a/spec/telapi/carrier_spec.rb b/spec/telapi/carrier_spec.rb index ca67655..b831733 100644 --- a/spec/telapi/carrier_spec.rb +++ b/spec/telapi/carrier_spec.rb @@ -8,10 +8,27 @@ it { should be_kind_of(Telapi::Resource) } + describe ".list" do + before { stub_telapi_request('{ "carrier_lookups": [] }') } + + it "calls api via http get and returns a ResourceCollection" do + api_should_use(:get) + klass.list.should be_a(Telapi::ResourceCollection) + end + + context "when Carrier lookups exist" do + before { stub_telapi_request('{ "carrier_lookups": [{ "phone_number": "+17325551234" }] }') } + + it "has a collection of Carrier Lookup objects" do + klass.list.first.should be_a(klass) + end + end + end + describe ".lookup" do it "calls api via http get and returns a Carrier resource" do api_should_use(:get) klass.lookup('17325551234').should be_a(klass) end end -end \ No newline at end of file +end From 5146a325ff910cb4732c31e4dc061e7b12fd7df8 Mon Sep 17 00:00:00 2001 From: Daniel Mackey Date: Mon, 23 Feb 2015 16:00:53 -0600 Subject: [PATCH 2/3] Use #post, and include 'Lookups' in path for creating a lookup The API docs provided use 'Lookups' as part of the path, and use the POST method. --- lib/telapi/carrier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/telapi/carrier.rb b/lib/telapi/carrier.rb index f0fb713..4f73bde 100644 --- a/lib/telapi/carrier.rb +++ b/lib/telapi/carrier.rb @@ -15,7 +15,7 @@ def list(optional_params = {}) end # Returns a Telapi::Carrier object given a phone number - # See http://www.telapi.com/docs/api/rest/carrier-services/carrier-lookup/ + # See http://docs.telapi.com/v2/docs/carrier-lookup def lookup(phone_number) opts = { :PhoneNumber => phone_number } response = Network.get(['Lookups','Carrier'], opts) From 16365744d9bc56fbdfc628918cee6fd22fba17fe Mon Sep 17 00:00:00 2001 From: Daniel Mackey Date: Mon, 23 Feb 2015 16:51:38 -0600 Subject: [PATCH 3/3] Telapi::Carrier.lookup should be a POST request, not a GET request POST will create a new lookup based on the provided phone number. GET will return all previous carrier lookups --- lib/telapi/carrier.rb | 2 +- spec/telapi/carrier_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/telapi/carrier.rb b/lib/telapi/carrier.rb index 4f73bde..22a957d 100644 --- a/lib/telapi/carrier.rb +++ b/lib/telapi/carrier.rb @@ -18,7 +18,7 @@ def list(optional_params = {}) # See http://docs.telapi.com/v2/docs/carrier-lookup def lookup(phone_number) opts = { :PhoneNumber => phone_number } - response = Network.get(['Lookups','Carrier'], opts) + response = Network.post(['Lookups','Carrier'], opts) Carrier.new(response) end diff --git a/spec/telapi/carrier_spec.rb b/spec/telapi/carrier_spec.rb index b831733..5477278 100644 --- a/spec/telapi/carrier_spec.rb +++ b/spec/telapi/carrier_spec.rb @@ -26,8 +26,8 @@ end describe ".lookup" do - it "calls api via http get and returns a Carrier resource" do - api_should_use(:get) + it "calls api via http post and returns a Carrier resource" do + api_should_use(:post) klass.lookup('17325551234').should be_a(klass) end end