Skip to content

Commit 90fb5c9

Browse files
author
Daniel Mackey
committed
Provide list of previous carrier lookups
1 parent f6f9ef8 commit 90fb5c9

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

lib/telapi/carrier.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ module Telapi
33
class Carrier < Resource
44
class << self
55

6+
# Returns a resource collection containing Telapi::Carrier objects
7+
# See http://docs.telapi.com/v2/docs/carrier-lookup-list
8+
#
9+
# Optional params is a hash containing:
10+
# +Page+:: integer greater than 0
11+
# +PageSize+:: integer greater than 0
12+
def list(optional_params = {})
13+
response = Network.get(['Lookups', 'Carrier'], optional_params)
14+
ResourceCollection.new(response, 'carrier_lookups', self)
15+
end
16+
617
# Returns a Telapi::Carrier object given a phone number
718
# See http://www.telapi.com/docs/api/rest/carrier-services/carrier-lookup/
819
def lookup(phone_number)
@@ -13,4 +24,4 @@ def lookup(phone_number)
1324

1425
end
1526
end
16-
end
27+
end

spec/telapi/carrier_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,27 @@
88

99
it { should be_kind_of(Telapi::Resource) }
1010

11+
describe ".list" do
12+
before { stub_telapi_request('{ "carrier_lookups": [] }') }
13+
14+
it "calls api via http get and returns a ResourceCollection" do
15+
api_should_use(:get)
16+
klass.list.should be_a(Telapi::ResourceCollection)
17+
end
18+
19+
context "when Carrier lookups exist" do
20+
before { stub_telapi_request('{ "carrier_lookups": [{ "phone_number": "+17325551234" }] }') }
21+
22+
it "has a collection of Carrier Lookup objects" do
23+
klass.list.first.should be_a(klass)
24+
end
25+
end
26+
end
27+
1128
describe ".lookup" do
1229
it "calls api via http get and returns a Carrier resource" do
1330
api_should_use(:get)
1431
klass.lookup('17325551234').should be_a(klass)
1532
end
1633
end
17-
end
34+
end

0 commit comments

Comments
 (0)