phaxio 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +2 -1
  3. data/README.md +53 -20
  4. data/lib/phaxio/client.rb +46 -16
  5. data/lib/phaxio/config.rb +7 -5
  6. data/lib/phaxio/resource.rb +11 -5
  7. data/lib/phaxio/resources/account.rb +1 -1
  8. data/lib/phaxio/resources/ata.rb +285 -0
  9. data/lib/phaxio/resources/callback.rb +10 -56
  10. data/lib/phaxio/resources/fax.rb +11 -11
  11. data/lib/phaxio/resources/phax_code.rb +2 -2
  12. data/lib/phaxio/resources/phone_number.rb +31 -5
  13. data/lib/phaxio/resources/port_number.rb +42 -0
  14. data/lib/phaxio/resources/port_number_note.rb +51 -0
  15. data/lib/phaxio/resources/port_order.rb +172 -0
  16. data/lib/phaxio/resources/public/area_code.rb +1 -1
  17. data/lib/phaxio/resources/public/country.rb +1 -1
  18. data/lib/phaxio/resources/webhook.rb +65 -0
  19. data/lib/phaxio/version.rb +1 -1
  20. data/lib/phaxio.rb +13 -3
  21. data/phaxio.gemspec +2 -1
  22. data/spec/client_spec.rb +38 -6
  23. data/spec/phaxio_spec.rb +7 -1
  24. data/spec/resources/account_spec.rb +1 -7
  25. data/spec/resources/ata_spec.rb +207 -0
  26. data/spec/resources/fax_spec.rb +42 -89
  27. data/spec/resources/phax_code_spec.rb +26 -32
  28. data/spec/resources/phone_number_spec.rb +19 -30
  29. data/spec/resources/port_number_note_spec.rb +33 -0
  30. data/spec/resources/port_number_spec.rb +32 -0
  31. data/spec/resources/port_order_spec.rb +76 -0
  32. data/spec/resources/public/area_code_spec.rb +1 -1
  33. data/spec/resources/public/country_spec.rb +1 -7
  34. data/spec/resources/{callback_spec.rb → webhook_spec.rb} +8 -8
  35. data/spec/spec_helper.rb +1 -0
  36. data/spec/support/{vcr_cassettes/resources/account/status.yml → cassettes/account/get.yml} +13 -14
  37. data/spec/support/cassettes/ata/add_phone_number.yml +89 -0
  38. data/spec/support/cassettes/ata/create.yml +46 -0
  39. data/spec/support/cassettes/ata/delete.yml +86 -0
  40. data/spec/support/cassettes/ata/get.yml +87 -0
  41. data/spec/support/cassettes/ata/list.yml +67 -0
  42. data/spec/support/cassettes/ata/provisioning_urls.yml +43 -0
  43. data/spec/support/cassettes/ata/reference.yml +87 -0
  44. data/spec/support/cassettes/ata/regenerate.yml +89 -0
  45. data/spec/support/cassettes/ata/remove_phone_number.yml +130 -0
  46. data/spec/support/cassettes/ata/update.yml +89 -0
  47. data/spec/support/cassettes/fax/cancel.yml +90 -0
  48. data/spec/support/cassettes/fax/create.yml +48 -0
  49. data/spec/support/cassettes/fax/delete.yml +88 -0
  50. data/spec/support/cassettes/fax/delete_file.yml +88 -0
  51. data/spec/support/cassettes/fax/file.yml +93 -0
  52. data/spec/support/cassettes/fax/get.yml +88 -0
  53. data/spec/support/cassettes/fax/list.yml +49 -0
  54. data/spec/support/cassettes/fax/reference.yml +88 -0
  55. data/spec/support/cassettes/fax/resend.yml +90 -0
  56. data/spec/support/cassettes/fax/test_receive.yml +49 -0
  57. data/spec/support/{vcr_cassettes/resources/fax/resend.yml → cassettes/phax_code/create.yml} +14 -15
  58. data/spec/support/cassettes/phax_code/create_png.yml +50 -0
  59. data/spec/support/cassettes/phax_code/get_by_id.yml +86 -0
  60. data/spec/support/{vcr_cassettes/resources/fax/delete.yml → cassettes/phax_code/get_default.yml} +14 -15
  61. data/spec/support/cassettes/phax_code/get_default_png.yml +48 -0
  62. data/spec/support/cassettes/phax_code/get_png_by_id.yml +90 -0
  63. data/spec/support/{vcr_cassettes/resources → cassettes}/phone_number/create.yml +15 -16
  64. data/spec/support/cassettes/phone_number/get.yml +44 -0
  65. data/spec/support/cassettes/phone_number/list.yml +72 -0
  66. data/spec/support/cassettes/phone_number/reference.yml +45 -0
  67. data/spec/support/cassettes/phone_number/release.yml +86 -0
  68. data/spec/support/cassettes/port_number/get.yml +88 -0
  69. data/spec/support/cassettes/port_number_note/list.yml +88 -0
  70. data/spec/support/cassettes/port_order/create.yml +48 -0
  71. data/spec/support/cassettes/port_order/get.yml +91 -0
  72. data/spec/support/cassettes/port_order/list.yml +52 -0
  73. data/spec/support/{vcr_cassettes/resources/public/area_codes → cassettes/public/area_code}/list.yml +18 -18
  74. data/spec/support/{vcr_cassettes/resources → cassettes}/public/country/list.yml +14 -15
  75. data/spec/support/files/test.txt +1 -0
  76. data/spec/support/vcr.rb +25 -8
  77. metadata +125 -31
  78. data/spec/support/credentials.rb +0 -7
  79. data/spec/support/vcr_cassettes/resources/fax/cancel.yml +0 -46
  80. data/spec/support/vcr_cassettes/resources/fax/create.yml +0 -230
  81. data/spec/support/vcr_cassettes/resources/fax/delete_file.yml +0 -44
  82. data/spec/support/vcr_cassettes/resources/fax/file.yml +0 -251
  83. data/spec/support/vcr_cassettes/resources/fax/get.yml +0 -44
  84. data/spec/support/vcr_cassettes/resources/fax/list.yml +0 -56
  85. data/spec/support/vcr_cassettes/resources/fax/test_receive.yml +0 -231
  86. data/spec/support/vcr_cassettes/resources/phax_code/create.yml +0 -100
  87. data/spec/support/vcr_cassettes/resources/phax_code/get.yml +0 -190
  88. data/spec/support/vcr_cassettes/resources/phone_number/get.yml +0 -45
  89. data/spec/support/vcr_cassettes/resources/phone_number/list.yml +0 -52
  90. data/spec/support/vcr_cassettes/resources/phone_number/release.yml +0 -44
@@ -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
@@ -2,19 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Fax do
4
4
  let(:test_file) { File.open test_file_path }
5
- let(:test_file_path) { File.expand_path(File.join('..', '..', 'support', 'files', 'test.pdf'), __FILE__) }
6
- let(:test_recipient_number) { ENV.fetch 'TEST_RECIPIENT_NUMBER' }
5
+ let(:test_file_path) { File.join File.expand_path('..', __dir__), 'support', 'files', 'test.pdf' }
6
+ let(:test_recipient_number) { TEST_NUMBER }
7
7
 
8
- describe 'creating a fax' do
8
+ describe 'creating a fax', vcr: 'fax/create' do
9
9
  let(:action) { Fax.create params }
10
10
  let(:params) { {to: test_recipient_number, file: test_file} }
11
11
 
12
- around(:each) do |example|
13
- VCR.use_cassette('resources/fax/create') do
14
- example.run
15
- end
16
- end
17
-
18
12
  it 'makes the request to Phaxio' do
19
13
  expect_api_request :post, 'faxes', to: test_recipient_number, file: test_file
20
14
  action
@@ -27,17 +21,11 @@ RSpec.describe Fax do
27
21
  end
28
22
  end
29
23
 
30
- describe 'retrieving a fax' do
24
+ describe 'retrieving a fax', vcr: 'fax/get' do
31
25
  let(:action) { Fax.get fax_id, params }
32
- let(:fax_id) { 1234 }
26
+ let(:fax_id) { Fax.create(to: test_recipient_number, file: test_file).id }
33
27
  let(:params) { {} }
34
28
 
35
- around(:each) do |example|
36
- VCR.use_cassette('resources/fax/get') do
37
- example.run
38
- end
39
- end
40
-
41
29
  it 'makes the request to Phaxio' do
42
30
  expect_api_request :get, "faxes/#{fax_id}", params
43
31
  action
@@ -50,47 +38,28 @@ RSpec.describe Fax do
50
38
  end
51
39
  end
52
40
 
53
- # TODO: Refactor this
54
- # This one's a little tricky, since it relies on having a fax to cancel.
55
- describe 'cancelling a fax' do
56
- let(:action) { Fax.cancel @fax_id, params }
41
+ describe 'cancelling a fax', vcr: 'fax/cancel' do
42
+ let(:action) { Fax.cancel fax_id, params }
43
+ let(:fax_id) { Fax.create(to: test_recipient_number, file: test_file).id }
57
44
  let(:params) { {} }
58
45
 
59
- before do
60
- VCR.use_cassette('resources/fax/create') do
61
- @fax_id = Fax.create(to: test_recipient_number, file: test_file).id
62
- end
63
- end
64
-
65
- around(:each) do |example|
66
- VCR.use_cassette('resources/fax/cancel') do
67
- example.run
68
- end
69
- end
70
-
71
46
  it 'makes the request to Phaxio' do
72
- expect_api_request :post, "faxes/#{@fax_id}/cancel", params
47
+ expect_api_request :post, "faxes/#{fax_id}/cancel", params
73
48
  action
74
49
  end
75
50
 
76
51
  it 'returns a reference to the fax' do
77
52
  result = action
78
53
  expect(result).to be_a(Fax::Reference)
79
- expect(result.id).to eq(@fax_id)
54
+ expect(result.id).to eq(fax_id)
80
55
  end
81
56
  end
82
57
 
83
- describe 'listing faxes' do
58
+ describe 'listing faxes', vcr: 'fax/list' do
84
59
  let(:action) { Fax.list params }
85
60
  let(:params) { {created_before: time} }
86
61
  let(:time) { Time.new 2017, 10, 28, 0, 17, 0, 0 }
87
62
 
88
- around do |example|
89
- VCR.use_cassette('resources/fax/list') do
90
- example.run
91
- end
92
- end
93
-
94
63
  it 'sends the request to phaxio' do
95
64
  expect_api_request :get, 'faxes', params
96
65
  action
@@ -102,17 +71,15 @@ RSpec.describe Fax do
102
71
  end
103
72
  end
104
73
 
105
- describe 'resending a fax' do
74
+ describe 'resending a fax', vcr: 'fax/resend' do
106
75
  let(:action) { Fax.resend fax_id, params }
107
- let(:fax_id) { 1234 }
76
+ let(:fax_id) {
77
+ fax_id = Fax.create(to: test_recipient_number, file: test_file).id
78
+ sleep 30 if VCR.current_cassette.recording?
79
+ fax_id
80
+ }
108
81
  let(:params) { {} }
109
82
 
110
- around do |example|
111
- VCR.use_cassette('resources/fax/resend') do
112
- example.run
113
- end
114
- end
115
-
116
83
  it 'makes the request to Phaxio' do
117
84
  expect_api_request :post, "faxes/#{fax_id}/resend", params
118
85
  action
@@ -125,17 +92,15 @@ RSpec.describe Fax do
125
92
  end
126
93
  end
127
94
 
128
- describe 'deleting a fax' do
95
+ describe 'deleting a fax', vcr: 'fax/delete' do
129
96
  let(:action) { Fax.delete fax_id, params }
130
- let(:fax_id) { 1234 }
97
+ let(:fax_id) {
98
+ fax_id = Fax.create(to: test_recipient_number, file: test_file).id
99
+ sleep 30 if VCR.current_cassette.recording?
100
+ fax_id
101
+ }
131
102
  let(:params) { {} }
132
103
 
133
- around do |example|
134
- VCR.use_cassette('resources/fax/delete') do
135
- example.run
136
- end
137
- end
138
-
139
104
  it 'makes the request to Phaxio' do
140
105
  expect_api_request :delete, "faxes/#{fax_id}", params
141
106
  action
@@ -147,17 +112,15 @@ RSpec.describe Fax do
147
112
  end
148
113
  end
149
114
 
150
- describe 'deleting a fax file' do
115
+ describe 'deleting a fax file', vcr: 'fax/delete_file' do
151
116
  let(:action) { Fax.delete_file fax_id, params }
152
- let(:fax_id) { 1234 }
117
+ let(:fax_id) {
118
+ fax_id = Fax.create(to: test_recipient_number, file: test_file).id
119
+ sleep 30 if VCR.current_cassette.recording?
120
+ fax_id
121
+ }
153
122
  let(:params) { {} }
154
123
 
155
- around do |example|
156
- VCR.use_cassette('resources/fax/delete_file') do
157
- example.run
158
- end
159
- end
160
-
161
124
  it 'makes the request to Phaxio' do
162
125
  expect_api_request :delete, "faxes/#{fax_id}/file", params
163
126
  action
@@ -169,17 +132,15 @@ RSpec.describe Fax do
169
132
  end
170
133
  end
171
134
 
172
- describe 'downloading a fax file' do
135
+ describe 'downloading a fax file', vcr: 'fax/file' do
173
136
  let(:action) { Fax.file fax_id, params }
174
- let(:fax_id) { 1234 }
137
+ let(:fax_id) {
138
+ fax_id = Fax.create(to: test_recipient_number, file: test_file).id
139
+ sleep 30 if VCR.current_cassette.recording?
140
+ fax_id
141
+ }
175
142
  let(:params) { {} }
176
143
 
177
- around do |example|
178
- VCR.use_cassette('resources/fax/file') do
179
- example.run
180
- end
181
- end
182
-
183
144
  it 'makes the request to phaxio' do
184
145
  expect_api_request :get, "faxes/#{fax_id}/file", params
185
146
  action
@@ -191,16 +152,10 @@ RSpec.describe Fax do
191
152
  end
192
153
  end
193
154
 
194
- describe 'receiving a test fax' do
155
+ describe 'receiving a test fax', vcr: 'fax/test_receive' do
195
156
  let(:action) { Fax.test_receive params }
196
157
  let(:params) { {file: test_file} }
197
158
 
198
- around do |example|
199
- VCR.use_cassette('resources/fax/test_receive') do
200
- example.run
201
- end
202
- end
203
-
204
159
  it 'makes the request to Phaxio' do
205
160
  expect_api_request :post, 'faxes', {file: test_file, direction: 'received'}
206
161
  action
@@ -212,16 +167,14 @@ RSpec.describe Fax do
212
167
  end
213
168
  end
214
169
 
215
- describe Fax::Reference do
216
- let(:fax_id) { 1234 }
170
+ describe Fax::Reference, vcr: 'fax/reference' do
171
+ let(:fax_id) { Fax.create(to: test_recipient_number, file: test_file).id }
217
172
 
218
173
  it 'gets the full fax' do
219
- VCR.use_cassette('resources/fax/get') do
220
- reference = Fax::Reference.new fax_id
221
- result = reference.get
222
- expect(result).to be_a(Fax)
223
- expect(result.id).to eq(1234)
224
- end
174
+ reference = Fax::Reference.new fax_id
175
+ result = reference.get
176
+ expect(result).to be_a(Fax)
177
+ expect(result.id).to eq(fax_id)
225
178
  end
226
179
  end
227
180
  end
@@ -5,23 +5,19 @@ RSpec.describe PhaxCode do
5
5
  let(:action) { PhaxCode.create params }
6
6
  let(:params) { {metadata: 'This is a test PhaxCode'} }
7
7
 
8
- around do |example|
9
- VCR.use_cassette('resources/phax_code/create') do
10
- example.run
8
+ context 'default type', vcr: 'phax_code/create' do
9
+ it 'makes the request to phaxio' do
10
+ expect_api_request :post, 'phax_codes', params
11
+ action
11
12
  end
12
- end
13
-
14
- it 'makes the request to phaxio' do
15
- expect_api_request :post, 'phax_codes', params
16
- action
17
- end
18
13
 
19
- it 'returns a PhaxCode instance by default' do
20
- result = action
21
- expect(result).to be_a(PhaxCode)
14
+ it 'returns a PhaxCode instance by default' do
15
+ result = action
16
+ expect(result).to be_a(PhaxCode)
17
+ end
22
18
  end
23
19
 
24
- context 'type is specified to be png' do
20
+ context 'type is specified to be png', vcr: 'phax_code/create_png' do
25
21
  let(:params) { {metadata: 'This is a test PhaxCode', type: 'png'} }
26
22
 
27
23
  it 'returns a png if type is specified to be png' do
@@ -35,25 +31,21 @@ RSpec.describe PhaxCode do
35
31
  let(:action) { PhaxCode.get params }
36
32
  let(:params) { {} }
37
33
 
38
- around do |example|
39
- VCR.use_cassette('resources/phax_code/get') do
40
- example.run
34
+ context 'default', vcr: 'phax_code/get_default' do
35
+ it 'makes the request to Phaxio' do
36
+ expect_api_request :get, 'phax_code', params
37
+ action
41
38
  end
42
- end
43
-
44
- it 'makes the request to Phaxio' do
45
- expect_api_request :get, 'phax_code', params
46
- action
47
- end
48
39
 
49
- context 'getting the default phax code with no type specified' do
50
- it 'returns a PhaxCode instance' do
51
- result = action
52
- expect(result).to be_a(PhaxCode)
40
+ context 'getting the default phax code with no type specified' do
41
+ it 'returns a PhaxCode instance' do
42
+ result = action
43
+ expect(result).to be_a(PhaxCode)
44
+ end
53
45
  end
54
46
  end
55
47
 
56
- context 'getting the default phax code with png type specified' do
48
+ context 'getting the default phax code with png type specified', vcr: 'phax_code/get_default_png' do
57
49
  let(:params) { {type: 'png'} }
58
50
 
59
51
  it 'returns a file' do
@@ -62,8 +54,9 @@ RSpec.describe PhaxCode do
62
54
  end
63
55
  end
64
56
 
65
- context 'getting a particular phax code with no type specified' do
66
- let(:params) { {identifier: '-Y3jxX'} }
57
+ context 'getting a particular phax code with no type specified', vcr: 'phax_code/get_by_id' do
58
+ let(:params) { {identifier: phax_code_identifier} }
59
+ let(:phax_code_identifier) { PhaxCode.create(metadata: 'Test Phax Code').identifier }
67
60
 
68
61
  it 'returns a PhaxCode instance' do
69
62
  result = action
@@ -71,8 +64,9 @@ RSpec.describe PhaxCode do
71
64
  end
72
65
  end
73
66
 
74
- context 'getting a particular phax code with png type specified' do
75
- let(:params) { {identifier: '-Y3jxX', type: 'png'} }
67
+ context 'getting a particular phax code with png type specified', vcr: 'phax_code/get_png_by_id' do
68
+ let(:params) { {identifier: phax_code_identifier, type: 'png'} }
69
+ let(:phax_code_identifier) { PhaxCode.create(metadata: 'Test Phax Code').identifier }
76
70
 
77
71
  it 'returns a file' do
78
72
  result = action
@@ -80,4 +74,4 @@ RSpec.describe PhaxCode do
80
74
  end
81
75
  end
82
76
  end
83
- end
77
+ end
@@ -1,15 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe PhoneNumber do
4
- describe 'provisioning a number' do
5
- let(:action) { PhoneNumber.create params }
6
- let(:params) { {country_code: 1, area_code: 225} }
7
-
8
- around do |example|
9
- VCR.use_cassette('resources/phone_number/create') do
10
- example.run
4
+ describe PhoneNumber::Reference, vcr: 'phone_number/reference' do
5
+ describe '#get' do
6
+ it 'returns information about the referenced number' do
7
+ reference = PhoneNumber::Reference.new TEST_NUMBER
8
+ result = reference.get
9
+ expect(result).to be_a(PhoneNumber)
10
+ expect(result.phone_number).to eq(TEST_NUMBER)
11
11
  end
12
12
  end
13
+ end
14
+
15
+ describe 'provisioning a number', vcr: 'phone_number/create' do
16
+ let(:action) { PhoneNumber.create params }
17
+ let(:params) { {country_code: 1, area_code: 225} }
13
18
 
14
19
  it 'makes the request to Phaxio' do
15
20
  expect_api_request :post, 'phone_numbers', params
@@ -22,17 +27,11 @@ RSpec.describe PhoneNumber do
22
27
  end
23
28
  end
24
29
 
25
- describe 'getting information about a number' do
30
+ describe 'getting information about a number', vcr: 'phone_number/get' do
26
31
  let(:action) { PhoneNumber.get phone_number, params }
27
- let(:phone_number) { '12258675309' }
32
+ let(:phone_number) { TEST_NUMBER }
28
33
  let(:params) { {} }
29
34
 
30
- around do |example|
31
- VCR.use_cassette('resources/phone_number/get') do
32
- example.run
33
- end
34
- end
35
-
36
35
  it 'makes the request to Phaxio' do
37
36
  expect_api_request :get, "phone_numbers/#{phone_number}"
38
37
  action
@@ -44,16 +43,10 @@ RSpec.describe PhoneNumber do
44
43
  end
45
44
  end
46
45
 
47
- describe 'listing numbers' do
46
+ describe 'listing numbers', vcr: 'phone_number/list' do
48
47
  let(:action) { PhoneNumber.list params }
49
48
  let(:params) { {} }
50
49
 
51
- around do |example|
52
- VCR.use_cassette('resources/phone_number/list') do
53
- example.run
54
- end
55
- end
56
-
57
50
  it 'makes the request to Phaxio' do
58
51
  expect_api_request :get, 'phone_numbers', params
59
52
  action
@@ -65,17 +58,13 @@ RSpec.describe PhoneNumber do
65
58
  end
66
59
  end
67
60
 
68
- describe 'releasing a number' do
61
+ describe 'releasing a number', vcr: 'phone_number/release' do
69
62
  let(:action) { PhoneNumber.release phone_number, params }
70
- let(:phone_number) { '+12258675309' }
63
+ let(:phone_number) {
64
+ PhoneNumber.provision(country_code: 1, area_code: 225).phone_number
65
+ }
71
66
  let(:params) { {} }
72
67
 
73
- around do |example|
74
- VCR.use_cassette('resources/phone_number/release') do
75
- example.run
76
- end
77
- end
78
-
79
68
  it 'sends the request to Phaxio' do
80
69
  expect_api_request :delete, "phone_numbers/#{phone_number}", params
81
70
  action
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PortNumberNote do
4
+ describe 'getting a list of notes', vcr: 'port_number_note/list' do
5
+ let(:action) { PortNumberNote.list port_number_id, params }
6
+ let(:port_number_id) {
7
+ PortOrder.create(
8
+ port_numbers: [TEST_NUMBER],
9
+ contact_number: TEST_NUMBER,
10
+ contact_email: 'julien@phaxio.com',
11
+ account_identifier: '1234',
12
+ name_on_account: 'THIS IS A TEST',
13
+ provider_name: 'DO NOT PORT --Julien',
14
+ has_bill: true,
15
+ legal_agreement: true,
16
+ port_type: 'residential',
17
+ esig: 'NOT A VALID SIGNATURE'
18
+ ).port_numbers[0].id
19
+ }
20
+
21
+ let(:params) { {} }
22
+
23
+ it 'makes the request to phaxio' do
24
+ expect_api_request :get, "port_numbers/#{port_number_id}/notes", params
25
+ action
26
+ end
27
+
28
+ it 'returns a collection of port number note objects' do
29
+ result = action
30
+ expect(result).to be_a(Phaxio::Resource::Collection)
31
+ end
32
+ end
33
+ end