phaxio 0.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,68 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"success":true,
|
3
|
-
"message":"Retrieved faxes successfully",
|
4
|
-
"paging":{
|
5
|
-
"max_per_page":1000,
|
6
|
-
"page":1,
|
7
|
-
"total_pages":1,
|
8
|
-
"total_results":3
|
9
|
-
},
|
10
|
-
"data":[
|
11
|
-
{
|
12
|
-
"id":123456,
|
13
|
-
"num_pages":3,
|
14
|
-
"cost":21,
|
15
|
-
"direction":"sent",
|
16
|
-
"status":"success",
|
17
|
-
"is_test":true,
|
18
|
-
"requested_at":1293910680,
|
19
|
-
"completed_at":1293911100,
|
20
|
-
"recipients":[
|
21
|
-
{
|
22
|
-
"number":"4141234567",
|
23
|
-
"status":"success",
|
24
|
-
"completed_at":1293911100
|
25
|
-
}
|
26
|
-
]
|
27
|
-
},
|
28
|
-
{
|
29
|
-
"id":123457,
|
30
|
-
"num_pages":1,
|
31
|
-
"cost":7,
|
32
|
-
"direction":"sent",
|
33
|
-
"status":"success",
|
34
|
-
"is_test":false,
|
35
|
-
"requested_at":1293984720,
|
36
|
-
"completed_at":1293985800,
|
37
|
-
"recipients":[
|
38
|
-
{
|
39
|
-
"number":"4145554567",
|
40
|
-
"status":"success",
|
41
|
-
"completed_at":1293985800
|
42
|
-
}
|
43
|
-
]
|
44
|
-
},
|
45
|
-
{
|
46
|
-
"id":123458,
|
47
|
-
"num_pages":1,
|
48
|
-
"cost":14,
|
49
|
-
"direction":"sent",
|
50
|
-
"status":"success",
|
51
|
-
"is_test":false,
|
52
|
-
"requested_at":1294094700,
|
53
|
-
"completed_at":1294095000,
|
54
|
-
"recipients":[
|
55
|
-
{
|
56
|
-
"number":"4145554568",
|
57
|
-
"status":"success",
|
58
|
-
"completed_at":1294095000
|
59
|
-
},
|
60
|
-
{
|
61
|
-
"number":"4145554567",
|
62
|
-
"status":"success",
|
63
|
-
"completed_at":1293985800
|
64
|
-
}
|
65
|
-
]
|
66
|
-
}
|
67
|
-
]
|
68
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"success":true,
|
3
|
-
"message":"Retrieved user phone numbers successfully",
|
4
|
-
"data":[
|
5
|
-
{
|
6
|
-
"number":"8021112222",
|
7
|
-
"city":"Burlington",
|
8
|
-
"state":"Vermont",
|
9
|
-
"cost":200,
|
10
|
-
"last_billed_at":"2012-10-11 10:51:33",
|
11
|
-
"provisioned_at":"2012-10-11 10:51:33"
|
12
|
-
},
|
13
|
-
{
|
14
|
-
"number":"8023334444",
|
15
|
-
"city":"Montpelier",
|
16
|
-
"state":"Vermont",
|
17
|
-
"cost":200,
|
18
|
-
"last_billed_at":"2012-10-11 10:51:33",
|
19
|
-
"provisioned_at":"2012-10-11 10:51:33"
|
20
|
-
}
|
21
|
-
]
|
22
|
-
}
|
Binary file
|
data/test/test_helper.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
$LOAD_PATH << '.'
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require 'mocha/mini_test'
|
6
|
-
require 'fakeweb'
|
7
|
-
require 'lib/phaxio'
|
8
|
-
|
9
|
-
Phaxio.config do |config|
|
10
|
-
config.api_key = '12345678910'
|
11
|
-
config.api_secret = '10987654321'
|
12
|
-
config.callback_token = '1234567890'
|
13
|
-
end
|
14
|
-
|
15
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/send",
|
16
|
-
:body => File.open("test/support/responses/send_success.json").read,
|
17
|
-
:content_type => "application/json")
|
18
|
-
|
19
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/testReceive",
|
20
|
-
:body => File.open("test/support/responses/test_receive.json").read,
|
21
|
-
:content_type => "application/json")
|
22
|
-
|
23
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/testReceive",
|
24
|
-
:body => File.open("test/support/responses/test_receive.json").read,
|
25
|
-
:content_type => "application/json")
|
26
|
-
|
27
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/provisionNumber",
|
28
|
-
:body => File.open("test/support/responses/provision_number.json").read,
|
29
|
-
:content_type => "application/json")
|
30
|
-
|
31
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/releaseNumber",
|
32
|
-
:body => File.open("test/support/responses/release_number.json").read,
|
33
|
-
:content_type => "application/json")
|
34
|
-
|
35
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/numberList",
|
36
|
-
:body => File.open("test/support/responses/list_numbers.json").read,
|
37
|
-
:content_type => "application/json")
|
38
|
-
|
39
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxFile",
|
40
|
-
:body => File.open("test/support/responses/test.pdf").read,
|
41
|
-
:content_type => "application/pdf")
|
42
|
-
|
43
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxList",
|
44
|
-
:body => File.open("test/support/responses/list_faxes.json").read,
|
45
|
-
:content_type => "application/json")
|
46
|
-
|
47
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxStatus",
|
48
|
-
:body => File.open("test/support/responses/fax_status_success.json").read,
|
49
|
-
:content_type => "application/json")
|
50
|
-
|
51
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxCancel",
|
52
|
-
:body => File.open("test/support/responses/cancel_success.json").read,
|
53
|
-
:content_type => "application/json")
|
54
|
-
|
55
|
-
FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/accountStatus",
|
56
|
-
:body => File.open("test/support/responses/account_status.json").read,
|
57
|
-
:content_type => "application/json")
|
data/test/test_phaxio.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
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
|
-
|
9
|
-
def test_config
|
10
|
-
assert_equal "12345678910", Phaxio.api_key
|
11
|
-
assert_equal "10987654321", Phaxio.api_secret
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_initialize
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_send_fax
|
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)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_test_receive
|
31
|
-
@response = Phaxio.test_receive(filename: "test_file.pdf")
|
32
|
-
assert_equal true, @response["success"]
|
33
|
-
assert_equal "Test fax received from 234567890. Calling back now...", @response["message"]
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_provision_number
|
37
|
-
@response = Phaxio.provision_number(area_code: 802)
|
38
|
-
assert_equal true, @response["success"]
|
39
|
-
assert_equal "Number provisioned successfully!", @response["message"]
|
40
|
-
assert_equal "Vermont", @response["data"]["state"]
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_release_number
|
44
|
-
@response = Phaxio.release_number(number: "8021112222")
|
45
|
-
assert_equal true, @response["success"]
|
46
|
-
assert_equal "Number released successfully!", @response["message"]
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_list_numbers
|
50
|
-
@response = Phaxio.list_numbers(area_code: 802)
|
51
|
-
assert_equal true, @response["success"]
|
52
|
-
assert_equal "Retrieved user phone numbers successfully", @response["message"]
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_get_fax_file
|
56
|
-
@response_pdf = Phaxio.get_fax_file(id: 1234, type: p)
|
57
|
-
assert_equal 6725, @response_pdf.size
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_list_faxes
|
61
|
-
@response = Phaxio.list_faxes(start: 1293861600, end: 1294034400)
|
62
|
-
assert_equal true, @response["success"]
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_get_fax_status
|
66
|
-
@response = Phaxio.get_fax_status(id: 123456)
|
67
|
-
assert_equal true, @response["success"]
|
68
|
-
assert_equal "Retrieved fax successfully", @response["message"]
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_cancel_fax
|
72
|
-
@response = Phaxio.cancel_fax(id: 123456)
|
73
|
-
assert_equal true, @response["success"]
|
74
|
-
assert_equal "Fax canceled successfully.", @response["message"]
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_delete_fax
|
78
|
-
Phaxio.expects(:send_post).with('/deleteFax', id: 1234)
|
79
|
-
Phaxio.delete_fax(id: 1234)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_get_account_status
|
83
|
-
@response = Phaxio.get_account_status
|
84
|
-
assert_equal true, @response["success"]
|
85
|
-
assert_equal "Account status retrieved successfully", @response["message"]
|
86
|
-
assert_equal 120, @response["data"]["faxes_sent_this_month"]
|
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
|
128
|
-
end
|