phaxio 0.5.0 → 2.0.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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +2 -1
  4. data/Gemfile +10 -0
  5. data/README.md +260 -73
  6. data/Rakefile +6 -16
  7. data/lib/phaxio.rb +47 -3
  8. data/lib/phaxio/client.rb +117 -484
  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/callback.rb +65 -0
  16. data/lib/phaxio/resources/fax.rb +310 -0
  17. data/lib/phaxio/resources/fax_recipient.rb +41 -0
  18. data/lib/phaxio/resources/phax_code.rb +89 -0
  19. data/lib/phaxio/resources/phone_number.rb +112 -0
  20. data/lib/phaxio/resources/public.rb +8 -0
  21. data/lib/phaxio/resources/public/area_code.rb +64 -0
  22. data/lib/phaxio/resources/public/country.rb +54 -0
  23. data/lib/phaxio/version.rb +1 -1
  24. data/phaxio.gemspec +9 -12
  25. data/spec/client_spec.rb +132 -0
  26. data/spec/helpers/mime_type_helper_spec.rb +11 -0
  27. data/spec/phaxio_spec.rb +20 -0
  28. data/spec/resources/account_spec.rb +24 -0
  29. data/spec/resources/callback_spec.rb +34 -0
  30. data/spec/resources/fax_spec.rb +227 -0
  31. data/spec/resources/phax_code_spec.rb +83 -0
  32. data/spec/resources/phone_number_spec.rb +89 -0
  33. data/spec/resources/public/area_code_spec.rb +24 -0
  34. data/spec/resources/public/country_spec.rb +24 -0
  35. data/spec/spec_helper.rb +6 -0
  36. data/spec/support/credentials.rb +7 -0
  37. data/spec/support/expectations.rb +9 -0
  38. data/spec/support/files/test.pdf +0 -0
  39. data/spec/support/vcr.rb +9 -0
  40. data/spec/support/vcr_cassettes/resources/account/status.yml +44 -0
  41. data/spec/support/vcr_cassettes/resources/fax/cancel.yml +46 -0
  42. data/spec/support/vcr_cassettes/resources/fax/create.yml +230 -0
  43. data/spec/support/vcr_cassettes/resources/fax/delete.yml +44 -0
  44. data/spec/support/vcr_cassettes/resources/fax/delete_file.yml +44 -0
  45. data/spec/support/vcr_cassettes/resources/fax/file.yml +251 -0
  46. data/spec/support/vcr_cassettes/resources/fax/get.yml +44 -0
  47. data/spec/support/vcr_cassettes/resources/fax/list.yml +56 -0
  48. data/spec/support/vcr_cassettes/resources/fax/resend.yml +46 -0
  49. data/spec/support/vcr_cassettes/resources/fax/test_receive.yml +231 -0
  50. data/spec/support/vcr_cassettes/resources/phax_code/create.yml +100 -0
  51. data/spec/support/vcr_cassettes/resources/phax_code/get.yml +190 -0
  52. data/spec/support/vcr_cassettes/resources/phone_number/create.yml +47 -0
  53. data/spec/support/vcr_cassettes/resources/phone_number/get.yml +45 -0
  54. data/spec/support/vcr_cassettes/resources/phone_number/list.yml +52 -0
  55. data/spec/support/vcr_cassettes/resources/phone_number/release.yml +44 -0
  56. data/spec/support/vcr_cassettes/resources/public/area_codes/list.yml +77 -0
  57. data/spec/support/vcr_cassettes/resources/public/country/list.yml +54 -0
  58. metadata +70 -82
  59. data/.ruby-version +0 -1
  60. data/CHANGELOG +0 -6
  61. data/test/files/test.pdf +0 -0
  62. data/test/integration/phaxio_integration_test.rb +0 -45
  63. data/test/support/responses/account_status.json +0 -9
  64. data/test/support/responses/cancel_success.json +0 -4
  65. data/test/support/responses/fax_status_success.json +0 -21
  66. data/test/support/responses/list_faxes.json +0 -68
  67. data/test/support/responses/list_numbers.json +0 -22
  68. data/test/support/responses/provision_number.json +0 -12
  69. data/test/support/responses/release_number.json +0 -7
  70. data/test/support/responses/send_failure.json +0 -8
  71. data/test/support/responses/send_success.json +0 -8
  72. data/test/support/responses/test.pdf +0 -0
  73. data/test/support/responses/test_receive.json +0 -4
  74. data/test/test_helper.rb +0 -57
  75. data/test/test_phaxio.rb +0 -128
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phaxio::MimeTypeHelper do
4
+ it 'gets the mimetype for a filename' do
5
+ expect(subject.mimetype_for_file('test.pdf')).to eq('application/pdf')
6
+ end
7
+
8
+ it 'gets the extension for a mimetype' do
9
+ expect(subject.extension_for_mimetype('application/pdf')).to eq('pdf')
10
+ end
11
+ end
@@ -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,227 @@
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' }
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) { 1234 }
33
+ let(:params) { {} }
34
+
35
+ around(:each) do |example|
36
+ VCR.use_cassette('resources/fax/get') do
37
+ example.run
38
+ end
39
+ end
40
+
41
+ it 'makes the request to Phaxio' do
42
+ expect_api_request :get, "faxes/#{fax_id}", params
43
+ action
44
+ end
45
+
46
+ it 'returns a fax' do
47
+ result = action
48
+ expect(result).to be_a(Fax)
49
+ expect(result.id).to eq(fax_id)
50
+ end
51
+ end
52
+
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 }
57
+ let(:params) { {} }
58
+
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
+ it 'makes the request to Phaxio' do
72
+ expect_api_request :post, "faxes/#{@fax_id}/cancel", params
73
+ action
74
+ end
75
+
76
+ it 'returns a reference to the fax' do
77
+ result = action
78
+ expect(result).to be_a(Fax::Reference)
79
+ expect(result.id).to eq(@fax_id)
80
+ end
81
+ end
82
+
83
+ describe 'listing faxes' do
84
+ let(:action) { Fax.list params }
85
+ let(:params) { {created_before: time} }
86
+ let(:time) { Time.new 2017, 10, 28, 0, 17, 0, 0 }
87
+
88
+ around do |example|
89
+ VCR.use_cassette('resources/fax/list') do
90
+ example.run
91
+ end
92
+ end
93
+
94
+ it 'sends the request to phaxio' do
95
+ expect_api_request :get, 'faxes', params
96
+ action
97
+ end
98
+
99
+ it 'returns a collection of faxes' do
100
+ result = action
101
+ expect(result).to be_a(Fax::Collection)
102
+ end
103
+ end
104
+
105
+ describe 'resending a fax' do
106
+ let(:action) { Fax.resend fax_id, params }
107
+ let(:fax_id) { 1234 }
108
+ let(:params) { {} }
109
+
110
+ around do |example|
111
+ VCR.use_cassette('resources/fax/resend') do
112
+ example.run
113
+ end
114
+ end
115
+
116
+ it 'makes the request to Phaxio' do
117
+ expect_api_request :post, "faxes/#{fax_id}/resend", params
118
+ action
119
+ end
120
+
121
+ it 'returns a reference to a new fax' do
122
+ result = action
123
+ expect(result).to be_a(Fax::Reference)
124
+ expect(result.id).to_not eq(fax_id)
125
+ end
126
+ end
127
+
128
+ describe 'deleting a fax' do
129
+ let(:action) { Fax.delete fax_id, params }
130
+ let(:fax_id) { 1234 }
131
+ let(:params) { {} }
132
+
133
+ around do |example|
134
+ VCR.use_cassette('resources/fax/delete') do
135
+ example.run
136
+ end
137
+ end
138
+
139
+ it 'makes the request to Phaxio' do
140
+ expect_api_request :delete, "faxes/#{fax_id}", params
141
+ action
142
+ end
143
+
144
+ it 'returns true' do
145
+ result = action
146
+ expect(result).to eq(true)
147
+ end
148
+ end
149
+
150
+ describe 'deleting a fax file' do
151
+ let(:action) { Fax.delete_file fax_id, params }
152
+ let(:fax_id) { 1234 }
153
+ let(:params) { {} }
154
+
155
+ around do |example|
156
+ VCR.use_cassette('resources/fax/delete_file') do
157
+ example.run
158
+ end
159
+ end
160
+
161
+ it 'makes the request to Phaxio' do
162
+ expect_api_request :delete, "faxes/#{fax_id}/file", params
163
+ action
164
+ end
165
+
166
+ it 'returns true' do
167
+ result = action
168
+ expect(result).to eq(true)
169
+ end
170
+ end
171
+
172
+ describe 'downloading a fax file' do
173
+ let(:action) { Fax.file fax_id, params }
174
+ let(:fax_id) { 1234 }
175
+ let(:params) { {} }
176
+
177
+ around do |example|
178
+ VCR.use_cassette('resources/fax/file') do
179
+ example.run
180
+ end
181
+ end
182
+
183
+ it 'makes the request to phaxio' do
184
+ expect_api_request :get, "faxes/#{fax_id}/file", params
185
+ action
186
+ end
187
+
188
+ it 'returns a file' do
189
+ result = action
190
+ expect(result).to be_a(File)
191
+ end
192
+ end
193
+
194
+ describe 'receiving a test fax' do
195
+ let(:action) { Fax.test_receive params }
196
+ let(:params) { {file: test_file} }
197
+
198
+ around do |example|
199
+ VCR.use_cassette('resources/fax/test_receive') do
200
+ example.run
201
+ end
202
+ end
203
+
204
+ it 'makes the request to Phaxio' do
205
+ expect_api_request :post, 'faxes', {file: test_file, direction: 'received'}
206
+ action
207
+ end
208
+
209
+ it 'returns true' do
210
+ result = action
211
+ expect(result).to eq(true)
212
+ end
213
+ end
214
+
215
+ describe Fax::Reference do
216
+ let(:fax_id) { 1234 }
217
+
218
+ 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
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,83 @@
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
+ around do |example|
9
+ VCR.use_cassette('resources/phax_code/create') do
10
+ example.run
11
+ 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
+
19
+ it 'returns a PhaxCode instance by default' do
20
+ result = action
21
+ expect(result).to be_a(PhaxCode)
22
+ end
23
+
24
+ context 'type is specified to be png' do
25
+ let(:params) { {metadata: 'This is a test PhaxCode', type: 'png'} }
26
+
27
+ it 'returns a png if type is specified to be png' do
28
+ result = action
29
+ expect(result).to be_a(File)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'getting a phax code' do
35
+ let(:action) { PhaxCode.get params }
36
+ let(:params) { {} }
37
+
38
+ around do |example|
39
+ VCR.use_cassette('resources/phax_code/get') do
40
+ example.run
41
+ 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
+
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)
53
+ end
54
+ end
55
+
56
+ context 'getting the default phax code with png type specified' do
57
+ let(:params) { {type: 'png'} }
58
+
59
+ it 'returns a file' do
60
+ result = action
61
+ expect(result).to be_a(File)
62
+ end
63
+ end
64
+
65
+ context 'getting a particular phax code with no type specified' do
66
+ let(:params) { {identifier: '-Y3jxX'} }
67
+
68
+ it 'returns a PhaxCode instance' do
69
+ result = action
70
+ expect(result).to be_a(PhaxCode)
71
+ end
72
+ end
73
+
74
+ context 'getting a particular phax code with png type specified' do
75
+ let(:params) { {identifier: '-Y3jxX', type: 'png'} }
76
+
77
+ it 'returns a file' do
78
+ result = action
79
+ expect(result).to be_a(File)
80
+ end
81
+ end
82
+ end
83
+ 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