Skip to content

Commit f8236ca

Browse files
singpolymackoegel
andauthored
Allow listing port-ins, and getting the TNs for a port-in (#65)
* Allow listing port-ins, and getting the TNs for a port-in * add test for new `list` portins * add example and snippet to README * update version Co-authored-by: Cameron Koegel <[email protected]>
1 parent 214d81f commit f8236ca

File tree

8 files changed

+89
-2
lines changed

8 files changed

+89
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ order.get_notes()
387387
```
388388

389389
## Port Ins
390+
391+
### List Portins
392+
```ruby
393+
page = BandwidthIris::PortIn.list(client, {'page': 1, 'size': 5})
394+
```
390395
### Create PortIn
391396
```ruby
392397
data = {

examples/portin_list.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
lib = File.expand_path('../../lib', __FILE__)
2+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3+
4+
require 'yaml'
5+
require 'ruby-bandwidth-iris'
6+
config = YAML.load_file('config.yml')
7+
8+
BandwidthIris::Client.global_options = {
9+
:api_endpoint => config['api_endpoint'],
10+
:user_name => config['user_name'],
11+
:password => config['password'],
12+
:account_id => config['account_id']
13+
}
14+
15+
@portins = Array.new # All portins on the account will be stored in this array
16+
page = BandwidthIris::PortIn.list({'page': 1, 'size': 5}) # Get the first page of paginated portin results
17+
18+
def get_portins(page) # Recursively check for more pages of results and populate array with portins from current page
19+
page.each do |portin|
20+
@portins.push(portin)
21+
end
22+
unless page.next.nil?
23+
get_portins(page.next)
24+
end
25+
end
26+
27+
get_portins(page)
28+
puts "Total Port-Ins: #{@portins.length()}" # Print total number of portins on account
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require "delegate"
2+
3+
module BandwidthIris
4+
class PaginatedResult < SimpleDelegator
5+
def initialize(items, links, &block)
6+
super(items)
7+
@links = links
8+
@requestor = block
9+
end
10+
11+
def next
12+
return unless @links[:next]
13+
14+
@requestor.call(@links[:next].match(/\<([^>]+)\>/)[1].sub(/^http.*\/v1.0/, ""))
15+
end
16+
end
17+
end

lib/bandwidth-iris/port_in.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ def self.create(client, item)
1313
end
1414
wrap_client_arg :create
1515

16+
def self.list_from_page_url(client, url, query=nil)
17+
response = client.make_request(:get, url, query)[0]
18+
items = response[:lnp_port_info_for_given_status]
19+
items = items.is_a?(Array) ? items : [items]
20+
PaginatedResult.new(
21+
items.map { |item| PortIn.new(item, client) },
22+
response[:links]
23+
) do |next_url|
24+
list_from_page_url(client, next_url)
25+
end
26+
end
27+
28+
def self.list(client, query=nil)
29+
list_from_page_url(client, client.concat_account_path(PORT_IN_PATH), query)
30+
end
31+
wrap_client_arg :list
32+
33+
def tns
34+
Array(@client.make_request(:get, "#{@client.concat_account_path(PORT_IN_PATH)}/#{order_id}/tns")[0][:telephone_number])
35+
end
1636

1737
def update(data)
1838
@client.make_request(:put,"#{@client.concat_account_path(PORT_IN_PATH)}/#{id}", {:lnp_order_supp => data})

lib/bandwidth-iris/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module BandwidthIris
22
# Version of this gem
3-
VERSION = "5.0.0"
3+
VERSION = "5.1.0"
44
end

lib/ruby-bandwidth-iris.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require 'bandwidth-iris/lnp_checker'
1818
require 'bandwidth-iris/lsr_order'
1919
require 'bandwidth-iris/order'
20+
require 'bandwidth-iris/paginated_result'
2021
require 'bandwidth-iris/port_in'
2122
require 'bandwidth-iris/port_out'
2223
require 'bandwidth-iris/rate_center'

spec/bandwidth-iris/port_in_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
client.stubs.verify_stubbed_calls()
1010
end
1111

12+
describe '#list_orders' do
13+
it 'should list port in orders' do
14+
client.stubs.get('/v1.0/accounts/accountId/portins') {|env| [200, {}, Helper.xml['port_ins']]}
15+
orders = PortIn.list(client)
16+
orders.each do |order|
17+
expect(order.class).to eql(BandwidthIris::PortIn)
18+
end
19+
expect(orders[0][:order_id]).to eql("ab03375f-e0a9-47f8-bd31-6d8435454a6b")
20+
expect(orders[1][:order_id]).to eql("b2190bcc-0272-4a51-ba56-7c3d628e8706")
21+
expect(orders[0][:lnp_losing_carrier_id]).to eql(1163)
22+
expect(orders[1][:lnp_losing_carrier_id]).to eql(1290)
23+
expect(orders[0][:last_modified_date]).to eql(DateTime.new(2020, 1, 15, 19, 8, 57.626))
24+
expect(orders[1][:last_modified_date]).to eql(DateTime.new(2020, 1, 15, 19, 6, 10.085))
25+
end
26+
end
27+
1228
describe '#create' do
1329
it 'should create an order' do
1430
data = {

spec/xml.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
tn_reservation: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ReservationResponse><Reservation><ReservationId>e34474d6-1d47-486d-af32-be9f2eefdff4</ReservationId><AccountId>111</AccountId><ReservationExpires>13157</ReservationExpires><ReservedTn>9198975719</ReservedTn></Reservation></ReservationResponse>"
2121
tn_details: "<TelephoneNumberResponse><TelephoneNumberDetails><City>JERSEY CITY</City><Lata>224</Lata><State>NJ</State><FullNumber>2018981023</FullNumber><Tier>0</Tier><VendorId>49</VendorId><VendorName>Bandwidth CLEC</VendorName><RateCenter>JERSEYCITY</RateCenter><Status>Inservice</Status><AccountId>14</AccountId><LastModified>2014-07-30T11:29:37.000Z</LastModified><Features><E911><Status>Success</Status></E911><Lidb><Status>Pending</Status><SubscriberInformation>Fred</SubscriberInformation><UseType>BUSINESS</UseType><Visibility>PUBLIC</Visibility></Lidb><Dlda><Status>Success</Status><SubscriberType>BUSINESS</SubscriberType><ListingType>LISTED</ListingType><ListingName><FirstName>Joe</FirstName><LastName>Smith</LastName></ListingName><ListAddress>true</ListAddress><Address><HouseNumber>12</HouseNumber><StreetName>ELM</StreetName><City>New York</City><StateCode>NY</StateCode><Zip>10007</Zip><Country>United States</Country><AddressType>Dlda</AddressType></Address></Dlda></Features><TnAttributes><TnAttribute>Protected</TnAttribute></TnAttributes></TelephoneNumberDetails></TelephoneNumberResponse>"
2222
port_in: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><LnpOrderResponse><OrderId>d28b36f7-fa96-49eb-9556-a40fca49f7c6</OrderId><Status><Code>201</Code><Description>Order request received. Please use the order id to check the status of your order later.</Description></Status><ProcessingStatus>PENDING_DOCUMENTS</ProcessingStatus><LoaAuthorizingPerson>John Doe</LoaAuthorizingPerson><Subscriber><SubscriberType>BUSINESS</SubscriberType><BusinessName>Acme Corporation</BusinessName><ServiceAddress><HouseNumber>1623</HouseNumber><StreetName>Brockton Ave #1</StreetName><City>Los Angeles</City><StateCode>CA</StateCode><Zip>90025</Zip><Country>USA</Country></ServiceAddress></Subscriber><BillingTelephoneNumber>6882015002</BillingTelephoneNumber><ListOfPhoneNumbers><PhoneNumber>6882015025</PhoneNumber><PhoneNumber>6882015026</PhoneNumber></ListOfPhoneNumbers><Triggered>false</Triggered><BillingType>PORTIN</BillingType></LnpOrderResponse>"
23+
port_ins: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><LNPResponseWrapper><TotalCount>2</TotalCount><Links><first>Link=&lt;https://test.dashboard.bandwidth.com:443/v1.0/accounts/9900012/portins?page=1&amp;size=10&amp;date=2020-01-15&amp;status=foc&gt;;rel=\"first\";</first></Links><lnpPortInfoForGivenStatus><accountId>9900012</accountId><CountOfTNs>1</CountOfTNs><userId>System</userId><lastModifiedDate>2020-01-15T19:08:57.626Z</lastModifiedDate><OrderDate>2020-01-15T19:08:10.488Z</OrderDate><OrderId>ab03375f-e0a9-47f8-bd31-6d8435454a6b</OrderId><OrderType>port_in</OrderType><ActualFOCDate>2020-01-16T16:30:00.000Z</ActualFOCDate><BillingTelephoneNumber>9196247209</BillingTelephoneNumber><CompanyName>WandEDemo</CompanyName><LNPLosingCarrierId>1163</LNPLosingCarrierId><LNPLosingCarrierName>Bandwidth</LNPLosingCarrierName><ProcessingStatus>FOC</ProcessingStatus><RequestedFOCDate>2020-01-16T16:30:00.000Z</RequestedFOCDate><VendorId>49</VendorId><VendorName>Bandwidth CLEC</VendorName><PON>4c129d8e-57fc-4ccb-a37d-7f21aca8b32d</PON></lnpPortInfoForGivenStatus><lnpPortInfoForGivenStatus><accountId>9900012</accountId><CountOfTNs>1</CountOfTNs><userId>gforrest</userId><lastModifiedDate>2020-01-15T19:06:10.085Z</lastModifiedDate><OrderDate>2019-10-14T17:16:41.949Z</OrderDate><OrderId>b2190bcc-0272-4a51-ba56-7c3d628e8706</OrderId><OrderType>port_in</OrderType><ActualFOCDate>2020-01-16T01:00:00.000Z</ActualFOCDate><BillingTelephoneNumber>2174101100</BillingTelephoneNumber><CompanyName>WandEDemo</CompanyName><LNPLosingCarrierId>1290</LNPLosingCarrierId><LNPLosingCarrierName>IntegraTelecom</LNPLosingCarrierName><ProcessingStatus>FOC</ProcessingStatus><RequestedFOCDate>2020-01-21T17:30:00.000Z</RequestedFOCDate><VendorId>57</VendorId><VendorName>Level 3</VendorName><PON>979E019287CDF6A1</PON></lnpPortInfoForGivenStatus></LNPResponseWrapper>"
2324
notes: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Notes><Note><Id>11299</Id><UserId>customer</UserId><Description>Test</Description><LastDateModifier>2014-11-20T07:08:47.000Z</LastDateModifier></Note><Note><Id>11301</Id><UserId>customer</UserId><Description>Test1</Description><LastDateModifier>2014-11-20T07:11:36.000Z</LastDateModifier></Note></Notes>"
2425
files: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><fileListResponse><fileCount>6</fileCount><fileData><FileName>d28b36f7-fa96-49eb-9556-a40fca49f7c6-1416231534986.txt</FileName><FileMetaData><DocumentType>LOA</DocumentType></FileMetaData></fileData><fileData><FileName>d28b36f7-fa96-49eb-9556-a40fca49f7c6-1416231558768.txt</FileName><FileMetaData><DocumentType>LOA</DocumentType></FileMetaData></fileData><fileData><FileName>d28b36f7-fa96-49eb-9556-a40fca49f7c6-1416231581134.txt</FileName><FileMetaData><DocumentType>LOA</DocumentType></FileMetaData></fileData><fileData><FileName>d28b36f7-fa96-49eb-9556-a40fca49f7c6-1416231629005.txt</FileName><FileMetaData><DocumentType>LOA</DocumentType></FileMetaData></fileData><fileData><FileName>d28b36f7-fa96-49eb-9556-a40fca49f7c6-1416231699462.txt</FileName><FileMetaData><DocumentType>LOA</DocumentType></FileMetaData></fileData><fileData><FileName>d28b36f7-fa96-49eb-9556-a40fca49f7c6-1416232756923.txt</FileName><FileMetaData><DocumentType>LOA</DocumentType></FileMetaData></fileData><resultCode>0</resultCode><resultMessage>LOA file list successfully returned</resultMessage></fileListResponse>"
2526
file_metadata: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><FileMetaData><DocumentType>LOA</DocumentType></FileMetaData>"
@@ -40,7 +41,6 @@
4041
users: "<?xml version=\"1.0\"?><UsersResponse><Users><User><Username>testcustomer</Username><FirstName>Jane</FirstName><LastName>Doe</LastName><EmailAddress>[email protected]</EmailAddress><TelephoneNumber>9199999999</TelephoneNumber></User><User><Username>johndoe</Username><FirstName>John</FirstName><LastName>Doe</LastName><EmailAddress>[email protected]</EmailAddress><TelephoneNumber>9199999998</TelephoneNumber></User></Users></UsersResponse>"
4142
dldas: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><ResponseSelectWrapper><ListOrderIdUserIdDate><TotalCount>3</TotalCount><OrderIdUserIdDate><accountId>14</accountId><CountOfTNs>2</CountOfTNs><userId>team_ua</userId><lastModifiedDate>2014-07-07T10:06:43.427Z</lastModifiedDate><OrderType>dlda</OrderType><OrderDate>2014-07-07T10:06:43.427Z</OrderDate><orderId>37a6447c-1a0b-4be9-ba89-3f5cb0aea142</orderId><OrderStatus>FAILED</OrderStatus></OrderIdUserIdDate><OrderIdUserIdDate><accountId>14</accountId><CountOfTNs>2</CountOfTNs><userId>team_ua</userId><lastModifiedDate>2014-07-07T10:05:56.595Z</lastModifiedDate><OrderType>dlda</OrderType><OrderDate>2014-07-07T10:05:56.595Z</OrderDate><orderId>743b0e64-3350-42e4-baa6-406dac7f4a85</orderId><OrderStatus>RECEIVED</OrderStatus></OrderIdUserIdDate><OrderIdUserIdDate><accountId>14</accountId><CountOfTNs>2</CountOfTNs><userId>team_ua</userId><lastModifiedDate>2014-07-07T09:32:17.234Z</lastModifiedDate><OrderType>dlda</OrderType><OrderDate>2014-07-07T09:32:17.234Z</OrderDate><orderId>f71eb4d2-bfef-4384-957f-45cd6321185e</orderId><OrderStatus>RECEIVED</OrderStatus></OrderIdUserIdDate></ListOrderIdUserIdDate></ResponseSelectWrapper>"
4243
dlda: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><DldaOrderResponse><DldaOrder><CustomerOrderId>5a88d16d-f8a9-45c5-a5db-137d700c6a22</CustomerOrderId><OrderCreateDate>2014-07-10T12:38:11.833Z</OrderCreateDate><AccountId>14</AccountId><CreatedByUser>jbm</CreatedByUser><OrderId>ea9e90c2-77a4-4f82-ac47-e1c5bb1311f4</OrderId><LastModifiedDate>2014-07-10T12:38:11.833Z</LastModifiedDate><ProcessingStatus>RECEIVED</ProcessingStatus><DldaTnGroups><DldaTnGroup><TelephoneNumbers><TelephoneNumber>2053778335</TelephoneNumber><TelephoneNumber>2053865784</TelephoneNumber></TelephoneNumbers><AccountType>BUSINESS</AccountType><ListingType>LISTED</ListingType><ListingName><FirstName>Joe</FirstName><LastName>Smith</LastName></ListingName><ListAddress>true</ListAddress><Address><HouseNumber>12</HouseNumber><StreetName>ELM</StreetName><City>New York</City><StateCode>NY</StateCode><Zip>10007</Zip><Country>United States</Country><AddressType>Dlda</AddressType></Address></DldaTnGroup></DldaTnGroups></DldaOrder></DldaOrderResponse>"
43-
order_history: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><OrderHistoryWrapper><OrderHistory><OrderDate>2014-05-20T14:21:43.937Z</OrderDate><Note>Order backordered - awaiting additional numbers</Note><Status>BACKORDERED</Status></OrderHistory><OrderHistory><OrderDate>2014-05-20T14:24:43.428Z</OrderDate><Note>Order backordered - awaiting additional numbers</Note><Author>System</Author><Status>BACKORDERED</Status><Difference></Difference></OrderHistory></OrderHistoryWrapper>"
4444
in_service_numbers: "<?xml version=\"1.0\"?><TNs><TotalCount>59</TotalCount><Links><first> ( a link goes here ) </first></Links><TelephoneNumbers><Count>59</Count><TelephoneNumber>8043024183</TelephoneNumber><TelephoneNumber>8042121778</TelephoneNumber><TelephoneNumber>8042146066</TelephoneNumber><TelephoneNumber>8043814903</TelephoneNumber><TelephoneNumber>8043814905</TelephoneNumber><TelephoneNumber>8043814864</TelephoneNumber><TelephoneNumber>8043326094</TelephoneNumber><TelephoneNumber>8042121771</TelephoneNumber><TelephoneNumber>8043024182</TelephoneNumber><!-- SNIP --><TelephoneNumber>8043814900</TelephoneNumber><TelephoneNumber>8047672642</TelephoneNumber><TelephoneNumber>8043024368</TelephoneNumber><TelephoneNumber>8042147950</TelephoneNumber><TelephoneNumber>8043169931</TelephoneNumber><TelephoneNumber>8043325302</TelephoneNumber></TelephoneNumbers></TNs>"
4545
in_service_numbers_totals: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Quantity><Count>3</Count></Quantity>"
4646
lidbs: "<?xml version=\"1.0\"?><ResponseSelectWrapper><ListOrderIdUserIdDate><TotalCount>2122</TotalCount><OrderIdUserIdDate><accountId>9999999</accountId><CountOfTNs>0</CountOfTNs><lastModifiedDate>2014-02-25T16:02:43.195Z</lastModifiedDate><OrderType>lidb</OrderType><OrderDate>2014-02-25T16:02:43.195Z</OrderDate><orderId>abe36738-6929-4c6f-926c-88e534e2d46f</orderId><OrderStatus>FAILED</OrderStatus><TelephoneNumberDetails/><userId>team_ua</userId></OrderIdUserIdDate><!-- ...SNIP... --><OrderIdUserIdDate><accountId>9999999</accountId><CountOfTNs>0</CountOfTNs><lastModifiedDate>2014-02-25T16:02:39.021Z</lastModifiedDate><OrderType>lidb</OrderType><OrderDate>2014-02-25T16:02:39.021Z</OrderDate><orderId>ba5b6297-139b-4430-aab0-9ff02c4362f4</orderId><OrderStatus>FAILED</OrderStatus><userId>team_ua</userId></OrderIdUserIdDate></ListOrderIdUserIdDate></ResponseSelectWrapper>"

0 commit comments

Comments
 (0)