diff --git a/lib/telapi/carrier.rb b/lib/telapi/carrier.rb index 46ec3fc..22a957d 100644 --- a/lib/telapi/carrier.rb +++ b/lib/telapi/carrier.rb @@ -3,11 +3,22 @@ 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/ + # 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 ca67655..5477278 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 ".lookup" do - it "calls api via http get and returns a Carrier resource" do + 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 post and returns a Carrier resource" do + api_should_use(:post) klass.lookup('17325551234').should be_a(klass) end end -end \ No newline at end of file +end