phaxio 2.1.0.pre → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -17
  3. data/lib/phaxio/client.rb +2 -6
  4. data/lib/phaxio/config.rb +6 -4
  5. data/lib/phaxio/resource.rb +11 -5
  6. data/lib/phaxio/resources/account.rb +1 -1
  7. data/lib/phaxio/resources/ata.rb +85 -19
  8. data/lib/phaxio/resources/callback.rb +10 -56
  9. data/lib/phaxio/resources/fax.rb +11 -11
  10. data/lib/phaxio/resources/phax_code.rb +2 -2
  11. data/lib/phaxio/resources/phone_number.rb +31 -5
  12. data/lib/phaxio/resources/port_number.rb +42 -0
  13. data/lib/phaxio/resources/port_number_note.rb +51 -0
  14. data/lib/phaxio/resources/port_order.rb +172 -0
  15. data/lib/phaxio/resources/public/area_code.rb +1 -1
  16. data/lib/phaxio/resources/public/country.rb +1 -1
  17. data/lib/phaxio/resources/webhook.rb +65 -0
  18. data/lib/phaxio/version.rb +1 -1
  19. data/lib/phaxio.rb +12 -3
  20. data/spec/phaxio_spec.rb +7 -1
  21. data/spec/resources/account_spec.rb +1 -7
  22. data/spec/resources/ata_spec.rb +207 -0
  23. data/spec/resources/fax_spec.rb +35 -103
  24. data/spec/resources/phax_code_spec.rb +10 -44
  25. data/spec/resources/phone_number_spec.rb +19 -30
  26. data/spec/resources/port_number_note_spec.rb +33 -0
  27. data/spec/resources/port_number_spec.rb +32 -0
  28. data/spec/resources/port_order_spec.rb +76 -0
  29. data/spec/resources/public/area_code_spec.rb +1 -1
  30. data/spec/resources/public/country_spec.rb +1 -7
  31. data/spec/resources/{callback_spec.rb → webhook_spec.rb} +8 -8
  32. data/spec/spec_helper.rb +1 -0
  33. data/spec/support/{vcr_cassettes/resources/account/status.yml → cassettes/account/get.yml} +7 -9
  34. data/spec/support/cassettes/ata/add_phone_number.yml +89 -0
  35. data/spec/support/{vcr_cassettes/resources/fax/resend.yml → cassettes/ata/create.yml} +12 -13
  36. data/spec/support/cassettes/ata/delete.yml +86 -0
  37. data/spec/support/cassettes/ata/get.yml +87 -0
  38. data/spec/support/cassettes/ata/list.yml +67 -0
  39. data/spec/support/{vcr_cassettes/resources/phax_code/get_id.yml → cassettes/ata/provisioning_urls.yml} +10 -13
  40. data/spec/support/cassettes/ata/reference.yml +87 -0
  41. data/spec/support/cassettes/ata/regenerate.yml +89 -0
  42. data/spec/support/cassettes/ata/remove_phone_number.yml +130 -0
  43. data/spec/support/cassettes/ata/update.yml +89 -0
  44. data/spec/support/{vcr_cassettes/resources/fax/create_for_cancel.yml → cassettes/fax/cancel.yml} +51 -11
  45. data/spec/support/{vcr_cassettes/resources/fax/create_for_reference.yml → cassettes/fax/create.yml} +11 -13
  46. data/spec/support/{vcr_cassettes/resources/fax/create.yml → cassettes/fax/delete.yml} +49 -11
  47. data/spec/support/{vcr_cassettes/resources/fax/create_for_delete.yml → cassettes/fax/delete_file.yml} +49 -11
  48. data/spec/support/cassettes/fax/file.yml +93 -0
  49. data/spec/support/{vcr_cassettes/resources/fax/create_for_download_file.yml → cassettes/fax/get.yml} +49 -11
  50. data/spec/support/{vcr_cassettes/resources → cassettes}/fax/list.yml +5 -7
  51. data/spec/support/cassettes/fax/reference.yml +88 -0
  52. data/spec/support/{vcr_cassettes/resources/fax/create_for_delete_file.yml → cassettes/fax/resend.yml} +51 -11
  53. data/spec/support/{vcr_cassettes/resources → cassettes}/fax/test_receive.yml +7 -9
  54. data/spec/support/{vcr_cassettes/resources → cassettes}/phax_code/create.yml +8 -10
  55. data/spec/support/{vcr_cassettes/resources → cassettes}/phax_code/create_png.yml +8 -10
  56. data/spec/support/cassettes/phax_code/get_by_id.yml +86 -0
  57. data/spec/support/{vcr_cassettes/resources/phax_code/get.yml → cassettes/phax_code/get_default.yml} +8 -10
  58. data/spec/support/{vcr_cassettes/resources/phax_code/get_png.yml → cassettes/phax_code/get_default_png.yml} +8 -10
  59. data/spec/support/cassettes/phax_code/get_png_by_id.yml +90 -0
  60. data/spec/support/{vcr_cassettes/resources → cassettes}/phone_number/create.yml +8 -10
  61. data/spec/support/{vcr_cassettes/resources → cassettes}/phone_number/get.yml +10 -12
  62. data/spec/support/cassettes/phone_number/list.yml +72 -0
  63. data/spec/support/cassettes/phone_number/reference.yml +45 -0
  64. data/spec/support/cassettes/phone_number/release.yml +86 -0
  65. data/spec/support/cassettes/port_number/get.yml +88 -0
  66. data/spec/support/cassettes/port_number_note/list.yml +88 -0
  67. data/spec/support/cassettes/port_order/create.yml +48 -0
  68. data/spec/support/cassettes/port_order/get.yml +91 -0
  69. data/spec/support/cassettes/port_order/list.yml +52 -0
  70. data/spec/support/{vcr_cassettes/resources/public/area_codes → cassettes/public/area_code}/list.yml +15 -17
  71. data/spec/support/{vcr_cassettes/resources → cassettes}/public/country/list.yml +5 -7
  72. data/spec/support/vcr.rb +24 -6
  73. metadata +115 -41
  74. data/spec/support/credentials.rb +0 -7
  75. data/spec/support/vcr_cassettes/resources/fax/cancel.yml +0 -47
  76. data/spec/support/vcr_cassettes/resources/fax/create_for_get.yml +0 -50
  77. data/spec/support/vcr_cassettes/resources/fax/create_for_resend.yml +0 -50
  78. data/spec/support/vcr_cassettes/resources/fax/delete.yml +0 -45
  79. data/spec/support/vcr_cassettes/resources/fax/delete_file.yml +0 -45
  80. data/spec/support/vcr_cassettes/resources/fax/file.yml +0 -50
  81. data/spec/support/vcr_cassettes/resources/fax/get.yml +0 -45
  82. data/spec/support/vcr_cassettes/resources/fax/reference.yml +0 -45
  83. data/spec/support/vcr_cassettes/resources/phax_code/get_id_png.yml +0 -50
  84. data/spec/support/vcr_cassettes/resources/phone_number/list.yml +0 -60
  85. data/spec/support/vcr_cassettes/resources/phone_number/release.yml +0 -45
@@ -0,0 +1,42 @@
1
+ module Phaxio
2
+ module Resources
3
+ # Provides functionality for viewing port numbers.
4
+ class PortNumber < Resource
5
+ PORT_NUMBERS_PATH = 'port_numbers'.freeze
6
+ private_constant :PORT_NUMBERS_PATH
7
+
8
+ # @return [Integer] the ID associated with this number.
9
+ # @!attribute id
10
+
11
+ # @return [String] the E.164 number.
12
+ # @!attribute port_number
13
+
14
+ # @return [String] the status of this number.
15
+ # @!attribute status
16
+
17
+ has_normal_attributes %w(id port_number status)
18
+
19
+ class << self
20
+ # Get port number info.
21
+ # @param id [Integer] The ID of the number to retrieve.
22
+ # @param params [Hash]
23
+ # A hash of parameters to send to Phaxio. This action takes no unique parameters.
24
+ # @return [Phaxio::Resource::PortNumber]
25
+ # @raise [Phaxio::Error::PhaxioError]
26
+ # @see https://www.phaxio.com/docs/api/v2/port_numbers/get_port_number
27
+ def get id, params = {}
28
+ response = Client.request :get, port_number_endpoint(id.to_i), params
29
+ response_record response
30
+ end
31
+ alias :retrieve :get
32
+ alias :find :get
33
+
34
+ private
35
+
36
+ def port_number_endpoint id
37
+ "#{PORT_NUMBERS_PATH}/#{id}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ module Phaxio
2
+ module Resources
3
+ # Provides functionality for viewing port number notes.
4
+ class PortNumberNote < Resource
5
+ PORT_NUMBERS_PATH = 'port_numbers'.freeze
6
+ private_constant :PORT_NUMBERS_PATH
7
+ NOTES_PATH = 'notes'.freeze
8
+ private_constant :NOTES_PATH
9
+
10
+ # @return [Integer] the ID associated with this note.
11
+ # @!attribute id
12
+
13
+ # @return [String] the author of this note.
14
+ # @!attribute author
15
+
16
+ # @return [String] the content of the note
17
+ # @!attribute note
18
+
19
+ has_normal_attributes %w[id note author]
20
+
21
+ # @return [Time] the time this note was created.
22
+ # @!attribute created_at
23
+
24
+ # @return [Time] the time this note was updated.
25
+ # @!attribute updated_at
26
+
27
+ has_time_attributes %w[created_at updated_at]
28
+
29
+ class << self
30
+ # List notes for a port number.
31
+ # @param port_number_id [Integer]
32
+ # The ID of the port number to list notes for.
33
+ # @param params [Hash]
34
+ # Any parameters to send to Phaxio. This action takes no unique parameters.
35
+ # @return [Phaxio::Resource::Collection<Phaxio::Resources::PortNumberNote>]
36
+ # @raise [Phaxio::Error::PhaxioError]
37
+ # @see https://www.phaxio.com/docs/api/v2/port_number_notes/list_notes
38
+ def list port_number_id, params = {}
39
+ response = Client.request :get, port_number_notes_endpoint(port_number_id.to_i), params
40
+ response_collection response
41
+ end
42
+
43
+ private
44
+
45
+ def port_number_notes_endpoint port_number_id
46
+ "#{PORT_NUMBERS_PATH}/#{port_number_id}/#{NOTES_PATH}"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,172 @@
1
+ module Phaxio
2
+ module Resources
3
+ # Provides functionality for viewing and managing port orders.
4
+ class PortOrder < Resource
5
+ PORT_ORDERS_PATH = 'port_orders'.freeze
6
+ private_constant :PORT_ORDERS_PATH
7
+
8
+ # @return [Integer] the ID associated with this order.
9
+ # @!attribute id
10
+
11
+ # @return [String] the status of this order.
12
+ # @!attribute status
13
+
14
+ # @return [String] the E.164 contact number.
15
+ # @!attribute contact_number
16
+
17
+ # @return [String] The email address for the order.
18
+ # @!attribute contact_email
19
+
20
+ # @return [String] The identifier for the account associated with the numbers.
21
+ # @!attribute account_identifier
22
+
23
+ # @return [String] Type of numbers to be ported. Either "business" or "residential".
24
+ # @!attribute port_type
25
+
26
+ # @return [String] The PIN or password needed to port out the numbers.
27
+ # @!attribute port_out_pin
28
+
29
+ # @return [String] the name associated with the account.
30
+ # @!attribute name_on_account
31
+
32
+ # @return [String] the name of the business.
33
+ # @!attribute name_of_business
34
+
35
+ # @return [String] the provider name.
36
+ # @!attribute provider_name
37
+
38
+ # @return [String] the E.164 billing number.
39
+ # @!attribute billing_number
40
+
41
+ # @return [String] the first billing address line.
42
+ # @!attribute billing_address1
43
+
44
+ # @return [String] the second billing address line.
45
+ # @!attribute billing_address2
46
+
47
+ # @return [String] the billing address city.
48
+ # @!attribute billing_city
49
+
50
+ # @return [String] the billing address state.
51
+ # @!attribute billing_state
52
+
53
+ # @return [String] the billing address zip.
54
+ # @!attribute billing_zip
55
+
56
+ # @return [String] the electronic signature used to sign the order.
57
+ # @!attribute esig
58
+
59
+ # @return [true | false]
60
+ # whether or not a bill will be provided. (only present on new orders)
61
+ # @!attribute has_bill
62
+
63
+ # @return [true | false]
64
+ # whether or not the legal agreement is accepted. (only present on new orders)
65
+ # @!attribute legal_agreement
66
+
67
+ has_normal_attributes %w[
68
+ id contact_number contact_email name_on_account name_of_business provider_name
69
+ billing_number billing_address1 billing_address2 account_identifier
70
+ billing_city billing_state billing_zip esig legal_agreement port_type port_out_pin
71
+ status
72
+ ]
73
+
74
+ # @return [Time] the time the order was created.
75
+ # @!attribute created_at
76
+
77
+ # @return [Time] the time the order was updated.
78
+ # @!attribute updated_at
79
+
80
+ # @return [Time] the time the bill for the order was received.
81
+ # @!attribute bill_received_at
82
+
83
+ # @return [Time] the time the order was requested for.
84
+ # @!attribute requested_for
85
+
86
+ # @return [Time] the time the order was completed.
87
+ # @!attribute completed_at
88
+
89
+ has_time_attributes %w[
90
+ created_at updated_at bill_received_at requested_for completed_at
91
+ ]
92
+
93
+ # @return [Phaxio::Resource::Collection<Phaxio::Resources::PortNumber>]
94
+ # a collection of port numbers associated with the order
95
+ # @!attribute port_numbers
96
+
97
+ has_collection_attributes({port_numbers: PortNumber})
98
+
99
+ class << self
100
+ # @macro paging
101
+ # List port orders in date range.
102
+ # @param params [Hash]
103
+ # Any parameters to send to Phaxio.
104
+ # - *created_before* [String] - RFC 3339 timestamp representing the end of the range.
105
+ # - *created_after* [String] - RFC 3339 timestamp representing the beginning of the range.
106
+ # @return [Phaxio::Resource::Collection<Phaxio::Resources::PortOrder>]
107
+ # The collection of port orders matching your request.
108
+ # @raise [Phaxio::Error::PhaxioError
109
+ # @see https://www.phaxio.com/docs/api/v2/port_orders/list_port_orders
110
+ def list params = {}
111
+ response = Client.request :get, port_orders_endpoint, params
112
+ response_collection response
113
+ end
114
+
115
+ # Create a port order.
116
+ # @param params [Hash]
117
+ # Any parameters to send to Phaxio.
118
+ # - *port_numbers* [Array<String>] - Numbers to port.
119
+ # - *contact_number* [String] - Number to contact about the port.
120
+ # - *contact_email* [String] - The email address for the order.
121
+ # - *account_identifier* [String] - The identifier for the account associated with the numbers.
122
+ # - *port_type* [String] - Type of numbers to be ported. Either "business" or "residential".
123
+ # - *port_out_pin* [String] - The PIN or password needed to port out the numbers.
124
+ # - *name_on_account* [String] - Name on the account for the port.
125
+ # - *name_of_business* [String] - Name of business associated with the port.
126
+ # - *provider_name* [String] - Name of provider for the port.
127
+ # - *esig* [String] - Electronic signature used to sign the order.
128
+ # - *legal_agreement* [true | false] - Indicates acceptance of the legal agreement.
129
+ # - *has_bill* [true | false] - Indicates whether or not a bill will be provided. If true, billing number
130
+ # and address fields are not needed.
131
+ # - *billing_number* [String] - Billing number.
132
+ # - *billing_address1* [String] - Billing address line 1
133
+ # - *billing_address2* [String] - Billing address line 2
134
+ # - *billing_city* [String] - Billing address city.
135
+ # - *billing_state* [String] - Billing address state.
136
+ # - *billing_zip* [String] - Billing address zip.
137
+ # @return [Phaxio::Resources::PortOrder]
138
+ # @raise [Phaxio::Error::PhaxioError]
139
+ # @see https://www.phaxio.com/docs/api/v2/port_orders/create_port_order
140
+ def create params = {}
141
+ response = Client.request :post, port_orders_endpoint, params
142
+ response_record response
143
+ end
144
+
145
+ # Get port order info.
146
+ # @param id [Integer]
147
+ # The ID of the order to retrieve.
148
+ # @param params [Hash]
149
+ # A hash of parameters to send to Phaxio. This action takes no unique parameters.
150
+ # @return [Phaxio::Resource::PortOrder]
151
+ # @raise [Phaxio::Error::PhaxioError]
152
+ # @see https://www.phaxio.com/docs/api/v2/port_orders/get_port_order
153
+ def get id, params = {}
154
+ response = Client.request :get, port_order_endpoint(id.to_i), params
155
+ response_record response
156
+ end
157
+ alias :retrieve :get
158
+ alias :find :get
159
+
160
+ private
161
+
162
+ def port_orders_endpoint
163
+ PORT_ORDERS_PATH
164
+ end
165
+
166
+ def port_order_endpoint id
167
+ "#{PORT_ORDERS_PATH}/#{id}"
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -46,7 +46,7 @@ module Phaxio
46
46
  # @return [Phaxio::Resource::Collection<Phaxio::Resources::AreaCode>] A collection of
47
47
  # AreaCode objects.
48
48
  # @raise [Phaxio::Error::PhaxioError]
49
- # @see https://www.phaxio.com/docs/api/v2/public/list_area_codes
49
+ # @see https://www.phaxio.com/docs/api/v2.1/public/list_area_codes
50
50
  def list params = {}
51
51
  response = Client.request :get, available_area_codes_endpoint, params
52
52
  AreaCode.response_collection response
@@ -36,7 +36,7 @@ module Phaxio
36
36
  # @return [Phaxio::Resource::Collection<Phaxio::Resources::Country>]
37
37
  # A collection of supported countries.
38
38
  # @raise Phaxio::Error::PhaxioError
39
- # @see https://www.phaxio.com/docs/api/v2/public/list_countries
39
+ # @see https://www.phaxio.com/docs/api/v2.1/public/list_countries
40
40
  def list params = {}
41
41
  response = Client.request :get, supported_countries_endpoint, params
42
42
  Country.response_collection response
@@ -0,0 +1,65 @@
1
+ module Phaxio
2
+ module Resources
3
+ # Provides utilities for working with webhooks.
4
+ # @see https://www.phaxio.com/docs/api/v2.1/faxes/send_webhook
5
+ # @see https://www.phaxio.com/docs/api/v2.1/faxes/receive_webhooks
6
+ class Webhook
7
+ DIGEST = OpenSSL::Digest.new('sha1')
8
+ private_constant :DIGEST
9
+
10
+ class << self
11
+ # Determines whether or not the passed signature is valid for the given
12
+ # url, params, and files.
13
+ # @param signature [String]
14
+ # The signature received from Phaxio.
15
+ # @param url [String]
16
+ # The webhook URL used in this request.
17
+ # @param params [Hash]
18
+ # The parameters received with the webhook, excluding files.
19
+ # @param files [Array<File>]
20
+ # The files received with the webhook, if any.
21
+ # @return [true, false]
22
+ # @raise [Phaxio::Error::PhaxioError]
23
+ # @see https://www.phaxio.com/docs/security/callbacks
24
+ def valid_signature? signature, url, params, files = []
25
+ check_signature = generate_check_signature url, params, files
26
+ check_signature == signature
27
+ end
28
+
29
+ private
30
+
31
+ def generate_check_signature url, params, files = []
32
+ params_string = generate_params_string(params)
33
+ files_string = generate_files_string(files)
34
+ webhook_data = "#{url}#{params_string}#{files_string}"
35
+ OpenSSL::HMAC.hexdigest(DIGEST, webhook_token, webhook_data)
36
+ end
37
+
38
+ def webhook_token
39
+ Phaxio.webhook_token or raise(Error::PhaxioError, 'No webhook token has been set')
40
+ end
41
+
42
+ def generate_params_string(params)
43
+ sorted_params = params.sort_by { |key, _value| key }
44
+ params_strings = sorted_params.map { |key, value| "#{key}#{value}" }
45
+ params_strings.join
46
+ end
47
+
48
+ def generate_files_string(files)
49
+ files_array = files_to_array(files).reject(&:nil?)
50
+ sorted_files = files_array.sort_by { |file| file[:name] }
51
+ files_strings = sorted_files.map { |file| generate_file_string(file) }
52
+ files_strings.join
53
+ end
54
+
55
+ def files_to_array(files)
56
+ files.is_a?(Array) ? files : [files]
57
+ end
58
+
59
+ def generate_file_string(file)
60
+ file[:name] + DIGEST.hexdigest(file[:tempfile].read)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,3 +1,3 @@
1
1
  module Phaxio
2
- VERSION = "2.1.0.pre"
2
+ VERSION = "2.1.0"
3
3
  end
data/lib/phaxio.rb CHANGED
@@ -17,7 +17,10 @@ Dir[File.expand_path(File.join('..', 'phaxio', 'helpers', '*.rb'), __FILE__)].ea
17
17
  require file
18
18
  end
19
19
 
20
- %w[fax_recipient fax account callback phax_code phone_number public ata].each do |filename|
20
+ %w[
21
+ fax_recipient fax account callback webhook phax_code phone_number public ata
22
+ port_number_note port_number port_order
23
+ ].each do |filename|
21
24
  require File.expand_path(File.join('..', 'phaxio', 'resources', filename), __FILE__)
22
25
  end
23
26
 
@@ -29,11 +32,13 @@ module Phaxio
29
32
  # @see Config.api_key
30
33
  # @!attribute api_secret
31
34
  # @see Config.api_secret
35
+ # @!attribute webhook_token
36
+ # @see Config.webhook_token
32
37
  # @!attribute callback_token
33
- # @see Config.callback_token
38
+ # @see Config.webhook_token
34
39
  # @!attribute api_endpoint
35
40
  # @see Config.api_endpoint
36
- %w(api_key api_secret callback_token api_endpoint).each do |config_attribute|
41
+ %w(api_key api_secret webhook_token callback_token api_endpoint).each do |config_attribute|
37
42
  # Define getters
38
43
  define_method(config_attribute) do
39
44
  Config.public_send config_attribute
@@ -45,5 +50,9 @@ module Phaxio
45
50
  Config.public_send setter, value
46
51
  end
47
52
  end
53
+
54
+ # for backwards compatibility
55
+ alias callback_token webhook_token
56
+ alias callback_token= webhook_token=
48
57
  end
49
58
  end
data/spec/phaxio_spec.rb CHANGED
@@ -13,8 +13,14 @@ RSpec.describe Phaxio do
13
13
  expect(subject.api_secret).to eq('test-api-secret')
14
14
  end
15
15
 
16
- it 'sets the callback token' do
16
+ it 'sets the webhook token' do
17
+ subject.webhook_token = 'test-webhook-token'
18
+ expect(subject.webhook_token).to eq('test-webhook-token')
19
+ end
20
+
21
+ it 'sets and gets the webhook token as callback_token' do
17
22
  subject.callback_token = 'test-callback-token'
18
23
  expect(subject.callback_token).to eq('test-callback-token')
24
+ expect(subject.webhook_token).to eq('test-callback-token')
19
25
  end
20
26
  end
@@ -1,16 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Account do
4
- describe 'getting account information' do
4
+ describe 'getting account information', vcr: 'account/get' do
5
5
  let(:action) { Account.get params }
6
6
  let(:params) { {} }
7
7
 
8
- around do |example|
9
- VCR.use_cassette('resources/account/status') do
10
- example.run
11
- end
12
- end
13
-
14
8
  it 'sends the request to Phaxio' do
15
9
  expect_api_request :get, 'account/status', params
16
10
  action
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ata do
4
+ describe Ata::Reference, vcr: 'ata/reference' do
5
+ let(:reference) { Ata::Reference.new ata_id }
6
+ let(:ata_id) { Ata.create(name: 'Test ATA').id }
7
+
8
+ describe '#get' do
9
+ it 'returns information about the referenced ATA' do
10
+ result = reference.get
11
+ expect(result).to be_a(Ata)
12
+ expect(result.name).to eq('Test ATA')
13
+ end
14
+ end
15
+ end
16
+
17
+ describe Ata::ProvisioningURLs, vcr: 'ata/provisioning_urls' do
18
+ let(:provisioning_urls) { Ata.provisioning_urls }
19
+
20
+ describe '#urls' do
21
+ it 'returns the full hash of provisioning URLS' do
22
+ expect(provisioning_urls.urls).to be_a(Hash)
23
+ expect(provisioning_urls.urls.keys).to match_array([
24
+ 'OBi',
25
+ 'Grandstream',
26
+ 'Netgen',
27
+ ])
28
+ end
29
+ end
30
+
31
+ describe '#grandstream' do
32
+ it 'returns the grandstream provisioning URL' do
33
+ url = provisioning_urls.urls['Grandstream']
34
+ expect(provisioning_urls.grandstream).to eq(url)
35
+ end
36
+ end
37
+
38
+ describe '#obi' do
39
+ it 'returns the obi provisioning URL' do
40
+ url = provisioning_urls.urls['OBi']
41
+ expect(provisioning_urls.obi).to eq(url)
42
+ end
43
+ end
44
+
45
+ describe '#netgen' do
46
+ it 'returns the netgen provisioning url' do
47
+ url = provisioning_urls.urls['Netgen']
48
+ expect(provisioning_urls.netgen).to eq(url)
49
+ end
50
+ end
51
+ end
52
+
53
+ describe 'getting a list of ATAs', vcr: 'ata/list' do
54
+ let(:action) { Ata.list params }
55
+ let(:params) { {} }
56
+
57
+ it 'sends the request to phaxio' do
58
+ expect_api_request :get, 'atas', params
59
+ action
60
+ end
61
+
62
+ it 'returns a collection of ATAs' do
63
+ result = action
64
+ expect(result).to be_a(Ata::Collection)
65
+ end
66
+ end
67
+
68
+ describe 'creating an ATA', vcr: 'ata/create' do
69
+ let(:action) { Ata.create params }
70
+ let(:params) { {name: 'Test ATA'} }
71
+
72
+ it 'sends the request to phaxio' do
73
+ expect_api_request :post, 'atas', name: 'Test ATA'
74
+ action
75
+ end
76
+
77
+ it 'returns information about the created ATA' do
78
+ result = action
79
+ expect(result).to be_a(Ata)
80
+ expect(result.name).to eq('Test ATA')
81
+ end
82
+ end
83
+
84
+ describe 'getting information about an ATA', vcr: 'ata/get' do
85
+ let(:action) { Ata.get ata_id, params }
86
+ let(:ata_id) { Ata.create(name: 'Test ATA').id }
87
+ let(:params) { {} }
88
+
89
+ it 'sends the request to phaxio' do
90
+ expect_api_request :get, "atas/#{ata_id}", params
91
+ action
92
+ end
93
+
94
+ it 'returns information about the ATA' do
95
+ result = action
96
+ expect(result).to be_a(Ata)
97
+ expect(result.name).to eq('Test ATA')
98
+ end
99
+ end
100
+
101
+ describe 'updating an ATA', vcr: 'ata/update' do
102
+ let(:action) { Ata.update ata_id, params }
103
+ let(:ata_id) { Ata.create(name: 'Test ATA').id }
104
+ let(:params) { {name: 'New Name'} }
105
+
106
+ it 'sends the request to phaxio' do
107
+ expect_api_request :patch, "atas/#{ata_id}", params
108
+ action
109
+ end
110
+
111
+ it 'returns information about the updated ATA' do
112
+ result = action
113
+ expect(result).to be_a(Ata)
114
+ expect(result.name).to eq('New Name')
115
+ end
116
+ end
117
+
118
+ describe 'regenerating ATA credentials', vcr: 'ata/regenerate' do
119
+ let(:action) { Ata.regenerate_credentials ata_id, params }
120
+ let(:ata) { Ata.create(name: 'Test ATA') }
121
+ let(:ata_id) { ata.id }
122
+ let(:params) { {} }
123
+
124
+ it 'sends the request to phaxio' do
125
+ expect_api_request :patch, "atas/#{ata_id}/regenerate_credentials", params
126
+ action
127
+ end
128
+
129
+ it 'returns information about the ATA' do
130
+ original_username = ata.username
131
+ # some actions don't return full creds; creation does, but run a sanity check just in case
132
+ expect(original_username).to_not be_nil
133
+ result = action
134
+ expect(result).to be_a(Ata)
135
+ expect(result.username).to_not eq(original_username)
136
+ expect(result.username).to_not be_nil
137
+ end
138
+ end
139
+
140
+ describe 'deleting an ATA', vcr: 'ata/delete' do
141
+ let(:action) { Ata.delete ata_id, params }
142
+ let(:ata_id) { Ata.create(name: 'Test ATA').id }
143
+ let(:params) { {} }
144
+
145
+ it 'sends the request to phaxio' do
146
+ expect_api_request :delete, "atas/#{ata_id}", params
147
+ action
148
+ end
149
+
150
+ it 'returns a reference to the deleted ATA' do
151
+ result = action
152
+ expect(result).to be_a(Ata::Reference)
153
+ expect(result.id).to eq(ata_id)
154
+ end
155
+ end
156
+
157
+ describe 'adding a phone number to an ATA', vcr: 'ata/add_phone_number' do
158
+ let(:action) { Ata.add_phone_number ata_id, TEST_NUMBER, params }
159
+ let(:ata_id) { Ata.create(name: 'Test ATA').id }
160
+ let(:params) { {} }
161
+
162
+ it 'sends the request to phaxio' do
163
+ expect_api_request :post, "atas/#{ata_id}/phone_numbers/#{TEST_NUMBER}", params
164
+ action
165
+ end
166
+
167
+ it 'returns a reference to the added phone number' do
168
+ result = action
169
+ expect(result).to be_a(PhoneNumber::Reference)
170
+ end
171
+ end
172
+
173
+ describe 'removing a phone number from an ATA', vcr: 'ata/remove_phone_number' do
174
+ let(:action) { Ata.remove_phone_number ata_id, TEST_NUMBER, params }
175
+ let(:ata_id) { Ata.create(name: 'Test ATA').id }
176
+ let(:params) { {} }
177
+
178
+ before do
179
+ Ata.add_phone_number ata_id, TEST_NUMBER
180
+ end
181
+
182
+ it 'sends the request to phaxio' do
183
+ expect_api_request :delete, "atas/#{ata_id}/phone_numbers/#{TEST_NUMBER}", params
184
+ action
185
+ end
186
+
187
+ it 'returns a reference to the removed phone number' do
188
+ result = action
189
+ expect(result).to be_a(PhoneNumber::Reference)
190
+ end
191
+ end
192
+
193
+ describe 'listing provisioning URLs for an ATA', vcr: 'ata/provisioning_urls' do
194
+ let(:action) { Ata.provisioning_urls params }
195
+ let(:params) { {} }
196
+
197
+ it 'sends the request to phaxio' do
198
+ expect_api_request :get, "atas/provisioning_urls", params
199
+ action
200
+ end
201
+
202
+ it 'returns a set of provisioning URLs' do
203
+ response = action
204
+ expect(response).to be_a(Ata::ProvisioningURLs)
205
+ end
206
+ end
207
+ end