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

Instance Method Details

#add_notes(note) ⇒ Object



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

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



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bandwidth-iris/port_in.rb', line 41

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



21
22
23
# File 'lib/bandwidth-iris/port_in.rb', line 21

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

#get_file(file_name) ⇒ Object



70
71
72
73
74
# File 'lib/bandwidth-iris/port_in.rb', line 70

def get_file(file_name)
  connection = @client.create_connection()
  response = connection.get("/#{@client.api_version}#{@client.(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{URI.encode(file_name)}")
  [response.body, response.headers['Content-Type'] || 'application/octet-stream']
end

#get_file_metadata(file_name) ⇒ Object



66
67
68
# File 'lib/bandwidth-iris/port_in.rb', line 66

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

#get_files(metadata = false) ⇒ Object



76
77
78
# File 'lib/bandwidth-iris/port_in.rb', line 76

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

#get_notesObject



25
26
27
28
29
30
31
32
33
# File 'lib/bandwidth-iris/port_in.rb', line 25

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

#update(data) ⇒ Object



17
18
19
# File 'lib/bandwidth-iris/port_in.rb', line 17

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



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bandwidth-iris/port_in.rb', line 54

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