class BandwidthIris::PortIn

Public Class Methods

create(client, item) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 9
def self.create(client, item)
  item  = client.make_request(:post, client.concat_account_path(PORT_IN_PATH), {:lnp_order => item})[0]
  item[:id] = item[:order_id]
  PortIn.new(item, client)
end
list(client, query=nil) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 30
def self.list(client, query=nil)
  list_from_page_url(client, client.concat_account_path(PORT_IN_PATH), query)
end
list_from_page_url(client, url, query=nil) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 16
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]
  return unless items

  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

Public Instance Methods

add_notes(note) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 57
def add_notes(note)
  r = @client.make_request(:post, "#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/notes", {:note => note})
  note_id = Client.get_id_from_location_header(r[1][:location])
  (get_notes().select {|n| n[:id].to_s == note_id }).first
end
create_file(io, media_type = nil) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 63
def create_file(io, media_type = nil)
  connection = @client.create_connection()
  # FIXME use streams directly when Faraday will support streaming
  buf = io.read()
  response = connection.post("/#{@client.api_version}#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}") do |req|
    req.headers['Content-Length'] = buf.size.to_s
    req.headers['Content-Type'] = media_type || 'application/octet-stream'
    req.body = buf
  end
  r = @client.check_response(response)
  r[:filename]
end
delete() click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 43
def delete()
  @client.make_request(:delete,"#{@client.concat_account_path(PORT_IN_PATH)}/#{id}")
end
get_file(file_name) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 92
def get_file(file_name)
  connection = @client.create_connection()
  response = connection.get("/#{@client.api_version}#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{CGI.escape(file_name)}")
  [response.body, response.headers['Content-Type'] || 'application/octet-stream']
end
get_file_metadata(file_name) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 88
def get_file_metadata(file_name)
  @client.make_request(:get, "#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{CGI.escape(file_name)}/metadata")[0]
end
get_files(metadata = false) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 98
def get_files(metadata = false)
   @client.make_request(:get, "#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}", {:metadata => metadata})[0][:file_data]
end
get_notes() click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 47
def get_notes()
  list = @client.make_request(:get, "#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/notes")[0][:note]
  return [] if !list
  if list.is_a?(Array)
    list
  else
    [list]
  end
end
tns() click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 35
def tns
  Array(@client.make_request(:get, "#{@client.concat_account_path(PORT_IN_PATH)}/#{order_id}/tns")[0][:telephone_number])
end
update(data) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 39
def update(data)
  @client.make_request(:put,"#{@client.concat_account_path(PORT_IN_PATH)}/#{id}", {:lnp_order_supp => data})
end
update_file(file_name, file, media_type) click to toggle source
# File lib/bandwidth-iris/port_in.rb, line 76
def update_file(file_name, file, media_type)
  connection = @client.create_connection()
  # FIXME use streams directly when Faraday will support streaming
  buf = io.read()
  response = connection.put("/#{@client.api_version}#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{URI.encode(file_name)}") do |req|
    req.headers['Content-Length'] = buf.size.to_s
    req.headers['Content-Type'] = media_type || 'application/octet-stream'
    req.body = buf
  end
  @client.check_response(response)
end