phaxio 0.3.1 → 0.4.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.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Ruby gem for interacting with the [Phaxio API]( https://www.phaxio.com/docs ).
4
4
 
5
-
5
+ **Note: This gem only runs on Ruby version 1.9.+**
6
6
 
7
7
  ## Installation
8
8
 
@@ -35,8 +35,15 @@ To send a fax:
35
35
 
36
36
  * send_fax - `Phaxio.send_fax(to: "0123456789", filename: "test.pdf")`
37
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")`
38
+ * provision_number - `Phaxio.provision_number(area_code: 802)`
39
+ * release_number - `Phaxio.release_number(number: "8021112222")`
40
+ * list_numbers - `Phaxio.list_numbers(area_code: 802)`
41
+ * get_fax_file - `Phaxio.get_fax_file(id: 123456, type: p)`
42
+ * list_faxes - `Phaxio.list_numbers(area_code: 802)`
43
+ * list_faxes - `Phaxio.list_faxes(start: Time.now - 48000,
44
+ end: Time.now)`
45
+ * get_fax_status - `Phaxio.get_fax_status(id: 123456)`
46
+ * cancel_fax - `Phaxio.cancel_fax(id: 123456)`
40
47
  * get_account_status - `Phaxio.get_account_status`
41
48
 
42
49
  ### Example
@@ -51,6 +58,12 @@ To send a fax:
51
58
  @fax = Phaxio.send_fax(to: '15555555555', string_data: "hello world")
52
59
  Phaxio.get_fax_status(id: @fax["faxId"])
53
60
 
61
+ # Get a Fax and save it as a PDF
62
+ @pdf = Phaxio.get_fax_file(id: @fax["faxId"], type: "p")
63
+ File.open("received_test.pdf", "w") do |file|
64
+ file << @pdf
65
+ end
66
+
54
67
  ## Contributing
55
68
 
56
69
  1. Fork it
@@ -65,7 +65,6 @@ module Phaxio
65
65
  # Returns a HTTParty::Response object containing a success bool,
66
66
  # a String message, and an in faxID.
67
67
  def send_fax(options)
68
- options.merge!({api_key: api_key, api_secret: api_secret})
69
68
  send_post("/send", options)
70
69
  end
71
70
 
@@ -86,10 +85,109 @@ module Phaxio
86
85
  # Returns a HTTParty::Response object containing a success bool
87
86
  # and a String message.
88
87
  def test_receive(options)
89
- options.merge!({api_key: api_key, api_secret: api_secret})
90
88
  send_post("/testReceive", options)
91
89
  end
92
90
 
91
+ # Public: Provision a phone number that you can use to receive faxes in
92
+ # your Phaxio account.
93
+ #
94
+ # options - The Hash options used to refine the selection (default: {}):
95
+ # area_code - The integer area code of the number you'd like
96
+ # to provision (required).
97
+ # callback_url - A callback URL that Phaxio will post to when a
98
+ # fax is received by this number. This will
99
+ # override the global receive callback URL, if you
100
+ # have one set (optional).
101
+ #
102
+ # Examples
103
+ #
104
+ # Phaxio.provision_number(area_code: 802)
105
+ #
106
+ # Returns a HTTParty::Response object containing a success bool, a string
107
+ # message, and data containing the phone number, city, state, cost,
108
+ # last_billed_at, and the date the number was provisioned at.
109
+ def provision_number(options)
110
+ send_post("/provisionNumber", options)
111
+ end
112
+
113
+ # Public: Release a phone number that you no longer need. Once a phone
114
+ # number is released you will no longer be charged for it.
115
+ #
116
+ # options - The Hash options used to refine the selection (default: {}):
117
+ # number - The String of the phone number you want to release
118
+ # (required).
119
+ #
120
+ # Examples
121
+ #
122
+ # Phaxio.release_number(number: "8021112222")
123
+ #
124
+ # Returns a HTTParty::Response object containing a success bool and a
125
+ # string message.
126
+ def release_number(options)
127
+ send_post("/releaseNumber", options)
128
+ end
129
+
130
+ # Public: Get a detailed list of the phone numbers you current own on
131
+ # Phaxio.
132
+ #
133
+ # options - The Hash options used to refne th selection (default: {}):
134
+ # area_code - An integer area code you'd like to filter by
135
+ # (optional).
136
+ # number - A String phone number you'd like to retrieve
137
+ # (optional).
138
+ #
139
+ # Examples
140
+ #
141
+ # Phaxio.list_numbers # list all the numbers you own
142
+ #
143
+ # Phaxio.list_numbers(area_code: 802) # list all numbers in the 802 area
144
+ #
145
+ # Phaxio.list_numbers(number: "8021112222") # show specific number detail
146
+ #
147
+ # Returns a HTTParty::Reponse object containing a success bool, a message,
148
+ # and the data attributes containing the queried phone number(s) details.
149
+ def list_numbers(options = {})
150
+ send_post("/numberList", options)
151
+ end
152
+
153
+ # Public: Get an image thumbnail or PDF file for a fax. For images to work
154
+ # file storage must not be disabled with Phaxio.
155
+ #
156
+ # options - The Hash options used to refine the selection (default: {}):
157
+ # id - The integer fax id of the fax you wish to retreive
158
+ # (required).
159
+ # type - An enum for the type return, defaults to 'p' (optional):
160
+ # s - Small JPG format thumbnail of the fax, 129 x 167 px.
161
+ # l - Large JPG format thumbnail of the fax, 300 x 388 px.
162
+ # p - PDF version of the fax (default).
163
+ #
164
+ # Examples
165
+ #
166
+ # Phaxio.get_fax_file(id: 1234, type: p)
167
+ # Phaxio.get_fax_file(id: 3254, type: l)
168
+ #
169
+ # Returns the fax as the type specified in the call, defaults to PDF.
170
+ def get_fax_file(options)
171
+ send_post("/faxFile", options)
172
+ end
173
+
174
+ # Public: List faxes within the specified time range.
175
+ #
176
+ # options - The Hash options used to refine the selection (default: {}):
177
+ # start - The Unix Timestamp for the beginning of the range
178
+ # (required).
179
+ # end - The Unix Timestamp for the end of the range (required).
180
+ #
181
+ # Examples
182
+ #
183
+ # Phaxio.list_faxes(start: 1293861600, end: 1294034400)
184
+ #
185
+ # Returns a HTTParty::Response object containing a success bool, a string
186
+ # message, paging information, and the fax data.
187
+ def list_faxes(options)
188
+ send_post("/faxList", options)
189
+ end
190
+
93
191
  # Public: Get the status of a specific fax.
94
192
  #
95
193
  # options - The Hash options used to refine the selection (default: {}):
@@ -107,7 +205,6 @@ module Phaxio
107
205
  raise StandardError, "You must include a fax id."
108
206
  end
109
207
 
110
- options.merge!({api_key: api_key, api_secret: api_secret})
111
208
  send_post("/faxStatus", options)
112
209
  end
113
210
 
@@ -123,7 +220,6 @@ module Phaxio
123
220
  # Returns a HTTParty::Response object containing a success bool
124
221
  # and a String message.
125
222
  def cancel_fax(options)
126
- options.merge!({api_key: api_key, api_secret: api_secret})
127
223
  send_post("/faxCancel", options)
128
224
  end
129
225
 
@@ -1,3 +1,3 @@
1
1
  module Phaxio
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,68 @@
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
+ }
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "success":true,
3
+ "message":"Number provisioned successfully!",
4
+ "data":{
5
+ "number":"8021112222",
6
+ "city":"Burlington",
7
+ "state":"Vermont",
8
+ "cost":200,
9
+ "last_billed_at":"2012-10-11 10:00:44",
10
+ "provisioned_at":"2012-10-11 10:00:44"
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "success":true,
3
+ "message":"Number released successfully!",
4
+ "data":[
5
+
6
+ ]
7
+ }
@@ -3,6 +3,11 @@ require "test/unit"
3
3
  require "fakeweb"
4
4
  require "lib/phaxio"
5
5
 
6
+ Phaxio.config do |config|
7
+ config.api_key = "12345678910"
8
+ config.api_secret = "10987654321"
9
+ end
10
+
6
11
  FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/send",
7
12
  :body => File.open("test/support/responses/send_success.json").read,
8
13
  :content_type => "application/json")
@@ -15,6 +20,26 @@ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/testReceive",
15
20
  :body => File.open("test/support/responses/test_receive.json").read,
16
21
  :content_type => "application/json")
17
22
 
23
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/provisionNumber",
24
+ :body => File.open("test/support/responses/provision_number.json").read,
25
+ :content_type => "application/json")
26
+
27
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/releaseNumber",
28
+ :body => File.open("test/support/responses/release_number.json").read,
29
+ :content_type => "application/json")
30
+
31
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/numberList",
32
+ :body => File.open("test/support/responses/list_numbers.json").read,
33
+ :content_type => "application/json")
34
+
35
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxFile",
36
+ :body => File.open("test/support/responses/test.pdf").read,
37
+ :content_type => "application/pdf")
38
+
39
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxList",
40
+ :body => File.open("test/support/responses/list_faxes.json").read,
41
+ :content_type => "application/json")
42
+
18
43
  FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxStatus",
19
44
  :body => File.open("test/support/responses/fax_status_success.json").read,
20
45
  :content_type => "application/json")
@@ -1,13 +1,6 @@
1
1
  require_relative "test_helper"
2
2
 
3
3
  class TestPhaxio < Test::Unit::TestCase
4
- def setup
5
- Phaxio.config do |config|
6
- config.api_key = "12345678910"
7
- config.api_secret = "10987654321"
8
- end
9
- end
10
-
11
4
  def test_config
12
5
  assert_equal "12345678910", Phaxio.api_key
13
6
  assert_equal "10987654321", Phaxio.api_secret
@@ -29,14 +22,43 @@ class TestPhaxio < Test::Unit::TestCase
29
22
  assert_equal "Test fax received from 234567890. Calling back now...", @response["message"]
30
23
  end
31
24
 
25
+ def test_provision_number
26
+ @response = Phaxio.provision_number(area_code: 802)
27
+ assert_equal true, @response["success"]
28
+ assert_equal "Number provisioned successfully!", @response["message"]
29
+ assert_equal "Vermont", @response["data"]["state"]
30
+ end
31
+
32
+ def test_release_number
33
+ @response = Phaxio.release_number(number: "8021112222")
34
+ assert_equal true, @response["success"]
35
+ assert_equal "Number released successfully!", @response["message"]
36
+ end
37
+
38
+ def test_list_numbers
39
+ @response = Phaxio.list_numbers(area_code: 802)
40
+ assert_equal true, @response["success"]
41
+ assert_equal "Retrieved user phone numbers successfully", @response["message"]
42
+ end
43
+
44
+ def test_get_fax_file
45
+ @response_pdf = Phaxio.get_fax_file(id: 1234, type: p)
46
+ assert_equal 6725, @response_pdf.size
47
+ end
48
+
49
+ def test_list_faxes
50
+ @response = Phaxio.list_faxes(start: 1293861600, end: 1294034400)
51
+ assert_equal true, @response["success"]
52
+ end
53
+
32
54
  def test_get_fax_status
33
- @response = Phaxio.get_fax_status(id: "123456")
55
+ @response = Phaxio.get_fax_status(id: 123456)
34
56
  assert_equal true, @response["success"]
35
57
  assert_equal "Retrieved fax successfully", @response["message"]
36
58
  end
37
59
 
38
60
  def test_cancel_fax
39
- @response = Phaxio.cancel_fax(id: "123456")
61
+ @response = Phaxio.cancel_fax(id: 123456)
40
62
  assert_equal true, @response["success"]
41
63
  assert_equal "Fax canceled successfully.", @response["message"]
42
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phaxio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-04 00:00:00.000000000 Z
13
+ date: 2012-10-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httmultiparty
@@ -79,12 +79,16 @@ files:
79
79
  - lib/phaxio/client.rb
80
80
  - lib/phaxio/version.rb
81
81
  - phaxio.gemspec
82
- - test/support/account_status.json
83
82
  - test/support/responses/account_status.json
84
83
  - test/support/responses/cancel_success.json
85
84
  - test/support/responses/fax_status_success.json
85
+ - test/support/responses/list_faxes.json
86
+ - test/support/responses/list_numbers.json
87
+ - test/support/responses/provision_number.json
88
+ - test/support/responses/release_number.json
86
89
  - test/support/responses/send_failure.json
87
90
  - test/support/responses/send_success.json
91
+ - test/support/responses/test.pdf
88
92
  - test/support/responses/test_receive.json
89
93
  - test/test_helper.rb
90
94
  - test/test_phaxio.rb
@@ -108,17 +112,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
112
  version: '0'
109
113
  requirements: []
110
114
  rubyforge_project:
111
- rubygems_version: 1.8.23
115
+ rubygems_version: 1.8.24
112
116
  signing_key:
113
117
  specification_version: 3
114
118
  summary: A Ruby Gem for interacting with Phaxio's JSON API
115
119
  test_files:
116
- - test/support/account_status.json
117
120
  - test/support/responses/account_status.json
118
121
  - test/support/responses/cancel_success.json
119
122
  - test/support/responses/fax_status_success.json
123
+ - test/support/responses/list_faxes.json
124
+ - test/support/responses/list_numbers.json
125
+ - test/support/responses/provision_number.json
126
+ - test/support/responses/release_number.json
120
127
  - test/support/responses/send_failure.json
121
128
  - test/support/responses/send_success.json
129
+ - test/support/responses/test.pdf
122
130
  - test/support/responses/test_receive.json
123
131
  - test/test_helper.rb
124
132
  - test/test_phaxio.rb
@@ -1,9 +0,0 @@
1
- {
2
- "success":true,
3
- "message":"Account status retrieved successfully",
4
- "data":{
5
- "faxes_sent_this_month":120,
6
- "faxes_sent_today":10,
7
- "balance":3000
8
- }
9
- }