Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/telapi/carrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 20 additions & 3 deletions spec/telapi/carrier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end