phaxio 0.4.0 → 2.1.0.pre

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 +7 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +11 -5
  5. data/README.md +296 -40
  6. data/Rakefile +7 -9
  7. data/lib/phaxio.rb +48 -3
  8. data/lib/phaxio/client.rb +151 -241
  9. data/lib/phaxio/config.rb +31 -0
  10. data/lib/phaxio/error.rb +13 -0
  11. data/lib/phaxio/helpers/mime_type_helper.rb +14 -0
  12. data/lib/phaxio/resource.rb +168 -0
  13. data/lib/phaxio/resources.rb +7 -0
  14. data/lib/phaxio/resources/account.rb +41 -0
  15. data/lib/phaxio/resources/ata.rb +219 -0
  16. data/lib/phaxio/resources/callback.rb +65 -0
  17. data/lib/phaxio/resources/fax.rb +310 -0
  18. data/lib/phaxio/resources/fax_recipient.rb +41 -0
  19. data/lib/phaxio/resources/phax_code.rb +89 -0
  20. data/lib/phaxio/resources/phone_number.rb +112 -0
  21. data/lib/phaxio/resources/public.rb +8 -0
  22. data/lib/phaxio/resources/public/area_code.rb +64 -0
  23. data/lib/phaxio/resources/public/country.rb +54 -0
  24. data/lib/phaxio/version.rb +1 -1
  25. data/phaxio.gemspec +10 -8
  26. data/spec/client_spec.rb +164 -0
  27. data/spec/helpers/mime_type_helper_spec.rb +11 -0
  28. data/spec/phaxio_spec.rb +20 -0
  29. data/spec/resources/account_spec.rb +24 -0
  30. data/spec/resources/callback_spec.rb +34 -0
  31. data/spec/resources/fax_spec.rb +248 -0
  32. data/spec/resources/phax_code_spec.rb +111 -0
  33. data/spec/resources/phone_number_spec.rb +89 -0
  34. data/spec/resources/public/area_code_spec.rb +24 -0
  35. data/spec/resources/public/country_spec.rb +24 -0
  36. data/spec/spec_helper.rb +6 -0
  37. data/spec/support/credentials.rb +7 -0
  38. data/spec/support/expectations.rb +9 -0
  39. data/spec/support/files/test.pdf +0 -0
  40. data/spec/support/files/test.txt +1 -0
  41. data/spec/support/vcr.rb +8 -0
  42. data/spec/support/vcr_cassettes/resources/account/status.yml +45 -0
  43. data/spec/support/vcr_cassettes/resources/fax/cancel.yml +47 -0
  44. data/spec/support/vcr_cassettes/resources/fax/create.yml +50 -0
  45. data/spec/support/vcr_cassettes/resources/fax/create_for_cancel.yml +50 -0
  46. data/spec/support/vcr_cassettes/resources/fax/create_for_delete.yml +50 -0
  47. data/spec/support/vcr_cassettes/resources/fax/create_for_delete_file.yml +50 -0
  48. data/spec/support/vcr_cassettes/resources/fax/create_for_download_file.yml +50 -0
  49. data/spec/support/vcr_cassettes/resources/fax/create_for_get.yml +50 -0
  50. data/spec/support/vcr_cassettes/resources/fax/create_for_reference.yml +50 -0
  51. data/spec/support/vcr_cassettes/resources/fax/create_for_resend.yml +50 -0
  52. data/spec/support/vcr_cassettes/resources/fax/delete.yml +45 -0
  53. data/spec/support/vcr_cassettes/resources/fax/delete_file.yml +45 -0
  54. data/spec/support/vcr_cassettes/resources/fax/file.yml +50 -0
  55. data/spec/support/vcr_cassettes/resources/fax/get.yml +45 -0
  56. data/spec/support/vcr_cassettes/resources/fax/list.yml +51 -0
  57. data/spec/support/vcr_cassettes/resources/fax/reference.yml +45 -0
  58. data/spec/support/vcr_cassettes/resources/fax/resend.yml +47 -0
  59. data/spec/support/vcr_cassettes/resources/fax/test_receive.yml +51 -0
  60. data/spec/support/vcr_cassettes/resources/phax_code/create.yml +47 -0
  61. data/spec/support/vcr_cassettes/resources/phax_code/create_png.yml +52 -0
  62. data/spec/support/vcr_cassettes/resources/phax_code/get.yml +45 -0
  63. data/spec/support/vcr_cassettes/resources/phax_code/get_id.yml +46 -0
  64. data/spec/support/vcr_cassettes/resources/phax_code/get_id_png.yml +50 -0
  65. data/spec/support/vcr_cassettes/resources/phax_code/get_png.yml +50 -0
  66. data/spec/support/vcr_cassettes/resources/phone_number/create.yml +48 -0
  67. data/spec/support/vcr_cassettes/resources/phone_number/get.yml +46 -0
  68. data/spec/support/vcr_cassettes/resources/phone_number/list.yml +60 -0
  69. data/spec/support/vcr_cassettes/resources/phone_number/release.yml +45 -0
  70. data/spec/support/vcr_cassettes/resources/public/area_codes/list.yml +79 -0
  71. data/spec/support/vcr_cassettes/resources/public/country/list.yml +55 -0
  72. metadata +103 -73
  73. data/test/support/responses/account_status.json +0 -9
  74. data/test/support/responses/cancel_success.json +0 -4
  75. data/test/support/responses/fax_status_success.json +0 -21
  76. data/test/support/responses/list_faxes.json +0 -68
  77. data/test/support/responses/list_numbers.json +0 -22
  78. data/test/support/responses/provision_number.json +0 -12
  79. data/test/support/responses/release_number.json +0 -7
  80. data/test/support/responses/send_failure.json +0 -8
  81. data/test/support/responses/send_success.json +0 -8
  82. data/test/support/responses/test.pdf +0 -0
  83. data/test/support/responses/test_receive.json +0 -4
  84. data/test/test_helper.rb +0 -53
  85. data/test/test_phaxio.rb +0 -72
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Phaxio do
4
+ subject { Phaxio }
5
+
6
+ it 'sets the api key' do
7
+ subject.api_key = 'test-api-key'
8
+ expect(subject.api_key).to eq('test-api-key')
9
+ end
10
+
11
+ it 'sets the api secret' do
12
+ subject.api_secret = 'test-api-secret'
13
+ expect(subject.api_secret).to eq('test-api-secret')
14
+ end
15
+
16
+ it 'sets the callback token' do
17
+ subject.callback_token = 'test-callback-token'
18
+ expect(subject.callback_token).to eq('test-callback-token')
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Account do
4
+ describe 'getting account information' do
5
+ let(:action) { Account.get params }
6
+ let(:params) { {} }
7
+
8
+ around do |example|
9
+ VCR.use_cassette('resources/account/status') do
10
+ example.run
11
+ end
12
+ end
13
+
14
+ it 'sends the request to Phaxio' do
15
+ expect_api_request :get, 'account/status', params
16
+ action
17
+ end
18
+
19
+ it 'returns an account object' do
20
+ result = action
21
+ expect(result).to be_a(Account)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Callback do
4
+ describe 'validating a callback signature' do
5
+ let(:action) { Callback.valid_signature? signature, url, params, files }
6
+ let(:signature) { '663099785e5eff09f0cd6f2bd5d78c852f3b670d' }
7
+ let(:url) { 'example.com' }
8
+ let(:params) { {test: true} }
9
+ let(:files) { [] }
10
+
11
+ it 'raises an error if Phaxio::Config.callback_token is unset' do
12
+ Phaxio.callback_token = nil
13
+ expect {
14
+ action
15
+ }.to raise_error(Phaxio::Error::PhaxioError, 'No callback token has been set')
16
+ end
17
+
18
+ context 'signature matches' do
19
+ it 'returns true' do
20
+ result = action
21
+ expect(result).to eq(true)
22
+ end
23
+ end
24
+
25
+ context 'signature does not match' do
26
+ let(:signature) { 'wrong' }
27
+
28
+ it 'returns false' do
29
+ result = action
30
+ expect(result).to eq(false)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,248 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Fax do
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', '+15558675309') }
7
+
8
+ describe 'creating a fax' do
9
+ let(:action) { Fax.create params }
10
+ let(:params) { {to: test_recipient_number, file: test_file} }
11
+
12
+ around(:each) do |example|
13
+ VCR.use_cassette('resources/fax/create') do
14
+ example.run
15
+ end
16
+ end
17
+
18
+ it 'makes the request to Phaxio' do
19
+ expect_api_request :post, 'faxes', to: test_recipient_number, file: test_file
20
+ action
21
+ end
22
+
23
+ it 'returns a reference to the fax' do
24
+ result = action
25
+ expect(result).to be_a(Fax::Reference)
26
+ expect(result.id).to be_a(Integer)
27
+ end
28
+ end
29
+
30
+ describe 'retrieving a fax' do
31
+ let(:action) { Fax.get fax_id, params }
32
+ let!(:fax_id) {
33
+ VCR.use_cassette('resources/fax/create_for_get') do
34
+ Phaxio::Fax.create(to: test_recipient_number, file: test_file).id
35
+ end
36
+ }
37
+ let(:params) { {} }
38
+
39
+ around(:each) do |example|
40
+ VCR.use_cassette('resources/fax/get') do
41
+ example.run
42
+ end
43
+ end
44
+
45
+ it 'makes the request to Phaxio' do
46
+ expect_api_request :get, "faxes/#{fax_id}", params
47
+ action
48
+ end
49
+
50
+ it 'returns a fax' do
51
+ result = action
52
+ expect(result).to be_a(Fax)
53
+ expect(result.id).to eq(fax_id)
54
+ end
55
+ end
56
+
57
+ describe 'cancelling a fax' do
58
+ let(:action) { Fax.cancel fax_id, params }
59
+ let(:params) { {} }
60
+ let!(:fax_id) {
61
+ VCR.use_cassette('resources/fax/create_for_cancel') do
62
+ Phaxio::Fax.create(to: test_recipient_number, file: test_file).id
63
+ end
64
+ }
65
+
66
+ around(:each) do |example|
67
+ VCR.use_cassette('resources/fax/cancel') do
68
+ example.run
69
+ end
70
+ end
71
+
72
+ it 'makes the request to Phaxio' do
73
+ expect_api_request :post, "faxes/#{fax_id}/cancel", params
74
+ action
75
+ end
76
+
77
+ it 'returns a reference to the fax' do
78
+ result = action
79
+ expect(result).to be_a(Fax::Reference)
80
+ expect(result.id).to eq(fax_id)
81
+ end
82
+ end
83
+
84
+ describe 'listing faxes' do
85
+ let(:action) { Fax.list params }
86
+ let(:params) { {created_before: time} }
87
+ let(:time) { Time.new 2017, 10, 28, 0, 17, 0, 0 }
88
+
89
+ around do |example|
90
+ VCR.use_cassette('resources/fax/list') do
91
+ example.run
92
+ end
93
+ end
94
+
95
+ it 'sends the request to phaxio' do
96
+ expect_api_request :get, 'faxes', params
97
+ action
98
+ end
99
+
100
+ it 'returns a collection of faxes' do
101
+ result = action
102
+ expect(result).to be_a(Fax::Collection)
103
+ end
104
+ end
105
+
106
+ describe 'resending a fax' do
107
+ let(:action) { Fax.resend fax_id, params }
108
+ let!(:fax_id) {
109
+ VCR.use_cassette('resources/fax/create_for_resend') do
110
+ Phaxio::Fax.create(to: test_recipient_number, file: test_file).id
111
+ end
112
+ }
113
+ let(:params) { {} }
114
+
115
+ around do |example|
116
+ VCR.use_cassette('resources/fax/resend') do
117
+ example.run
118
+ end
119
+ end
120
+
121
+ it 'makes the request to Phaxio' do
122
+ expect_api_request :post, "faxes/#{fax_id}/resend", params
123
+ action
124
+ end
125
+
126
+ it 'returns a reference to a new fax' do
127
+ result = action
128
+ expect(result).to be_a(Fax::Reference)
129
+ expect(result.id).to_not eq(fax_id)
130
+ end
131
+ end
132
+
133
+ describe 'deleting a fax' do
134
+ let(:action) { Fax.delete fax_id, params }
135
+ let!(:fax_id) {
136
+ VCR.use_cassette('resources/fax/create_for_delete') do
137
+ Phaxio::Fax.create(to: test_recipient_number, file: test_file).id
138
+ end
139
+ }
140
+ let(:params) { {} }
141
+
142
+ around do |example|
143
+ VCR.use_cassette('resources/fax/delete') do
144
+ example.run
145
+ end
146
+ end
147
+
148
+ it 'makes the request to Phaxio' do
149
+ expect_api_request :delete, "faxes/#{fax_id}", params
150
+ action
151
+ end
152
+
153
+ it 'returns true' do
154
+ result = action
155
+ expect(result).to eq(true)
156
+ end
157
+ end
158
+
159
+ describe 'deleting a fax file' do
160
+ let(:action) { Fax.delete_file fax_id, params }
161
+ let!(:fax_id) {
162
+ VCR.use_cassette('resources/fax/create_for_delete_file') do
163
+ Phaxio::Fax.create(to: test_recipient_number, file: test_file).id
164
+ end
165
+ }
166
+ let(:params) { {} }
167
+
168
+ around do |example|
169
+ VCR.use_cassette('resources/fax/delete_file') do
170
+ example.run
171
+ end
172
+ end
173
+
174
+ it 'makes the request to Phaxio' do
175
+ expect_api_request :delete, "faxes/#{fax_id}/file", params
176
+ action
177
+ end
178
+
179
+ it 'returns true' do
180
+ result = action
181
+ expect(result).to eq(true)
182
+ end
183
+ end
184
+
185
+ describe 'downloading a fax file' do
186
+ let(:action) { Fax.file fax_id, params }
187
+ let!(:fax_id) {
188
+ VCR.use_cassette('resources/fax/create_for_download_file') do
189
+ Phaxio::Fax.create(to: test_recipient_number, file: test_file).id
190
+ end
191
+ }
192
+ let(:params) { {} }
193
+
194
+ around do |example|
195
+ VCR.use_cassette('resources/fax/file') do
196
+ example.run
197
+ end
198
+ end
199
+
200
+ it 'makes the request to phaxio' do
201
+ expect_api_request :get, "faxes/#{fax_id}/file", params
202
+ action
203
+ end
204
+
205
+ it 'returns a file' do
206
+ result = action
207
+ expect(result).to be_a(File)
208
+ end
209
+ end
210
+
211
+ describe 'receiving a test fax' do
212
+ let(:action) { Fax.test_receive params }
213
+ let(:params) { {file: test_file} }
214
+
215
+ around do |example|
216
+ VCR.use_cassette('resources/fax/test_receive') do
217
+ example.run
218
+ end
219
+ end
220
+
221
+ it 'makes the request to Phaxio' do
222
+ expect_api_request :post, 'faxes', {file: test_file, direction: 'received'}
223
+ action
224
+ end
225
+
226
+ it 'returns true' do
227
+ result = action
228
+ expect(result).to eq(true)
229
+ end
230
+ end
231
+
232
+ describe Fax::Reference do
233
+ let!(:fax_id) {
234
+ VCR.use_cassette('resources/fax/create_for_reference') do
235
+ Phaxio::Fax.create(to: test_recipient_number, file: test_file).id
236
+ end
237
+ }
238
+
239
+ it 'gets the full fax' do
240
+ VCR.use_cassette('resources/fax/reference') do
241
+ reference = Fax::Reference.new fax_id
242
+ result = reference.get
243
+ expect(result).to be_a(Fax)
244
+ expect(result.id).to eq(fax_id)
245
+ end
246
+ end
247
+ end
248
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PhaxCode do
4
+ describe 'creating a phax code' do
5
+ let(:action) { PhaxCode.create params }
6
+ let(:params) { {metadata: 'This is a test PhaxCode'} }
7
+
8
+ context 'default type' do
9
+ around do |example|
10
+ VCR.use_cassette('resources/phax_code/create') do
11
+ example.run
12
+ end
13
+ end
14
+
15
+ it 'makes the request to phaxio' do
16
+ expect_api_request :post, 'phax_codes', params
17
+ action
18
+ end
19
+
20
+ it 'returns a PhaxCode instance by default' do
21
+ result = action
22
+ expect(result).to be_a(PhaxCode)
23
+ end
24
+ end
25
+
26
+ context 'type is specified to be png' do
27
+ let(:params) { {metadata: 'This is a test PhaxCode', type: 'png'} }
28
+
29
+ around do |example|
30
+ VCR.use_cassette('resources/phax_code/create_png') do
31
+ example.run
32
+ end
33
+ end
34
+
35
+ it 'returns a png if type is specified to be png' do
36
+ result = action
37
+ expect(result).to be_a(File)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe 'getting a phax code' do
43
+ let(:action) { PhaxCode.get params }
44
+ let(:params) { {} }
45
+
46
+ context 'default' do
47
+ around do |example|
48
+ VCR.use_cassette('resources/phax_code/get') do
49
+ example.run
50
+ end
51
+ end
52
+
53
+ it 'makes the request to Phaxio' do
54
+ expect_api_request :get, 'phax_code', params
55
+ action
56
+ end
57
+
58
+ context 'getting the default phax code with no type specified' do
59
+ it 'returns a PhaxCode instance' do
60
+ result = action
61
+ expect(result).to be_a(PhaxCode)
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'getting the default phax code with png type specified' do
67
+ let(:params) { {type: 'png'} }
68
+
69
+ around do |example|
70
+ VCR.use_cassette('resources/phax_code/get_png') do
71
+ example.run
72
+ end
73
+ end
74
+
75
+ it 'returns a file' do
76
+ result = action
77
+ expect(result).to be_a(File)
78
+ end
79
+ end
80
+
81
+ context 'getting a particular phax code with no type specified' do
82
+ let(:params) { {identifier: '-Y3jxX'} }
83
+
84
+ around do |example|
85
+ VCR.use_cassette('resources/phax_code/get_id') do
86
+ example.run
87
+ end
88
+ end
89
+
90
+ it 'returns a PhaxCode instance' do
91
+ result = action
92
+ expect(result).to be_a(PhaxCode)
93
+ end
94
+ end
95
+
96
+ context 'getting a particular phax code with png type specified' do
97
+ let(:params) { {identifier: '-Y3jxX', type: 'png'} }
98
+
99
+ around do |example|
100
+ VCR.use_cassette('resources/phax_code/get_id_png') do
101
+ example.run
102
+ end
103
+ end
104
+
105
+ it 'returns a file' do
106
+ result = action
107
+ expect(result).to be_a(File)
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
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
11
+ end
12
+ end
13
+
14
+ it 'makes the request to Phaxio' do
15
+ expect_api_request :post, 'phone_numbers', params
16
+ action
17
+ end
18
+
19
+ it 'returns a phone number object' do
20
+ result = action
21
+ expect(result).to be_a(PhoneNumber)
22
+ end
23
+ end
24
+
25
+ describe 'getting information about a number' do
26
+ let(:action) { PhoneNumber.get phone_number, params }
27
+ let(:phone_number) { '12258675309' }
28
+ let(:params) { {} }
29
+
30
+ around do |example|
31
+ VCR.use_cassette('resources/phone_number/get') do
32
+ example.run
33
+ end
34
+ end
35
+
36
+ it 'makes the request to Phaxio' do
37
+ expect_api_request :get, "phone_numbers/#{phone_number}"
38
+ action
39
+ end
40
+
41
+ it 'returns a phone number object' do
42
+ result = action
43
+ expect(result).to be_a(PhoneNumber)
44
+ end
45
+ end
46
+
47
+ describe 'listing numbers' do
48
+ let(:action) { PhoneNumber.list params }
49
+ let(:params) { {} }
50
+
51
+ around do |example|
52
+ VCR.use_cassette('resources/phone_number/list') do
53
+ example.run
54
+ end
55
+ end
56
+
57
+ it 'makes the request to Phaxio' do
58
+ expect_api_request :get, 'phone_numbers', params
59
+ action
60
+ end
61
+
62
+ it 'returns a collection of phone number objects' do
63
+ result = action
64
+ expect(result).to be_a(Phaxio::Resource::Collection)
65
+ end
66
+ end
67
+
68
+ describe 'releasing a number' do
69
+ let(:action) { PhoneNumber.release phone_number, params }
70
+ let(:phone_number) { '+12258675309' }
71
+ let(:params) { {} }
72
+
73
+ around do |example|
74
+ VCR.use_cassette('resources/phone_number/release') do
75
+ example.run
76
+ end
77
+ end
78
+
79
+ it 'sends the request to Phaxio' do
80
+ expect_api_request :delete, "phone_numbers/#{phone_number}", params
81
+ action
82
+ end
83
+
84
+ it 'returns true' do
85
+ result = action
86
+ expect(result).to eq(true)
87
+ end
88
+ end
89
+ end