ruby-bandwidth-iris 2.1.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ lib = File.expand_path("../../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'ruby-bandwidth-iris'
5
+
6
+ $bandwidth_account_id = ENV['BANDWIDTH_ACCOUNT_ID']
7
+ $bandwidth_user_name = ENV['BANDWIDTH_API_USER']
8
+ $bandwidth_password = ENV['BANDWIDTH_API_PASSWORD']
9
+ ## Fill these in
10
+ $bandwidth_site_id = ENV['BANDWIDTH_SITE_ID']
11
+ $bandwidth_to_sippeer_id = ENV['BANDWIDTH_SIPPEER_ID']
12
+
13
+
14
+ def get_order_by_id(client, order_id:, attempts: 0)
15
+ begin
16
+ order_result = BandwidthIris::Order.get(client, order_id)
17
+ return order_result
18
+ rescue Exception => e
19
+ if attempts > 3
20
+ puts("Completely Failed fetching Order")
21
+ raise StandardError.new e
22
+ end
23
+ puts("Error Message: #{e.message}")
24
+ attempts = attempts+1
25
+ sleep(1)
26
+ return get_order_by_id(client, order_id: order_id, attempts: attempts)
27
+ end
28
+ end
29
+
30
+ def get_numbers_from_order_id(client, order_id:)
31
+ order = BandwidthIris::Order.new({:id => order_id}, client)
32
+ numbers_result = order.get_tns
33
+ return numbers_result
34
+ end
35
+
36
+ def order_numbers_with_reservation_id(client, reservation_id:, number:)
37
+ order_data = {
38
+ :name => "Reservation Test",
39
+ :site_id => $bandwidth_site_id,
40
+ :existing_telephone_number_order_type => {
41
+ :telephone_number_list => [
42
+ :telephone_number => number
43
+ ],
44
+ :reservation_id_list => [
45
+ :reservation_id => reservation_id
46
+ ]
47
+ }
48
+ }
49
+ order_result = BandwidthIris::Order.create(client, order_data)
50
+ return order_result
51
+ end
52
+
53
+ def reserve_numbers(client, number:)
54
+ reservation = BandwidthIris::TnReservation.create(client, number)
55
+ return reservation
56
+ end
57
+
58
+ def search_numbers(client, area_code: 919)
59
+ list = BandwidthIris::AvailableNumber.list(client, {:area_code => area_code, :quantity => 5})
60
+ return list
61
+ end
62
+
63
+ def main()
64
+ client = BandwidthIris::Client.new($bandwidth_account_id, $bandwidth_user_name, $bandwidth_password)
65
+ available_numbers = search_numbers(client)
66
+ number = available_numbers[0]
67
+ reservation = reserve_numbers(client, number: number)
68
+ reservation_id = reservation.id
69
+ order = order_numbers_with_reservation_id(client, reservation_id: reservation_id, number: number)
70
+ order_id = order.id
71
+ puts(order_id)
72
+ my_order = get_order_by_id(client, order_id: order_id)
73
+ my_numbers = get_numbers_from_order_id(client, order_id:order_id)
74
+ puts(my_numbers)
75
+ end
76
+
77
+ if __FILE__ == $0
78
+ main
79
+ end
@@ -0,0 +1,83 @@
1
+ lib = File.expand_path("../../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require "ruby-bandwidth-iris"
5
+
6
+ def order_numbers_in_area_code(client, site_id:, sippeer_id:, area_code: 919, quantity: 1)
7
+ order_data = {
8
+ :name => "Test",
9
+ :site_id => site_id,
10
+ :area_code_search_and_order_type => {
11
+ :area_code => area_code,
12
+ :quantity => quantity
13
+ }
14
+ }
15
+ order_result = BandwidthIris::Order.create(client, order_data)
16
+ order_id = order_result.to_data[:id]
17
+ return order_id
18
+ end
19
+
20
+ def get_order_by_id(client, order_id:, attempts: 0)
21
+ begin
22
+ order_result = BandwidthIris::Order.get(client, order_id)
23
+ return order_result
24
+ rescue Exception => e
25
+ if attempts > 3
26
+ puts("Completely Failed fetching Order")
27
+ raise StandardError.new e
28
+ end
29
+ puts("Error Message: #{e.message}\nCode:#{e.code}")
30
+ attempts = attempts+1
31
+ sleep(1)
32
+ return get_order_by_id(client, order_id: order_id, attempts: attempts)
33
+ end
34
+ end
35
+
36
+ def get_order_response_by_id(client, order_id:, attempts: 0)
37
+ begin
38
+ order_response = BandwidthIris::Order.get_order_response(client, order_id)
39
+ order_data = order_response.to_data
40
+ numbers = order_response.completed_numbers
41
+ completed_number = order_data[:completed_numbers][:telephone_number][:full_number]
42
+ return order_data
43
+ rescue Exception => e
44
+ if attempts > 3
45
+ puts("Completely Failed fetching Order")
46
+ raise StandardError.new e
47
+ end
48
+ puts("Error Message: #{e.message}\nCode:#{e.code}")
49
+ attempts = attempts+1
50
+ sleep(1)
51
+ return get_order_response(client, order_id: order_id, attempts: attempts)
52
+ end
53
+ end
54
+
55
+
56
+ def get_numbers_from_order_id(client, order_id:)
57
+ order = BandwidthIris::Order.new({:id => order_id}, client)
58
+ numbers_result = order.get_tns
59
+ return numbers_result
60
+ end
61
+
62
+ def get_numbers_from_order(order)
63
+ numbers_result = order.get_tns
64
+ return numbers_result
65
+ end
66
+
67
+ def main
68
+ bandwidth_account_id = ENV["BANDWIDTH_ACCOUNT_ID"]
69
+ bandwidth_user_name = ENV["BANDWIDTH_API_USER"]
70
+ bandwidth_password = ENV["BANDWIDTH_API_PASSWORD"]
71
+ bandwidth_site_id = ENV["BANDWIDTH_SITE_ID"]
72
+ bandwidth_to_sippeer_id = ENV["BANDWIDTH_SIPPEER_ID"]
73
+ client = BandwidthIris::Client.new(bandwidth_account_id, bandwidth_user_name, bandwidth_password)
74
+ order_id = order_numbers_in_area_code(client, site_id: bandwidth_site_id, sippeer_id: bandwidth_to_sippeer_id)
75
+ my_order = get_order_by_id(client, order_id: order_id)
76
+ my_order_response = get_order_response_by_id(client, order_id: order_id)
77
+ my_numbers = get_numbers_from_order_id(client, order_id:order_id)
78
+ my_numbers = get_numbers_from_order(my_order)
79
+ end
80
+
81
+ if __FILE__ == $0
82
+ main
83
+ end
@@ -0,0 +1,20 @@
1
+ module BandwidthIris
2
+ AEUI_PATH = 'aeuis'
3
+
4
+ class AlternateEndUserIdentity
5
+ extend ClientWrapper
6
+ include ApiItem
7
+
8
+ def self.get_alternate_end_user_information(client, query=nil)
9
+ response = client.make_request(:get, "#{client.concat_account_path(AEUI_PATH)}", query)
10
+ return response[0]
11
+ end
12
+ wrap_client_arg :get_alternate_end_user_information
13
+
14
+ def self.get_alternate_caller_information(client, acid)
15
+ response = client.make_request(:get, "#{client.concat_account_path(AEUI_PATH)}/#{acid}")
16
+ return response[0][:alternate_end_user_identifier]
17
+ end
18
+ wrap_client_arg :get_alternate_caller_information
19
+ end
20
+ end
@@ -0,0 +1,61 @@
1
+ module BandwidthIris
2
+ APPLICATIONS_PATH = "applications"
3
+
4
+ class Applications
5
+ extend ClientWrapper
6
+ include ApiItem
7
+
8
+ def self.get_applications(client)
9
+ data = client.make_request(:get, client.concat_account_path(APPLICATIONS_PATH))
10
+ list = data[0][:application_list][:application]
11
+ return [] if !list
12
+ if list.is_a?(Array) then
13
+ return list
14
+ else
15
+ return [list]
16
+ end
17
+ end
18
+ wrap_client_arg :get_applications
19
+
20
+ def self.create_application(client, application_data)
21
+ data = client.make_request(:post, client.concat_account_path(APPLICATIONS_PATH), {:application => application_data})
22
+ return data[0][:application]
23
+ end
24
+ wrap_client_arg :create_application
25
+
26
+ def self.get_application(client, application_id)
27
+ data = client.make_request(:get, client.concat_account_path("#{APPLICATIONS_PATH}/#{application_id}"))
28
+ return data[0][:application]
29
+ end
30
+ wrap_client_arg :get_application
31
+
32
+ def self.partial_update_application(client, application_id, application_data)
33
+ data = client.make_request(:patch, client.concat_account_path("#{APPLICATIONS_PATH}/#{application_id}"), {:application => application_data})
34
+ return data[0][:application]
35
+ end
36
+ wrap_client_arg :partial_update_application
37
+
38
+ def self.complete_update_application(client, application_id, application_data)
39
+ data = client.make_request(:put, client.concat_account_path("#{APPLICATIONS_PATH}/#{application_id}"), {:application => application_data})
40
+ return data[0][:application]
41
+ end
42
+ wrap_client_arg :complete_update_application
43
+
44
+ def self.delete_application(client, application_id)
45
+ client.make_request(:delete, client.concat_account_path("#{APPLICATIONS_PATH}/#{application_id}"))
46
+ end
47
+ wrap_client_arg :delete_application
48
+
49
+ def self.get_application_sippeers(client, application_id)
50
+ data = client.make_request(:get, client.concat_account_path("#{APPLICATIONS_PATH}/#{application_id}/associatedsippeers"))
51
+ list = data[0][:associated_sip_peers][:associated_sip_peer]
52
+ return [] if !list
53
+ if list.is_a?(Array) then
54
+ return list
55
+ else
56
+ return [list]
57
+ end
58
+ end
59
+ wrap_client_arg :get_application_sippeers
60
+ end
61
+ end
@@ -77,12 +77,44 @@ module BandwidthIris
77
77
  req.params = d unless d == nil || d.empty?
78
78
  end
79
79
  else
80
- connection.run_request(method, @build_path.call(path), build_xml(data), {'Content-Type' => 'application/xml'})
80
+ xml_to_send = build_xml(data) # help debug
81
+ connection.run_request(method, @build_path.call(path), xml_to_send, {'Content-Type' => 'application/xml'})
81
82
  end
82
83
  body = check_response(response)
83
84
  [body || {}, symbolize(response.headers || {})]
84
85
  end
85
86
 
87
+ # Makes an HTTP request for file uploads
88
+ # @param method [Symbol] http method to make
89
+ # @param path [string] path of url (exclude api verion and endpoint) to make call
90
+ # @param data [string] the raw binary string representing the file to upload
91
+ # @param content_type [string] the content type of the request
92
+ # @return [Array] array with 2 elements: parsed data of response and response headers
93
+ def make_request_file_upload(method, path, data, content_type)
94
+ connection = @create_connection.call()
95
+ response = connection.run_request(method, @build_path.call(path), data, {'Content-Type' => content_type})
96
+ body = check_response(response)
97
+ [body || {}, symbolize(response.headers || {})]
98
+ end
99
+
100
+ # Makes an HTTP request for a file download
101
+ # @param method [Symbol] http method to make
102
+ # @param path [string] path of url (exclude api verion and endpoint) to make call
103
+ # @param data [Hash] data which will be sent with request (for :get and :delete request they will be sent with query in url)
104
+ # @return [string] raw response from the API
105
+ def make_request_file_download(method, path, data = {})
106
+ connection = @create_connection.call()
107
+ response = if method == :get || method == :delete
108
+ d = camelcase(data)
109
+ connection.run_request(method, @build_path.call(path), nil, nil) do |req|
110
+ req.params = d unless d == nil || d.empty?
111
+ end
112
+ else
113
+ connection.run_request(method, @build_path.call(path), build_xml(data), {'Content-Type' => 'application/xml'})
114
+ end
115
+ return response.body
116
+ end
117
+
86
118
  # Check response object and raise error if status code >= 400
87
119
  # @param response response object
88
120
  def check_response(response)
@@ -0,0 +1,26 @@
1
+ module BandwidthIris
2
+ ENE_ORDERS_PATH = 'emergencyNotificationEndpointOrders'
3
+
4
+ class EmergencyNotificationEndpoints
5
+ extend ClientWrapper
6
+ include ApiItem
7
+
8
+ def self.create_emergency_notification_endpoint_order(client, data)
9
+ response = client.make_request(:post, "#{client.concat_account_path(ENE_ORDERS_PATH)}", {:emergency_notification_endpoint_order => data})
10
+ return response[0][:emergency_notification_endpoint_order]
11
+ end
12
+ wrap_client_arg :create_emergency_notification_endpoint_order
13
+
14
+ def self.get_emergency_notification_endpoint_orders(client, query=nil)
15
+ response = client.make_request(:get, "#{client.concat_account_path(ENE_ORDERS_PATH)}", query)
16
+ return response[0]
17
+ end
18
+ wrap_client_arg :get_emergency_notification_endpoint_orders
19
+
20
+ def self.get_emergency_notification_endpoint_order(client, order_id)
21
+ response = client.make_request(:get, "#{client.concat_account_path(ENE_ORDERS_PATH)}/#{order_id}")
22
+ return response[0][:emergency_notification_endpoint_order]
23
+ end
24
+ wrap_client_arg :get_emergency_notification_endpoint_order
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ module BandwidthIris
2
+ ENG_ORDERS_PATH = 'emergencyNotificationGroupOrders'
3
+ ENG_PATH = 'emergencyNotificationGroups'
4
+
5
+ class EmergencyNotificationGroups
6
+ extend ClientWrapper
7
+ include ApiItem
8
+
9
+ def self.create_emergency_notification_group_order(client, data)
10
+ response = client.make_request(:post, "#{client.concat_account_path(ENG_ORDERS_PATH)}", {:emergency_notification_group_order => data})
11
+ return response[0][:emergency_notification_endpoint_order]
12
+ end
13
+ wrap_client_arg :create_emergency_notification_group_order
14
+
15
+ def self.get_emergency_notification_group_orders(client, query=nil)
16
+ response = client.make_request(:get, "#{client.concat_account_path(ENG_ORDERS_PATH)}", query)
17
+ return response[0]
18
+ end
19
+ wrap_client_arg :get_emergency_notification_group_orders
20
+
21
+ def self.get_emergency_notification_group_order(client, order_id)
22
+ response = client.make_request(:get, "#{client.concat_account_path(ENG_ORDERS_PATH)}/#{order_id}")
23
+ return response[0][:emergency_notification_endpoint_order]
24
+ end
25
+ wrap_client_arg :get_emergency_notification_group_order
26
+
27
+ def self.get_emergency_notification_group(client, eng_id)
28
+ response = client.make_request(:get, "#{client.concat_account_path(ENG_PATH)}/#{eng_id}")
29
+ return response[0][:emergency_notification_group]
30
+ end
31
+ wrap_client_arg :get_emergency_notification_group
32
+
33
+ def self.get_emergency_notification_groups(client, query=nil)
34
+ response = client.make_request(:get, "#{client.concat_account_path(ENG_PATH)}", query)
35
+ return response[0]
36
+ end
37
+ wrap_client_arg :get_emergency_notification_groups
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ module BandwidthIris
2
+ ENR_PATH = 'emergencyNotificationRecipients'
3
+
4
+ class EmergencyNotificationRecipients
5
+ extend ClientWrapper
6
+ include ApiItem
7
+
8
+ def self.create_emergency_notification_recipient(client, data)
9
+ response = client.make_request(:post, "#{client.concat_account_path(ENR_PATH)}", {:emergency_notification_recipient => data})
10
+ return response[0][:emergency_notification_recipient]
11
+ end
12
+ wrap_client_arg :create_emergency_notification_recipient
13
+
14
+ def self.get_emergency_notification_recipients(client, query=nil)
15
+ response = client.make_request(:get, "#{client.concat_account_path(ENR_PATH)}", query)
16
+ return response[0]
17
+ end
18
+ wrap_client_arg :get_emergency_notification_recipients
19
+
20
+ def self.get_emergency_notification_recipient(client, enr_id)
21
+ response = client.make_request(:get, "#{client.concat_account_path(ENR_PATH)}/#{enr_id}")
22
+ return response[0][:emergency_notification_recipient]
23
+ end
24
+ wrap_client_arg :get_emergency_notification_recipient
25
+
26
+ def self.replace_emergency_notification_recipient(client, enr_id, data)
27
+ response = client.make_request(:put, "#{client.concat_account_path(ENR_PATH)}/#{enr_id}", {:emergency_notification_recipient => data})
28
+ return response[0][:emergency_notification_recipient]
29
+ end
30
+ wrap_client_arg :replace_emergency_notification_recipient
31
+
32
+ def self.delete_emergency_notification_recipient(client, enr_id)
33
+ client.make_request(:delete, "#{client.concat_account_path(ENR_PATH)}/#{enr_id}")
34
+ end
35
+ wrap_client_arg :delete_emergency_notification_recipient
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module BandwidthIris
2
- IMPORT_TN_ORDERS_PATH = "importTnOrders"
2
+ IMPORT_TN_ORDERS_PATH = "importtnorders"
3
3
 
4
4
  class ImportTnOrders
5
5
  extend ClientWrapper
@@ -28,5 +28,48 @@ module BandwidthIris
28
28
  return data
29
29
  end
30
30
  wrap_client_arg :create_import_tn_order
31
+
32
+ def self.get_loa_files(client, order_id)
33
+ data = client.make_request(:get, client.concat_account_path("#{IMPORT_TN_ORDERS_PATH}/#{order_id}/#{LOAS_PATH}"))
34
+ return data
35
+ end
36
+ wrap_client_arg :get_loa_files
37
+
38
+ def self.upload_loa_file(client, order_id, file_contents, mime_type)
39
+ client.make_request_file_upload(:post, client.concat_account_path("#{IMPORT_TN_ORDERS_PATH}/#{order_id}/#{LOAS_PATH}"), file_contents, mime_type)
40
+ end
41
+ wrap_client_arg :upload_loa_file
42
+
43
+ def self.download_loa_file(client, order_id, file_id)
44
+ data = client.make_request_file_download(:get, client.concat_account_path("#{IMPORT_TN_ORDERS_PATH}/#{order_id}/#{LOAS_PATH}/#{file_id}"))
45
+ return data
46
+ end
47
+ wrap_client_arg :download_loa_file
48
+
49
+ def self.replace_loa_file(client, order_id, file_id, file_contents, mime_type)
50
+ data = client.make_request_file_upload(:put, client.concat_account_path("#{IMPORT_TN_ORDERS_PATH}/#{order_id}/#{LOAS_PATH}/#{file_id}"), file_contents, mime_type)
51
+ end
52
+ wrap_client_arg :replace_loa_file
53
+
54
+ def self.delete_loa_file(client, order_id, file_id)
55
+ client.make_request(:delete, client.concat_account_path("#{IMPORT_TN_ORDERS_PATH}/#{order_id}/#{LOAS_PATH}/#{file_id}"))
56
+ end
57
+ wrap_client_arg :delete_loa_file
58
+
59
+ def self.get_loa_file_metadata(client, order_id, file_id)
60
+ data = client.make_request(:get, client.concat_account_path("#{IMPORT_TN_ORDERS_PATH}/#{order_id}/#{LOAS_PATH}/#{file_id}/metadata"))
61
+ return data
62
+ end
63
+ wrap_client_arg :get_loa_file_metadata
64
+
65
+ def self.update_loa_file_metadata(client, order_id, file_id, file_metadata)
66
+ client.make_request(:put, client.concat_account_path("#{IMPORT_TN_ORDERS_PATH}/#{order_id}/#{LOAS_PATH}/#{file_id}/metadata"), {:file_meta_data => file_metadata})
67
+ end
68
+ wrap_client_arg :update_loa_file_metadata
69
+
70
+ def self.delete_loa_file_metadata(client, order_id, file_id)
71
+ client.make_request(:delete, client.concat_account_path("#{IMPORT_TN_ORDERS_PATH}/#{order_id}/#{LOAS_PATH}/#{file_id}/metadata"))
72
+ end
73
+ wrap_client_arg :delete_loa_file_metadata
31
74
  end
32
75
  end