Skip to content

Commit

Permalink
Allow listing port-ins, and getting the TNs for a port-in
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed May 11, 2022
1 parent 12fef79 commit f7dc798
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/bandwidth-iris/paginated_result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "delegate"

module BandwidthIris
class PaginatedResult < SimpleDelegator
def initialize(items, links, &block)
super(items)
@links = links
@requestor = block
end

def next
return unless @links[:next]

@requestor.call(@links[:next].match(/\<([^>]+)\>/)[1].sub(/^http.*\/v1.0/, ""))
end
end
end
20 changes: 20 additions & 0 deletions lib/bandwidth-iris/port_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ def self.create(client, item)
end
wrap_client_arg :create

def self.list_from_page_url(client, url, query=nil)
response = client.make_request(:get, url, query)[0]
items = response[:lnp_port_info_for_given_status]
items = items.is_a?(Array) ? items : [items]
PaginatedResult.new(
items.map { |item| PortIn.new(item, client) },
response[:links]
) do |next_url|
list_from_page_url(client, next_url)
end
end

def self.list(client, query=nil)
list_from_page_url(client, client.concat_account_path(PORT_IN_PATH), query)
end
wrap_client_arg :list

def tns
Array(@client.make_request(:get, "#{@client.concat_account_path(PORT_IN_PATH)}/#{order_id}/tns")[0][:telephone_number])
end

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

0 comments on commit f7dc798

Please sign in to comment.