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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +2 -1
- data/Gemfile +10 -0
- data/README.md +260 -73
- data/Rakefile +6 -16
- data/lib/phaxio.rb +47 -3
- data/lib/phaxio/client.rb +117 -484
- data/lib/phaxio/config.rb +31 -0
- data/lib/phaxio/error.rb +13 -0
- data/lib/phaxio/helpers/mime_type_helper.rb +14 -0
- data/lib/phaxio/resource.rb +168 -0
- data/lib/phaxio/resources.rb +7 -0
- data/lib/phaxio/resources/account.rb +41 -0
- data/lib/phaxio/resources/callback.rb +65 -0
- data/lib/phaxio/resources/fax.rb +310 -0
- data/lib/phaxio/resources/fax_recipient.rb +41 -0
- data/lib/phaxio/resources/phax_code.rb +89 -0
- data/lib/phaxio/resources/phone_number.rb +112 -0
- data/lib/phaxio/resources/public.rb +8 -0
- data/lib/phaxio/resources/public/area_code.rb +64 -0
- data/lib/phaxio/resources/public/country.rb +54 -0
- data/lib/phaxio/version.rb +1 -1
- data/phaxio.gemspec +9 -12
- data/spec/client_spec.rb +132 -0
- data/spec/helpers/mime_type_helper_spec.rb +11 -0
- data/spec/phaxio_spec.rb +20 -0
- data/spec/resources/account_spec.rb +24 -0
- data/spec/resources/callback_spec.rb +34 -0
- data/spec/resources/fax_spec.rb +227 -0
- data/spec/resources/phax_code_spec.rb +83 -0
- data/spec/resources/phone_number_spec.rb +89 -0
- data/spec/resources/public/area_code_spec.rb +24 -0
- data/spec/resources/public/country_spec.rb +24 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/credentials.rb +7 -0
- data/spec/support/expectations.rb +9 -0
- data/spec/support/files/test.pdf +0 -0
- data/spec/support/vcr.rb +9 -0
- data/spec/support/vcr_cassettes/resources/account/status.yml +44 -0
- data/spec/support/vcr_cassettes/resources/fax/cancel.yml +46 -0
- data/spec/support/vcr_cassettes/resources/fax/create.yml +230 -0
- data/spec/support/vcr_cassettes/resources/fax/delete.yml +44 -0
- data/spec/support/vcr_cassettes/resources/fax/delete_file.yml +44 -0
- data/spec/support/vcr_cassettes/resources/fax/file.yml +251 -0
- data/spec/support/vcr_cassettes/resources/fax/get.yml +44 -0
- data/spec/support/vcr_cassettes/resources/fax/list.yml +56 -0
- data/spec/support/vcr_cassettes/resources/fax/resend.yml +46 -0
- data/spec/support/vcr_cassettes/resources/fax/test_receive.yml +231 -0
- data/spec/support/vcr_cassettes/resources/phax_code/create.yml +100 -0
- data/spec/support/vcr_cassettes/resources/phax_code/get.yml +190 -0
- data/spec/support/vcr_cassettes/resources/phone_number/create.yml +47 -0
- data/spec/support/vcr_cassettes/resources/phone_number/get.yml +45 -0
- data/spec/support/vcr_cassettes/resources/phone_number/list.yml +52 -0
- data/spec/support/vcr_cassettes/resources/phone_number/release.yml +44 -0
- data/spec/support/vcr_cassettes/resources/public/area_codes/list.yml +77 -0
- data/spec/support/vcr_cassettes/resources/public/country/list.yml +54 -0
- metadata +70 -82
- data/.ruby-version +0 -1
- data/CHANGELOG +0 -6
- data/test/files/test.pdf +0 -0
- data/test/integration/phaxio_integration_test.rb +0 -45
- data/test/support/responses/account_status.json +0 -9
- data/test/support/responses/cancel_success.json +0 -4
- data/test/support/responses/fax_status_success.json +0 -21
- data/test/support/responses/list_faxes.json +0 -68
- data/test/support/responses/list_numbers.json +0 -22
- data/test/support/responses/provision_number.json +0 -12
- data/test/support/responses/release_number.json +0 -7
- data/test/support/responses/send_failure.json +0 -8
- data/test/support/responses/send_success.json +0 -8
- data/test/support/responses/test.pdf +0 -0
- data/test/support/responses/test_receive.json +0 -4
- data/test/test_helper.rb +0 -57
- data/test/test_phaxio.rb +0 -128
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a10449404bdb1df029a52a878f49202589e727d
|
4
|
+
data.tar.gz: f500188f94760b8300dc2f63b17eb4ad31edc5fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df06285d6e87fbc048f0ebcad0cd5ee608ccfb0b45c6813926f272c4302aa5dc60421445df11bacc6fae2e26a32951912ca201376a56c77bcd2e5fa71e0e5976
|
7
|
+
data.tar.gz: 9d5bcfa978e6e92317d17d4bb0a31e4cd2f33f57d96f8241721bc581be34c768623704d951d4a177f5634dc0eb6a7f2cff4c8db7588e6e286a61ba2aa5020dd3
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,104 +1,291 @@
|
|
1
|
-
# Phaxio
|
1
|
+
# 📠 Phaxio
|
2
2
|
|
3
3
|
[](https://travis-ci.org/phaxio/phaxio-ruby)
|
4
4
|
|
5
|
-
A Ruby gem for interacting with the [Phaxio API](
|
6
|
-
|
7
|
-
**Note: This gem only runs on Ruby version 1.9.+**
|
5
|
+
A Ruby gem for interacting with the [Phaxio API](https://www.phaxio.com/docs/api/v2).
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
11
|
-
Add
|
9
|
+
Add to your application's Gemfile:
|
12
10
|
|
13
|
-
|
11
|
+
``` ruby
|
12
|
+
gem 'phaxio', '~> 2.0.0'
|
13
|
+
```
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
|
-
|
17
|
+
``` sh
|
18
|
+
$ bundle install
|
19
|
+
```
|
18
20
|
|
19
21
|
Or install it yourself as:
|
20
22
|
|
21
|
-
|
23
|
+
``` sh
|
24
|
+
$ gem install phaxio
|
25
|
+
```
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
|
29
|
+
Set up your API Key, API Secret, and, optionally, Callback Token.
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
``` ruby
|
32
|
+
require 'phaxio'
|
33
|
+
|
34
|
+
Phaxio.api_key = '11111'
|
35
|
+
Phaxio.api_secret = '22222'
|
36
|
+
Phaxio.callback_token = '33333'
|
37
|
+
```
|
38
|
+
|
39
|
+
Try sending a fax:
|
40
|
+
|
41
|
+
``` ruby
|
42
|
+
fax_file = File.open 'test.pdf', 'rb'
|
43
|
+
Phaxio::Fax.create to: '+15558675309', file: fax_file
|
44
|
+
```
|
31
45
|
|
32
|
-
|
46
|
+
You can include `Phaxio::Resources` to pull in the resource classes for convenience:
|
47
|
+
|
48
|
+
``` ruby
|
49
|
+
include Phaxio::Resources
|
50
|
+
|
51
|
+
fax_file = File.open 'test.pdf', 'rb'
|
52
|
+
Fax.create to: '+15558675309', file: fax_file
|
53
|
+
```
|
33
54
|
|
34
|
-
Phaxio.send_fax(to: "0123456789", filename: File.new("test.pdf"))
|
35
55
|
|
36
56
|
### Currently Supported API Calls
|
37
57
|
|
38
|
-
|
39
|
-
* resend_fax - `Phaxio.resend_fax(id: 1234)`
|
40
|
-
* test_receive - `Phaxio.test_receive(filename: "test_file.pdf")`
|
41
|
-
* provision_number - `Phaxio.provision_number(area_code: 802)`
|
42
|
-
* release_number - `Phaxio.release_number(number: "8021112222")`
|
43
|
-
* list_numbers - `Phaxio.list_numbers(area_code: 802)`
|
44
|
-
* get_fax_file - `Phaxio.get_fax_file(id: 123456, type: p)`
|
45
|
-
* list_faxes - `Phaxio.list_numbers(area_code: 802)`
|
46
|
-
* list_faxes - `Phaxio.list_faxes(start: Time.now - 48000, end: Time.now)`
|
47
|
-
* get_fax_status - `Phaxio.get_fax_status(id: 123456)`
|
48
|
-
* cancel_fax - `Phaxio.cancel_fax(id: 123456)`
|
49
|
-
* delete_fax - `Phaxio.delete_fax(id: 1234, files_only: true)`
|
50
|
-
* get_account_status - `Phaxio.get_account_status`
|
51
|
-
* attach_phaxcode_to_pdf - `Phaxio.attach_phaxcode_to_pdf(x: 10, y:10, File.new("input.pdf"))`
|
52
|
-
* create_phaxcode - `Phaxio.create_phaxcode(metadata: "some metadata")`
|
53
|
-
* supported_countries
|
54
|
-
* area_codes
|
55
|
-
|
56
|
-
### Example
|
57
|
-
|
58
|
-
require 'phaxio'
|
59
|
-
|
60
|
-
Phaxio.config do |config|
|
61
|
-
config.api_key = "your_key"
|
62
|
-
config.api_secret = "your_secret"
|
63
|
-
end
|
58
|
+
#### Faxes
|
64
59
|
|
65
|
-
|
66
|
-
Phaxio.get_fax_status(id: @fax["faxId"])
|
60
|
+
##### `Fax.create`
|
67
61
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
62
|
+
Create and send a fax.
|
63
|
+
|
64
|
+
``` ruby
|
65
|
+
fax_file = File.open 'test.pdf', 'rb'
|
66
|
+
ref = Fax.create to: '+15558675309', file: fax_file
|
67
|
+
# => Fax::Reference(id: 1234)
|
68
|
+
fax = ref.get
|
69
|
+
# => Fax(id: 1234, num_pages: 1, ...)
|
70
|
+
```
|
71
|
+
|
72
|
+
##### `Fax.list`
|
73
|
+
|
74
|
+
List faxes in date range.
|
75
|
+
|
76
|
+
``` ruby
|
77
|
+
start = 2.weeks.ago
|
78
|
+
stop = 1.week.ago
|
79
|
+
faxes = Fax.list created_after: start, created_before: stop
|
80
|
+
# => Phaxio::Resource::Collection([Fax(id: 1234, ...), ...])
|
81
|
+
faxes.length
|
82
|
+
# => 5
|
83
|
+
faxes.map(&:cost).inject(&:+)
|
84
|
+
# => 35
|
85
|
+
```
|
86
|
+
|
87
|
+
##### `Fax.get`
|
88
|
+
|
89
|
+
Get information about a specific fax.
|
90
|
+
|
91
|
+
``` ruby
|
92
|
+
fax = Fax.get 1234
|
93
|
+
# => Fax(id: 1234, ...)
|
94
|
+
```
|
95
|
+
|
96
|
+
##### `Fax.cancel`
|
97
|
+
|
98
|
+
Cancel a fax.
|
99
|
+
|
100
|
+
``` ruby
|
101
|
+
Fax.cancel 1234
|
102
|
+
# => Fax::Reference(id: 1234)
|
103
|
+
```
|
104
|
+
|
105
|
+
##### `Fax.resend`
|
106
|
+
|
107
|
+
Resend a fax.
|
108
|
+
|
109
|
+
``` ruby
|
110
|
+
Fax.resend 1234
|
111
|
+
# => Fax::Reference(id: 5678)
|
112
|
+
```
|
113
|
+
|
114
|
+
##### `Fax.delete`
|
115
|
+
|
116
|
+
Delete a fax. Only test faxes are allowed to be deleted.
|
117
|
+
|
118
|
+
``` ruby
|
119
|
+
Fax.delete 1234
|
120
|
+
# => true
|
121
|
+
```
|
122
|
+
|
123
|
+
##### `Fax.delete_file`
|
124
|
+
|
125
|
+
Delete fax file.
|
126
|
+
|
127
|
+
``` ruby
|
128
|
+
Fax.delete_file 1234
|
129
|
+
# => true
|
130
|
+
```
|
131
|
+
|
132
|
+
##### `Fax.file`
|
133
|
+
|
134
|
+
``` ruby
|
135
|
+
Fax.file 1234
|
136
|
+
# => File
|
137
|
+
```
|
138
|
+
|
139
|
+
##### `Fax.test_receive`
|
140
|
+
|
141
|
+
Test receiving a fax.
|
142
|
+
|
143
|
+
``` ruby
|
144
|
+
fax_file = File.open 'test.pdf', 'rb'
|
145
|
+
Fax.test_receive file: fax_file
|
146
|
+
# => true
|
147
|
+
```
|
148
|
+
|
149
|
+
#### Countries
|
150
|
+
|
151
|
+
##### `Public::Country.list`
|
152
|
+
|
153
|
+
Get a list of supported countries.
|
154
|
+
|
155
|
+
``` ruby
|
156
|
+
Public::Country.list
|
157
|
+
# => Phaxio::Resource::Collection([Public::Country(alpha2: 'US', ...), ...])
|
158
|
+
```
|
159
|
+
|
160
|
+
#### Phone Numbers
|
161
|
+
|
162
|
+
##### `PhoneNumber.create`
|
163
|
+
|
164
|
+
Provision a new phone number.
|
165
|
+
|
166
|
+
``` ruby
|
167
|
+
PhoneNumber.create country_code: 1, area_code: 555
|
168
|
+
# => PhoneNumber(phone_number: '+15558675309', ...)
|
169
|
+
```
|
170
|
+
|
171
|
+
##### `PhoneNumber.list`
|
172
|
+
|
173
|
+
List phone numbers that you own on Phaxio.
|
174
|
+
|
175
|
+
``` ruby
|
176
|
+
PhoneNumber.list
|
177
|
+
# => Phaxio::Resource::Collection([PhoneNumber(phone_number: '+15558675309', ...), ...])
|
178
|
+
```
|
179
|
+
|
180
|
+
##### `PhoneNumber.get`
|
181
|
+
|
182
|
+
Get information about a specific phone number.
|
183
|
+
|
184
|
+
``` ruby
|
185
|
+
PhoneNumber.get '+15558675309'
|
186
|
+
# => PhoneNumber(phone_number: '+15558675309', ...)
|
187
|
+
```
|
188
|
+
|
189
|
+
##### `PhoneNumber.delete`
|
190
|
+
|
191
|
+
Release a phone number.
|
192
|
+
|
193
|
+
``` ruby
|
194
|
+
PhoneNumber.delete '+15558675309'
|
195
|
+
# => true
|
196
|
+
```
|
197
|
+
|
198
|
+
#### Area Codes
|
199
|
+
|
200
|
+
##### `Public::AreaCode.list`
|
201
|
+
|
202
|
+
Lists available area codes for purchasing Phaxio numbers.
|
203
|
+
|
204
|
+
``` ruby
|
205
|
+
area_codes = Public::AreaCode.list toll_free: true
|
206
|
+
# => Phaxio::Resource::Collection([Public::AreaCode(city: 'Toll Free Service', ...), ...], page: 1)
|
207
|
+
```
|
208
|
+
|
209
|
+
#### PhaxCodes
|
210
|
+
|
211
|
+
##### `PhaxCode.create`
|
212
|
+
|
213
|
+
Creates a PhaxCode. Returns data about the PhaxCode by default, or a .png file if `type: 'png'` is
|
214
|
+
passed.
|
215
|
+
|
216
|
+
``` ruby
|
217
|
+
PhaxCode.create metadata: 'test_phax_code'
|
218
|
+
# => PhaxCode(identifier: 'phax-code-identifier')
|
219
|
+
PhaxCode.create type: 'png'
|
220
|
+
# => File
|
221
|
+
```
|
222
|
+
|
223
|
+
##### `PhaxCode.get`
|
224
|
+
|
225
|
+
Gets a PhaxCode. Returns data about the PhaxCode by default, or a .png file if `type: 'png'` is
|
226
|
+
passed.
|
227
|
+
|
228
|
+
``` ruby
|
229
|
+
PhaxCode.get 'phax-code-identifier'
|
230
|
+
# => PhaxCode(identifier: 'phax-code-identifier', metadata: 'phax-code-metadata')
|
231
|
+
PhaxCode.get 'phax-code-identifier', type: 'png'
|
232
|
+
# => File
|
233
|
+
```
|
234
|
+
|
235
|
+
#### Account
|
236
|
+
|
237
|
+
##### `Account.get`
|
238
|
+
|
239
|
+
Get information about your Phaxio account.
|
240
|
+
|
241
|
+
``` ruby
|
242
|
+
Account.get
|
243
|
+
# => Account(balance: 1000, faxes_today: 0, faxes_this_month: 100)
|
244
|
+
```
|
245
|
+
|
246
|
+
#### Callback
|
247
|
+
|
248
|
+
##### `Callback.valid_signature?`
|
249
|
+
|
250
|
+
Validate the callback signature sent with a Phaxio callback. Requires that Phaxio.callback_token be
|
251
|
+
set.
|
252
|
+
|
253
|
+
``` ruby
|
254
|
+
Callback.valid_signature? received_signature, callback_url, received_params, received_files
|
255
|
+
# => true
|
256
|
+
```
|
73
257
|
|
74
258
|
## Callback Validation Example with Sinatra
|
75
259
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
260
|
+
``` ruby
|
261
|
+
require 'sinatra/base'
|
262
|
+
require 'phaxio'
|
263
|
+
|
264
|
+
class PhaxioCallbackExample < Sinatra::Base
|
265
|
+
Phaxio.config do |config|
|
266
|
+
config.api_key = '0123456789'
|
267
|
+
config.api_secret = '0123456789'
|
268
|
+
config.callback_token = '0123456789'
|
269
|
+
end
|
270
|
+
|
271
|
+
post '/phaxio_callback' do
|
272
|
+
signature = request.env['HTTP_X_PHAXIO_SIGNATURE']
|
273
|
+
url = request.url
|
274
|
+
file_params = params[:filename]
|
275
|
+
if Phaxio::Callback.valid_signature? signature, url, callback_params, file_params
|
276
|
+
'Success'
|
277
|
+
else
|
278
|
+
'Invalid callback signature'
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def callback_params
|
283
|
+
params.select do |key, _value|
|
284
|
+
%w(success is_test direction fax metadata message).include?(key)
|
101
285
|
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
```
|
102
289
|
|
103
290
|
## Contributing
|
104
291
|
|
data/Rakefile
CHANGED
@@ -1,21 +1,11 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'rake'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
t.libs << 'test'
|
8
|
-
t.test_files = FileList['test/test*.rb']
|
9
|
-
t.verbose = true
|
5
|
+
RSpec::Core::RakeTask.new do |t|
|
6
|
+
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
7
|
+
t.rspec_opts = '--format documentation'
|
10
8
|
end
|
11
9
|
|
12
10
|
desc 'Run tests'
|
13
|
-
task :default => :
|
14
|
-
|
15
|
-
desc 'Run integration tests'
|
16
|
-
task :integration_tests do
|
17
|
-
integration_tests_path = File.expand_path(
|
18
|
-
'../test/integration/*_integration_test.rb', __FILE__
|
19
|
-
)
|
20
|
-
FileList[integration_tests_path].each { |file| require file }
|
21
|
-
end
|
11
|
+
task :default => :spec
|
data/lib/phaxio.rb
CHANGED
@@ -1,4 +1,48 @@
|
|
1
|
-
require
|
1
|
+
require 'json'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'openssl'
|
4
|
+
require 'time'
|
5
|
+
require 'faraday'
|
6
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
7
|
+
require 'mime/types/full'
|
8
|
+
require 'phaxio/version'
|
9
|
+
require 'phaxio/config'
|
10
|
+
require 'phaxio/client'
|
11
|
+
require 'phaxio/error'
|
12
|
+
require 'phaxio/resource'
|
13
|
+
require 'phaxio/resources'
|
2
14
|
|
3
|
-
|
4
|
-
require
|
15
|
+
Dir[File.expand_path(File.join('..', 'phaxio', 'helpers', '*.rb'), __FILE__)].each do |file|
|
16
|
+
require file
|
17
|
+
end
|
18
|
+
|
19
|
+
%w[fax_recipient fax account callback phax_code phone_number public].each do |filename|
|
20
|
+
require File.expand_path(File.join('..', 'phaxio', 'resources', filename), __FILE__)
|
21
|
+
end
|
22
|
+
|
23
|
+
module Phaxio
|
24
|
+
include Resources
|
25
|
+
|
26
|
+
class << self
|
27
|
+
# @!attribute api_key
|
28
|
+
# @see Config.api_key
|
29
|
+
# @!attribute api_secret
|
30
|
+
# @see Config.api_secret
|
31
|
+
# @!attribute callback_token
|
32
|
+
# @see Config.callback_token
|
33
|
+
# @!attribute api_endpoint
|
34
|
+
# @see Config.api_endpoint
|
35
|
+
%w(api_key api_secret callback_token api_endpoint).each do |config_attribute|
|
36
|
+
# Define getters
|
37
|
+
define_method(config_attribute) do
|
38
|
+
Config.public_send config_attribute
|
39
|
+
end
|
40
|
+
|
41
|
+
# Define setters
|
42
|
+
setter = "#{config_attribute}="
|
43
|
+
define_method(setter) do |value|
|
44
|
+
Config.public_send setter, value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|