Class: BandwidthIris::PortIn

Inherits:
Object
  • Object
show all
Extended by:
ClientWrapper
Includes:
ApiItem
Defined in:
lib/bandwidth-iris/port_in.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClientWrapper

wrap_client_arg

Methods included from ApiItem

#[], #[]=, #initialize, #to_data

Class Method Details

.create(client, item) ⇒ Object



9
10
11
12
13
# File 'lib/bandwidth-iris/port_in.rb', line 9

def self.create(client, item)
  item  = client.make_request(:post, client.(PORT_IN_PATH), {:lnp_order => item})[0]
  item[:id] = item[:order_id]
  PortIn.new(item, client)
end

.list(client, query = nil) ⇒ Object



30
31
32
# File 'lib/bandwidth-iris/port_in.rb', line 30

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

.list_from_page_url(client, url, query = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Instance Method Details

#add_notes(note) ⇒ Object



57
58
59
60
61
# File 'lib/bandwidth-iris/port_in.rb', line 57

def add_notes(note)
  r = @client.make_request(:post, "#{@client.(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) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# 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.(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

#deleteObject



43
44
45
# File 'lib/bandwidth-iris/port_in.rb', line 43

def delete()
  @client.make_request(:delete,"#{@client.(PORT_IN_PATH)}/#{id}")
end

#get_file(file_name) ⇒ Object



92
93
94
95
96
# 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.(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) ⇒ Object



88
89
90
# File 'lib/bandwidth-iris/port_in.rb', line 88

def (file_name)
  @client.make_request(:get, "#{@client.(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{CGI.escape(file_name)}/metadata")[0]
end

#get_files(metadata = false) ⇒ Object



98
99
100
# File 'lib/bandwidth-iris/port_in.rb', line 98

def get_files( = false)
   @client.make_request(:get, "#{@client.(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}", {:metadata => })[0][:file_data]
end

#get_notesObject



47
48
49
50
51
52
53
54
55
# File 'lib/bandwidth-iris/port_in.rb', line 47

def get_notes()
  list = @client.make_request(:get, "#{@client.(PORT_IN_PATH)}/#{id}/notes")[0][:note]
  return [] if !list
  if list.is_a?(Array)
    list
  else
    [list]
  end
end

#tnsObject



35
36
37
# File 'lib/bandwidth-iris/port_in.rb', line 35

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

#update(data) ⇒ Object



39
40
41
# File 'lib/bandwidth-iris/port_in.rb', line 39

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

#update_file(file_name, file, media_type) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# 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.(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