phaxio 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -11
- data/lib/phaxio/client.rb +48 -30
- data/lib/phaxio/version.rb +1 -1
- data/phaxio.gemspec +1 -1
- data/test/test_phaxio.rb +10 -11
- metadata +1 -1
data/README.md
CHANGED
@@ -20,24 +20,24 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Configure
|
23
|
+
Configure Phaxio with your api_key and api_secret:
|
24
24
|
|
25
|
-
|
26
|
-
config.api_key = 10987654321
|
27
|
-
config.api_secret = 12345678910
|
25
|
+
Phaxio.config do |config|
|
26
|
+
config.api_key = "10987654321"
|
27
|
+
config.api_secret = "12345678910"
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
To send a fax:
|
31
31
|
|
32
|
-
|
32
|
+
Phaxio.send_fax(to: "0123456789", filename: "test.pdf")
|
33
33
|
|
34
34
|
### Currently Supported API Calls
|
35
35
|
|
36
|
-
* send_fax
|
37
|
-
* test_receive
|
38
|
-
* get_fax_status
|
39
|
-
* cancel_fax
|
40
|
-
* get_account_status
|
36
|
+
* send_fax - `Phaxio.send_fax(to: "0123456789", filename: "test.pdf")`
|
37
|
+
* test_receive - `Phaxio.test_receive(filename: "test_file.pdf")`
|
38
|
+
* get_fax_status - `Phaxio.get_fax_status(id: "123456")`
|
39
|
+
* cancel_fax - `Phaxio.cancel_fax(id: "123456")`
|
40
|
+
* get_account_status - `Phaxio.get_account_status`
|
41
41
|
|
42
42
|
## Contributing
|
43
43
|
|
data/lib/phaxio/client.rb
CHANGED
@@ -1,30 +1,12 @@
|
|
1
1
|
module Phaxio
|
2
|
+
include HTTParty
|
3
|
+
base_uri 'https://api.phaxio.com/v1'
|
4
|
+
|
2
5
|
module Config
|
3
6
|
attr_accessor :api_key, :api_secret
|
4
7
|
end
|
5
8
|
|
6
|
-
|
7
|
-
include HTTParty
|
8
|
-
base_uri 'https://api.phaxio.com/v1'
|
9
|
-
|
10
|
-
# Public: Initialize a new Client.
|
11
|
-
#
|
12
|
-
# Returns nothing.
|
13
|
-
def initialize
|
14
|
-
extend(Config)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Public: Configure a Client.
|
18
|
-
#
|
19
|
-
# Returns the Client.
|
20
|
-
def config
|
21
|
-
if block_given?
|
22
|
-
yield(self)
|
23
|
-
end
|
24
|
-
|
25
|
-
self
|
26
|
-
end
|
27
|
-
|
9
|
+
module Client
|
28
10
|
# Public: Send a fax.
|
29
11
|
#
|
30
12
|
# options - The Hash options used to refine the selection (default: {}):
|
@@ -76,11 +58,15 @@ module Phaxio
|
|
76
58
|
# completed. Must be between 1 and 60
|
77
59
|
# (optional).
|
78
60
|
#
|
61
|
+
# Examples
|
62
|
+
#
|
63
|
+
# Phaxio.send_fax(to: "0123456789", filename: "test.pdf")
|
64
|
+
#
|
79
65
|
# Returns a HTTParty::Response object containing a success bool,
|
80
66
|
# a String message, and an in faxID.
|
81
67
|
def send_fax(options)
|
82
68
|
options.merge!({api_key: api_key, api_secret: api_secret})
|
83
|
-
|
69
|
+
send_post("/send", options)
|
84
70
|
end
|
85
71
|
|
86
72
|
# Public: Test receiving a fax.
|
@@ -93,11 +79,15 @@ module Phaxio
|
|
93
79
|
# a PhaxCode and is the file you want to simulate
|
94
80
|
# sending (required).
|
95
81
|
#
|
82
|
+
# Examples
|
83
|
+
#
|
84
|
+
# Phaxio.test_receive(filename: "test_file.pdf")
|
85
|
+
#
|
96
86
|
# Returns a HTTParty::Response object containing a success bool
|
97
87
|
# and a String message.
|
98
88
|
def test_receive(options)
|
99
89
|
options.merge!({api_key: api_key, api_secret: api_secret})
|
100
|
-
|
90
|
+
send_post("/testReceive", options)
|
101
91
|
end
|
102
92
|
|
103
93
|
# Public: Get the status of a specific fax.
|
@@ -106,15 +96,19 @@ module Phaxio
|
|
106
96
|
# id - The int id of the fax you want to get the status of
|
107
97
|
# (required).
|
108
98
|
#
|
99
|
+
# Examples
|
100
|
+
#
|
101
|
+
# Phaxio.get_fax_status(id: "123456")
|
102
|
+
#
|
109
103
|
# Returns a HTTParty::Response object containing a success bool,
|
110
104
|
# a String message, and the data of the fax.
|
111
105
|
def get_fax_status(options)
|
112
106
|
if options[:id].nil?
|
113
107
|
raise StandardError, "You must include a fax id."
|
114
108
|
end
|
115
|
-
|
109
|
+
|
116
110
|
options.merge!({api_key: api_key, api_secret: api_secret})
|
117
|
-
|
111
|
+
send_post("/faxStatus", options)
|
118
112
|
end
|
119
113
|
|
120
114
|
# Public: Cancel a specific fax.
|
@@ -122,24 +116,48 @@ module Phaxio
|
|
122
116
|
# options - The Hash options used to refine the selection (defaults: {}):
|
123
117
|
# id - The int id of the fax you want to cancel (required).
|
124
118
|
#
|
119
|
+
# Examples
|
120
|
+
#
|
121
|
+
# Phaxio.cancel_fax(id: "123456")
|
122
|
+
#
|
125
123
|
# Returns a HTTParty::Response object containing a success bool
|
126
124
|
# and a String message.
|
127
125
|
def cancel_fax(options)
|
128
126
|
options.merge!({api_key: api_key, api_secret: api_secret})
|
129
|
-
|
127
|
+
send_post("/faxCancel", options)
|
130
128
|
end
|
131
129
|
|
132
130
|
# Public: Get the status of Client's account.
|
133
131
|
#
|
132
|
+
# Examples
|
133
|
+
#
|
134
|
+
# Phaxio.get_account_status
|
135
|
+
#
|
134
136
|
# Returns a HTTParty::Response object with success, message, and data
|
135
137
|
# (containing faxes_sent_this_month, faxes_sent_today, and balance).
|
136
138
|
def get_account_status
|
137
|
-
|
139
|
+
send_post("/accountStatus", {})
|
140
|
+
end
|
141
|
+
|
142
|
+
def send_post(path, options)
|
143
|
+
post(path, options.merge!({api_key: api_key, api_secret: api_secret}))
|
138
144
|
end
|
139
145
|
end
|
140
146
|
|
141
|
-
|
142
|
-
|
147
|
+
# Public: Configure Phaxio with your api_key and api_secret
|
148
|
+
#
|
149
|
+
# Examples
|
150
|
+
#
|
151
|
+
# Phaxio.config do |config|
|
152
|
+
# config.api_key = "12345678910"
|
153
|
+
# config.api_secret = "10987654321"
|
154
|
+
# end
|
155
|
+
#
|
156
|
+
# Returns nothing.
|
157
|
+
def self.config
|
158
|
+
yield(self)
|
143
159
|
end
|
144
160
|
|
161
|
+
extend Client
|
162
|
+
extend Config
|
145
163
|
end
|
data/lib/phaxio/version.rb
CHANGED
data/phaxio.gemspec
CHANGED
data/test/test_phaxio.rb
CHANGED
@@ -2,48 +2,47 @@ require_relative "test_helper"
|
|
2
2
|
|
3
3
|
class TestPhaxio < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
6
|
-
config.api_key =
|
7
|
-
config.api_secret =
|
5
|
+
Phaxio.config do |config|
|
6
|
+
config.api_key = "12345678910"
|
7
|
+
config.api_secret = "10987654321"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_config
|
12
|
-
assert_equal
|
13
|
-
assert_equal
|
12
|
+
assert_equal "12345678910", Phaxio.api_key
|
13
|
+
assert_equal "10987654321", Phaxio.api_secret
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_initialize
|
17
|
-
assert_instance_of Phaxio::Client, @client
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_send_fax
|
21
|
-
@response =
|
20
|
+
@response = Phaxio.send_fax(to: "0123456789", filename: "test.pdf")
|
22
21
|
assert_equal true, @response["success"]
|
23
22
|
assert_equal "Fax queued for sending", @response["message"]
|
24
23
|
assert_equal 1234, @response["faxId"]
|
25
24
|
end
|
26
25
|
|
27
26
|
def test_test_receive
|
28
|
-
@response =
|
27
|
+
@response = Phaxio.test_receive(filename: "test_file.pdf")
|
29
28
|
assert_equal true, @response["success"]
|
30
29
|
assert_equal "Test fax received from 234567890. Calling back now...", @response["message"]
|
31
30
|
end
|
32
31
|
|
33
32
|
def test_get_fax_status
|
34
|
-
@response =
|
33
|
+
@response = Phaxio.get_fax_status(id: "123456")
|
35
34
|
assert_equal true, @response["success"]
|
36
35
|
assert_equal "Retrieved fax successfully", @response["message"]
|
37
36
|
end
|
38
37
|
|
39
38
|
def test_cancel_fax
|
40
|
-
@response =
|
39
|
+
@response = Phaxio.cancel_fax(id: "123456")
|
41
40
|
assert_equal true, @response["success"]
|
42
41
|
assert_equal "Fax canceled successfully.", @response["message"]
|
43
42
|
end
|
44
43
|
|
45
44
|
def test_get_account_status
|
46
|
-
@response =
|
45
|
+
@response = Phaxio.get_account_status
|
47
46
|
assert_equal true, @response["success"]
|
48
47
|
assert_equal "Account status retrieved successfully", @response["message"]
|
49
48
|
assert_equal 120, @response["data"]["faxes_sent_this_month"]
|