phaxio 0.4.1 → 0.5.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 -0
- data/CHANGELOG +6 -0
- data/README.md +38 -4
- data/Rakefile +9 -1
- data/lib/phaxio/client.rb +258 -15
- data/lib/phaxio/version.rb +1 -1
- data/phaxio.gemspec +6 -5
- data/test/files/test.pdf +0 -0
- data/test/integration/phaxio_integration_test.rb +45 -0
- data/test/test_helper.rb +8 -5
- data/test/test_phaxio.rb +60 -4
- metadata +24 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0ba3d3a1d93ed66b41b2f43e4830301b1cf636f
|
4
|
+
data.tar.gz: 61dec61548a074dbaedd1e450fe8aa23bc729740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c04abdcfb62078eace54eb05a7560cd183aa4b70717f0c267833b5808f39130a89f6c448713b6f9036b038894909b8ae9cc97234208f713a2bcb665723f5b2f9
|
7
|
+
data.tar.gz: 48ea7099e4556e635f0a66dcfd61d5f205594835230a7797effd4e823b7762d24affe7fed8dd3fb2c759fd85f9a015353b63532aaf17f2adaa1b6df1476e9643
|
data/.gitignore
CHANGED
data/CHANGELOG
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Phaxio
|
2
2
|
|
3
|
-
[](https://travis-ci.org/phaxio/phaxio-ruby)
|
4
4
|
|
5
5
|
A Ruby gem for interacting with the [Phaxio API]( https://www.phaxio.com/docs ).
|
6
6
|
|
@@ -36,17 +36,22 @@ To send a fax:
|
|
36
36
|
### Currently Supported API Calls
|
37
37
|
|
38
38
|
* send_fax - `Phaxio.send_fax(to: "0123456789", filename: File.new("test.pdf"))`
|
39
|
+
* resend_fax - `Phaxio.resend_fax(id: 1234)`
|
39
40
|
* test_receive - `Phaxio.test_receive(filename: "test_file.pdf")`
|
40
41
|
* provision_number - `Phaxio.provision_number(area_code: 802)`
|
41
42
|
* release_number - `Phaxio.release_number(number: "8021112222")`
|
42
43
|
* list_numbers - `Phaxio.list_numbers(area_code: 802)`
|
43
|
-
* get_fax_file - `Phaxio.get_fax_file(id: 123456, type: p)`
|
44
|
+
* get_fax_file - `Phaxio.get_fax_file(id: 123456, type: p)`
|
44
45
|
* list_faxes - `Phaxio.list_numbers(area_code: 802)`
|
45
|
-
* list_faxes - `Phaxio.list_faxes(start: Time.now - 48000,
|
46
|
-
end: Time.now)`
|
46
|
+
* list_faxes - `Phaxio.list_faxes(start: Time.now - 48000, end: Time.now)`
|
47
47
|
* get_fax_status - `Phaxio.get_fax_status(id: 123456)`
|
48
48
|
* cancel_fax - `Phaxio.cancel_fax(id: 123456)`
|
49
|
+
* delete_fax - `Phaxio.delete_fax(id: 1234, files_only: true)`
|
49
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
|
50
55
|
|
51
56
|
### Example
|
52
57
|
|
@@ -66,6 +71,35 @@ end: Time.now)`
|
|
66
71
|
file << @pdf
|
67
72
|
end
|
68
73
|
|
74
|
+
## Callback Validation Example with Sinatra
|
75
|
+
|
76
|
+
require 'sinatra/base'
|
77
|
+
require 'phaxio'
|
78
|
+
|
79
|
+
class PhaxioCallbackExample < Sinatra::Base
|
80
|
+
Phaxio.config do |config|
|
81
|
+
config.api_key = '0123456789'
|
82
|
+
config.api_secret = '0123456789'
|
83
|
+
config.callback_token = '0123456789'
|
84
|
+
end
|
85
|
+
|
86
|
+
post '/phaxio_callback' do
|
87
|
+
if Phaxio.valid_callback_signature?(
|
88
|
+
request.env['HTTP_X_PHAXIO_SIGNATURE'],
|
89
|
+
request.url, callback_params, params[:filename])
|
90
|
+
'Success'
|
91
|
+
else
|
92
|
+
'Invalid callback signature'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def callback_params
|
97
|
+
params.select do |key, _value|
|
98
|
+
%w(success is_test direction fax metadata).include?(key)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
69
103
|
## Contributing
|
70
104
|
|
71
105
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -9,5 +9,13 @@ Rake::TestTask.new do |t|
|
|
9
9
|
t.verbose = true
|
10
10
|
end
|
11
11
|
|
12
|
-
desc
|
12
|
+
desc 'Run tests'
|
13
13
|
task :default => :test
|
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
|
data/lib/phaxio/client.rb
CHANGED
@@ -3,10 +3,12 @@ module Phaxio
|
|
3
3
|
base_uri 'https://api.phaxio.com/v1'
|
4
4
|
|
5
5
|
module Config
|
6
|
-
attr_accessor :api_key, :api_secret
|
6
|
+
attr_accessor :api_key, :api_secret, :callback_token
|
7
7
|
end
|
8
8
|
|
9
9
|
module Client
|
10
|
+
DIGEST = OpenSSL::Digest.new('sha1')
|
11
|
+
|
10
12
|
# Public: Send a fax.
|
11
13
|
#
|
12
14
|
# options - The Hash options used to refine the selection (default: {}):
|
@@ -16,14 +18,8 @@ module Phaxio
|
|
16
18
|
# square brackets after parameter
|
17
19
|
# name to send to multiple
|
18
20
|
# recipients (e.g. to[]) (required).
|
19
|
-
# :filename -
|
20
|
-
#
|
21
|
-
# if you specify string_data. Must
|
22
|
-
# have file name in the filename
|
23
|
-
# field of the body-part header. Put
|
24
|
-
# square brackets after parameter
|
25
|
-
# name to send multiple files (e.g.
|
26
|
-
# filename[]) (required).
|
21
|
+
# :filename - A Ruby File of a document to fax
|
22
|
+
# (supported file types: https://www.phaxio.com/faq#faq10)
|
27
23
|
# :string_data - A String of html, plain text, or a
|
28
24
|
# URL. If additional files are
|
29
25
|
# specified as well, this data will
|
@@ -60,7 +56,7 @@ module Phaxio
|
|
60
56
|
#
|
61
57
|
# Examples
|
62
58
|
#
|
63
|
-
# Phaxio.send_fax(to: "0123456789", filename: "
|
59
|
+
# Phaxio.send_fax(to: "0123456789", filename: File.new("docToSend.pdf"))
|
64
60
|
#
|
65
61
|
# Returns a HTTParty::Response object containing a success bool,
|
66
62
|
# a String message, and an in faxID.
|
@@ -68,6 +64,21 @@ module Phaxio
|
|
68
64
|
send_post("/send", options)
|
69
65
|
end
|
70
66
|
|
67
|
+
# Public: Resend a fax.
|
68
|
+
#
|
69
|
+
# options - The Hash options used to refine the selection (default: {}):
|
70
|
+
# :id - The int id of the fax you want to resend (required).
|
71
|
+
#
|
72
|
+
# Examples
|
73
|
+
#
|
74
|
+
# Phaxio.resend_fax(id: "123456")
|
75
|
+
#
|
76
|
+
# Returns a HTTParty::Response object containing a success bool,
|
77
|
+
# a message string, and data containing the fax ID int.
|
78
|
+
def resend_fax(options)
|
79
|
+
send_post("/resendFax", options)
|
80
|
+
end
|
81
|
+
|
71
82
|
# Public: Test receiving a fax.
|
72
83
|
#
|
73
84
|
# options - The Hash options used to refine the selection (default: {}):
|
@@ -131,7 +142,7 @@ module Phaxio
|
|
131
142
|
# Phaxio.
|
132
143
|
#
|
133
144
|
# options - The Hash options used to refne th selection (default: {}):
|
134
|
-
# area_code - An integer area code you'd like to filter by
|
145
|
+
# area_code - An integer area code you'd like to filter by
|
135
146
|
# (optional).
|
136
147
|
# number - A String phone number you'd like to retrieve
|
137
148
|
# (optional).
|
@@ -223,6 +234,24 @@ module Phaxio
|
|
223
234
|
send_post("/faxCancel", options)
|
224
235
|
end
|
225
236
|
|
237
|
+
# Public: Delete a specific fax.
|
238
|
+
#
|
239
|
+
# options - The hash options used to refine the selection (defaults: {}):
|
240
|
+
# :id - The int ID of the fax you want to cancel
|
241
|
+
# (required).
|
242
|
+
# :files_only - The bool used to determine whether only the files
|
243
|
+
# are deleted. If not specified, default is false
|
244
|
+
# (optional).
|
245
|
+
#
|
246
|
+
# Examples
|
247
|
+
#
|
248
|
+
# Phaxio.delete_fax(id: 1234, files_only: true)
|
249
|
+
#
|
250
|
+
# Returns a HTTParty::Response object with success bool and message string.
|
251
|
+
def delete_fax(options)
|
252
|
+
send_post("/deleteFax", options)
|
253
|
+
end
|
254
|
+
|
226
255
|
# Public: Get the status of Client's account.
|
227
256
|
#
|
228
257
|
# Examples
|
@@ -235,18 +264,232 @@ module Phaxio
|
|
235
264
|
send_post("/accountStatus", {})
|
236
265
|
end
|
237
266
|
|
267
|
+
# Public: Attach a PhaxCode to a PDF you provide.
|
268
|
+
#
|
269
|
+
# options - Type: hash. Options used to refine the action (default: {}):
|
270
|
+
# x - Type: float. The x-coordinate (in PDF points*)
|
271
|
+
# where the PhaxCode should be drawn. x=0 is at the
|
272
|
+
# left-most point on the page. (required)
|
273
|
+
# y - Type: float. The y-coordinate (in PDF points*)
|
274
|
+
# where the PhaxCode should be drawn. Y=0 is the
|
275
|
+
# bottom-most point on the page. (required)
|
276
|
+
# filename - A Ruby File in PDF format (required)
|
277
|
+
# metadata - Type: string. Custom metadata to be associated
|
278
|
+
# with the created barcode. If not present, the
|
279
|
+
# basic PhaxCode for your account will be used.
|
280
|
+
# page_number - Type: integer. The page where the PhaxCode should
|
281
|
+
# be drawn. 1-based.
|
282
|
+
# *PDF points definition: A "point" is 1/72 of an inch. An
|
283
|
+
# 8.5"x11" document is therefore 612 pt x 792 pt.
|
284
|
+
#
|
285
|
+
# Examples
|
286
|
+
#
|
287
|
+
# Phaxio.attach_phaxcode_to_pdf(
|
288
|
+
# x: "0", y: "100", filename: File.new("input.pdf")
|
289
|
+
# )
|
290
|
+
#
|
291
|
+
# Response: A PDF file containing a PhaxCode at the location specified.
|
292
|
+
def attach_phaxcode_to_pdf(options)
|
293
|
+
if options[:filename].nil?
|
294
|
+
raise StandardError, 'You must include a PDF file.'
|
295
|
+
end
|
296
|
+
|
297
|
+
if options[:x] < 0 || options[:y] < 0
|
298
|
+
raise StandardError, 'Coordinates must be greater than or equal to 0.'
|
299
|
+
end
|
300
|
+
|
301
|
+
send_post('/attachPhaxCodeToPdf', options)
|
302
|
+
end
|
303
|
+
|
304
|
+
# Public: Create a custom PhaxCode.
|
305
|
+
#
|
306
|
+
# options - Type: hash. Options used to refine the action (default: {}):
|
307
|
+
# metadata - Type: string. Custom metadata to be associated with
|
308
|
+
# this barcode. If not present, the basic PhaxCode for
|
309
|
+
# your account will be used. (optional)
|
310
|
+
# redirect - Type: boolean. If present and true, the PhaxCode
|
311
|
+
# barcode image will be dumped in the response.
|
312
|
+
# (optional)
|
313
|
+
#
|
314
|
+
# Example:
|
315
|
+
# Phaxio.create_phaxcode(metadata: "sale_id=44")
|
316
|
+
#
|
317
|
+
# Response: If the redirect parameter is not provided, a JSON object with
|
318
|
+
# success, message, and data attributes is returned. The data
|
319
|
+
# attribute contains a url where the PhaxCode barcode image can be
|
320
|
+
# accessed. Otherwise, the image data is dumped in the response.
|
321
|
+
def create_phaxcode(options = {})
|
322
|
+
send_post('/createPhaxCode', options)
|
323
|
+
end
|
324
|
+
|
325
|
+
# Public: Get a Hosted Document with PhaxCode included
|
326
|
+
#
|
327
|
+
# Note: You will have to set up the hosted document with Phaxio (along with
|
328
|
+
# the relevant PhaxCode) before calling this method.
|
329
|
+
#
|
330
|
+
# options - Type: hash. Options used to refine the action (default: {}):
|
331
|
+
# name - Type: string. The name of a hosted document.
|
332
|
+
# (required)
|
333
|
+
# metadata - Type: string. Custom metadata to be associated with
|
334
|
+
# the PhaxCode that will be attached to the hosted
|
335
|
+
# document. If not present, the basic PhaxCode for your
|
336
|
+
# account will be used.
|
337
|
+
# (optional)
|
338
|
+
#
|
339
|
+
# Example:
|
340
|
+
# Phaxio.get_hosted_document(name:"business_fax")
|
341
|
+
#
|
342
|
+
# Response: A PDF copy of the hosted document with a PhaxCode included at
|
343
|
+
# the pre-specified location.
|
344
|
+
def get_hosted_document(options)
|
345
|
+
if options[:name].nil?
|
346
|
+
raise StandardError, 'You must include the name of the hosted document.'
|
347
|
+
end
|
348
|
+
|
349
|
+
send_post('/getHostedDocument', options)
|
350
|
+
end
|
351
|
+
|
352
|
+
# Public: Get a list of supported countries for sending faxes
|
353
|
+
#
|
354
|
+
# Note: This method doesn't require API keys and is included for the sake of
|
355
|
+
# completion.
|
356
|
+
#
|
357
|
+
# Example:
|
358
|
+
# Phaxio.supported_countries
|
359
|
+
#
|
360
|
+
# Response: A JSON object with success, message, and data attributes. The
|
361
|
+
# data attribute contains a hash, where the key contains the name
|
362
|
+
# of the country, and the value is a hash of attributes for the
|
363
|
+
# country (currently only pricing information).
|
364
|
+
#
|
365
|
+
# Example Response:
|
366
|
+
# {
|
367
|
+
# "success": true,
|
368
|
+
# "message": "Data contains supported countries.",
|
369
|
+
# "data": {
|
370
|
+
# "United States": {
|
371
|
+
# "price_per_page": 7
|
372
|
+
# },
|
373
|
+
# "Canada": {
|
374
|
+
# "price_per_page": 7
|
375
|
+
# },
|
376
|
+
# "United Kingdom": {
|
377
|
+
# "price_per_page": 10
|
378
|
+
# },
|
379
|
+
# ...
|
380
|
+
# }
|
381
|
+
# }
|
382
|
+
def supported_countries
|
383
|
+
post('/supportedCountries')
|
384
|
+
end
|
385
|
+
|
386
|
+
# Public: List area codes available for purchasing numbers
|
387
|
+
#
|
388
|
+
# Note: This method doesn't require API keys and is included for the sake of
|
389
|
+
# completion.
|
390
|
+
#
|
391
|
+
# options - Type: hash. Options used to refine the query (default: {}):
|
392
|
+
# is_toll_free - Type: boolean. Will only return toll free area
|
393
|
+
# codes. (optional)
|
394
|
+
# state - Type: string. A two character state or province
|
395
|
+
# abbreviation (e.g. IL or YT). Will only return
|
396
|
+
# area codes for this state. (optional)
|
397
|
+
#
|
398
|
+
# Response: A JSON object with success, message, and data attributes. The
|
399
|
+
# data attribute contains a map of area codes to city and state.
|
400
|
+
#
|
401
|
+
# Example response:
|
402
|
+
# {
|
403
|
+
# "success": true,
|
404
|
+
# "message": "295 area codes available.",
|
405
|
+
# "data": {
|
406
|
+
# "201": {
|
407
|
+
# "city": "Bayonne, Jersey City, Union City",
|
408
|
+
# "state": "New Jersey"
|
409
|
+
# },
|
410
|
+
# "202": {
|
411
|
+
# "city": "Washington",
|
412
|
+
# "state": "District Of Columbia"
|
413
|
+
# },
|
414
|
+
# ... a lot more area codes here...
|
415
|
+
# }
|
416
|
+
# }
|
417
|
+
def area_codes(options = {})
|
418
|
+
post('/areaCodes', options)
|
419
|
+
end
|
420
|
+
|
238
421
|
def send_post(path, options)
|
239
|
-
post(
|
422
|
+
post(
|
423
|
+
path, query: options.merge!(api_key: api_key, api_secret: api_secret)
|
424
|
+
)
|
425
|
+
end
|
426
|
+
|
427
|
+
# Public: Check the signature of the signed request.
|
428
|
+
#
|
429
|
+
# signature - Type: string. The X-Phaxio-Signature HTTP header value.
|
430
|
+
# url - Type: string. The full URL that was called by Phaxio,
|
431
|
+
# including the query. (required)
|
432
|
+
# params - Type: hash. The POSTed form data (required)
|
433
|
+
# files - Type: array. Submitted files (required - "received" fax
|
434
|
+
# callback only)
|
435
|
+
#
|
436
|
+
# Returns true if the signature matches the signed request, otherwise false
|
437
|
+
def valid_callback_signature?(signature, url, params, files = [])
|
438
|
+
check_signature = generate_check_signature(url, params, files)
|
439
|
+
check_signature == signature
|
440
|
+
end
|
441
|
+
|
442
|
+
# Public: Generate a signature using the request data and callback token
|
443
|
+
#
|
444
|
+
# url - Type: string. The full URL that was called by Phaxio,
|
445
|
+
# including the query. (required)
|
446
|
+
# params - Type: hash. The POSTed form data (required)
|
447
|
+
# files - Type: array. Submitted files (required - "received" fax
|
448
|
+
# callback only)
|
449
|
+
#
|
450
|
+
# Retuns a signature based on the request data and configured callback
|
451
|
+
# token, which can then be compared with the request signature.
|
452
|
+
def generate_check_signature(url, params, files = [])
|
453
|
+
params_string = generate_params_string(params)
|
454
|
+
file_string = generate_files_string(files)
|
455
|
+
callback_data = "#{url}#{params_string}#{file_string}"
|
456
|
+
OpenSSL::HMAC.hexdigest(DIGEST, callback_token, callback_data)
|
457
|
+
end
|
458
|
+
|
459
|
+
private
|
460
|
+
|
461
|
+
def generate_params_string(params)
|
462
|
+
sorted_params = params.sort_by { |key, _value| key }
|
463
|
+
params_strings = sorted_params.map { |key, value| "#{key}#{value}" }
|
464
|
+
params_strings.join
|
465
|
+
end
|
466
|
+
|
467
|
+
def generate_files_string(files)
|
468
|
+
files_array = files_to_array(files).reject(&:nil?)
|
469
|
+
sorted_files = files_array.sort_by { |file| file[:name] }
|
470
|
+
files_strings = sorted_files.map { |file| generate_file_string(file) }
|
471
|
+
files_strings.join
|
472
|
+
end
|
473
|
+
|
474
|
+
def files_to_array(files)
|
475
|
+
files.is_a?(Array) ? files : [files]
|
476
|
+
end
|
477
|
+
|
478
|
+
def generate_file_string(file)
|
479
|
+
file[:name] + DIGEST.hexdigest(file[:tempfile].read)
|
240
480
|
end
|
241
481
|
end
|
242
482
|
|
243
|
-
# Public: Configure Phaxio with your api_key and
|
483
|
+
# Public: Configure Phaxio with your api_key, api_secret, and the callback
|
484
|
+
# token provided in your Phaxio account (to verify that requests are
|
485
|
+
# coming from Phaxio).
|
244
486
|
#
|
245
487
|
# Examples
|
246
488
|
#
|
247
489
|
# Phaxio.config do |config|
|
248
|
-
# config.api_key =
|
249
|
-
# config.api_secret =
|
490
|
+
# config.api_key = '12345678910'
|
491
|
+
# config.api_secret = '10987654321'
|
492
|
+
# config.callback_token = '32935829'
|
250
493
|
# end
|
251
494
|
#
|
252
495
|
# Returns nothing.
|
data/lib/phaxio/version.rb
CHANGED
data/phaxio.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
require File.expand_path('../lib/phaxio/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["
|
6
|
-
gem.email = ["
|
7
|
-
gem.description = %q{
|
8
|
-
gem.summary = %q{
|
9
|
-
gem.homepage = "http://
|
5
|
+
gem.authors = ["Josh Nankin"]
|
6
|
+
gem.email = ["support@phaxio.com"]
|
7
|
+
gem.description = %q{Ruby wrapper for the Phaxio API}
|
8
|
+
gem.summary = %q{Ruby wrapper for the Phaxio API}
|
9
|
+
gem.homepage = "http://github.com/phaxio/phaxio-ruby"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_development_dependency 'fakeweb', '~> 1.3'
|
22
22
|
gem.add_development_dependency 'rake', '~> 10'
|
23
23
|
gem.add_development_dependency 'minitest', '~> 5'
|
24
|
+
gem.add_development_dependency 'mocha', '~> 1.1'
|
24
25
|
end
|
data/test/files/test.pdf
ADDED
Binary file
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class PhaxioIntegrationTest < MiniTest::Test
|
5
|
+
def setup
|
6
|
+
FakeWeb.clean_registry
|
7
|
+
configure
|
8
|
+
|
9
|
+
@fax_number = '2025550168'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_resend_fax
|
13
|
+
send_fax(test_fail: 'faxError')
|
14
|
+
response = Phaxio.resend_fax(id: @send_fax_response['faxId'])
|
15
|
+
assert response['success']
|
16
|
+
assert_equal 'Fax queued for resend', response['message']
|
17
|
+
assert response['data']['faxId'].integer?
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_delete_fax
|
21
|
+
send_fax
|
22
|
+
response = Phaxio.delete_fax(id: @send_fax_response['faxId'])
|
23
|
+
assert response['success']
|
24
|
+
assert_equal 'Deleted fax successfully!', response['message']
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def configure
|
30
|
+
Phaxio.config do |config|
|
31
|
+
config.api_key = ENV.fetch 'PHAXIO_TEST_API_KEY'
|
32
|
+
config.api_secret = ENV.fetch 'PHAXIO_TEST_API_SECRET'
|
33
|
+
end
|
34
|
+
rescue KeyError
|
35
|
+
raise(KeyError, 'You must set PHAXIO_TEST_API_KEY and ' \
|
36
|
+
'PHAXIO_TEST_API_SECRET to run integration tests')
|
37
|
+
end
|
38
|
+
|
39
|
+
# Convenience method for actions requiring an existing fax
|
40
|
+
def send_fax(options = {})
|
41
|
+
params = options.merge(to: @fax_number, string_data: 'test')
|
42
|
+
@send_fax_response = Phaxio.send_fax(params)
|
43
|
+
sleep(5)
|
44
|
+
end
|
45
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH << '.'
|
2
|
+
|
2
3
|
require 'minitest/autorun'
|
3
4
|
|
4
|
-
require
|
5
|
-
require
|
5
|
+
require 'mocha/mini_test'
|
6
|
+
require 'fakeweb'
|
7
|
+
require 'lib/phaxio'
|
6
8
|
|
7
9
|
Phaxio.config do |config|
|
8
|
-
config.api_key =
|
9
|
-
config.api_secret =
|
10
|
+
config.api_key = '12345678910'
|
11
|
+
config.api_secret = '10987654321'
|
12
|
+
config.callback_token = '1234567890'
|
10
13
|
end
|
11
14
|
|
12
15
|
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/send",
|
data/test/test_phaxio.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class TestPhaxio < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
@callback_data = ['example.com', { test: true }]
|
6
|
+
@testPDF = File.new(File.dirname(__FILE__) + "/files/test.pdf")
|
7
|
+
end
|
8
|
+
|
4
9
|
def test_config
|
5
10
|
assert_equal "12345678910", Phaxio.api_key
|
6
11
|
assert_equal "10987654321", Phaxio.api_secret
|
@@ -10,10 +15,16 @@ class TestPhaxio < MiniTest::Test
|
|
10
15
|
end
|
11
16
|
|
12
17
|
def test_send_fax
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
Phaxio.expects(:send_post).with(
|
19
|
+
'/send',
|
20
|
+
to: "+18005551234", filename: @testPDF
|
21
|
+
)
|
22
|
+
Phaxio.send_fax(to: "+18005551234", filename: @testPDF)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_resend_fax
|
26
|
+
Phaxio.expects(:send_post).with('/resendFax', id: 1234)
|
27
|
+
Phaxio.resend_fax(id: 1234)
|
17
28
|
end
|
18
29
|
|
19
30
|
def test_test_receive
|
@@ -63,10 +74,55 @@ class TestPhaxio < MiniTest::Test
|
|
63
74
|
assert_equal "Fax canceled successfully.", @response["message"]
|
64
75
|
end
|
65
76
|
|
77
|
+
def test_delete_fax
|
78
|
+
Phaxio.expects(:send_post).with('/deleteFax', id: 1234)
|
79
|
+
Phaxio.delete_fax(id: 1234)
|
80
|
+
end
|
81
|
+
|
66
82
|
def test_get_account_status
|
67
83
|
@response = Phaxio.get_account_status
|
68
84
|
assert_equal true, @response["success"]
|
69
85
|
assert_equal "Account status retrieved successfully", @response["message"]
|
70
86
|
assert_equal 120, @response["data"]["faxes_sent_this_month"]
|
71
87
|
end
|
88
|
+
|
89
|
+
def test_generate_check_signature
|
90
|
+
signature = Phaxio.generate_check_signature(*@callback_data)
|
91
|
+
assert_equal '15adeecb7eca79676ece07ee4bc1bbba2c69eddd', signature
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_valid_callback_signature?
|
95
|
+
assert_equal true, Phaxio.valid_callback_signature?(
|
96
|
+
'15adeecb7eca79676ece07ee4bc1bbba2c69eddd', *@callback_data)
|
97
|
+
assert_equal false, Phaxio.valid_callback_signature?(
|
98
|
+
'wrong', *@callback_data)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_attach_phax_code_to_pdf
|
102
|
+
Phaxio.expects(:send_post).with(
|
103
|
+
'/attachPhaxCodeToPdf',
|
104
|
+
x: 0, y: 100, filename: @testPDF
|
105
|
+
)
|
106
|
+
Phaxio.attach_phaxcode_to_pdf(x: 0, y: 100, filename: @testPDF)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_create_phaxcode
|
110
|
+
Phaxio.expects(:send_post).with('/createPhaxCode', {})
|
111
|
+
Phaxio.create_phaxcode
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_get_hosted_document
|
115
|
+
Phaxio.expects(:send_post).with('/getHostedDocument', name: 'test_fax')
|
116
|
+
Phaxio.get_hosted_document(name: 'test_fax')
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_supported_countries
|
120
|
+
Phaxio.expects(:post).with('/supportedCountries')
|
121
|
+
Phaxio.supported_countries
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_area_codes
|
125
|
+
Phaxio.expects(:post).with('/areaCodes', is_toll_free: true, state: 'IL')
|
126
|
+
Phaxio.area_codes(is_toll_free: true, state: 'IL')
|
127
|
+
end
|
72
128
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phaxio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- Brett Chalupa
|
7
|
+
- Josh Nankin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: httmultiparty
|
@@ -81,12 +80,23 @@ dependencies:
|
|
81
80
|
- - "~>"
|
82
81
|
- !ruby/object:Gem::Version
|
83
82
|
version: '5'
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.1'
|
97
|
+
description: Ruby wrapper for the Phaxio API
|
87
98
|
email:
|
88
|
-
-
|
89
|
-
- brettchalupa@gmail.com
|
99
|
+
- support@phaxio.com
|
90
100
|
executables: []
|
91
101
|
extensions: []
|
92
102
|
extra_rdoc_files: []
|
@@ -94,6 +104,7 @@ files:
|
|
94
104
|
- ".gitignore"
|
95
105
|
- ".ruby-version"
|
96
106
|
- ".travis.yml"
|
107
|
+
- CHANGELOG
|
97
108
|
- Gemfile
|
98
109
|
- LICENSE
|
99
110
|
- README.md
|
@@ -102,6 +113,8 @@ files:
|
|
102
113
|
- lib/phaxio/client.rb
|
103
114
|
- lib/phaxio/version.rb
|
104
115
|
- phaxio.gemspec
|
116
|
+
- test/files/test.pdf
|
117
|
+
- test/integration/phaxio_integration_test.rb
|
105
118
|
- test/support/responses/account_status.json
|
106
119
|
- test/support/responses/cancel_success.json
|
107
120
|
- test/support/responses/fax_status_success.json
|
@@ -115,7 +128,7 @@ files:
|
|
115
128
|
- test/support/responses/test_receive.json
|
116
129
|
- test/test_helper.rb
|
117
130
|
- test/test_phaxio.rb
|
118
|
-
homepage: http://
|
131
|
+
homepage: http://github.com/phaxio/phaxio-ruby
|
119
132
|
licenses: []
|
120
133
|
metadata: {}
|
121
134
|
post_install_message:
|
@@ -137,5 +150,5 @@ rubyforge_project:
|
|
137
150
|
rubygems_version: 2.4.6
|
138
151
|
signing_key:
|
139
152
|
specification_version: 4
|
140
|
-
summary:
|
153
|
+
summary: Ruby wrapper for the Phaxio API
|
141
154
|
test_files: []
|