phaxio 2.1.0.pre → 2.1.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/README.md +17 -17
- data/lib/phaxio/client.rb +2 -6
- data/lib/phaxio/config.rb +6 -4
- data/lib/phaxio/resource.rb +11 -5
- data/lib/phaxio/resources/account.rb +1 -1
- data/lib/phaxio/resources/ata.rb +85 -19
- data/lib/phaxio/resources/callback.rb +10 -56
- data/lib/phaxio/resources/fax.rb +11 -11
- data/lib/phaxio/resources/phax_code.rb +2 -2
- data/lib/phaxio/resources/phone_number.rb +31 -5
- data/lib/phaxio/resources/port_number.rb +42 -0
- data/lib/phaxio/resources/port_number_note.rb +51 -0
- data/lib/phaxio/resources/port_order.rb +172 -0
- data/lib/phaxio/resources/public/area_code.rb +1 -1
- data/lib/phaxio/resources/public/country.rb +1 -1
- data/lib/phaxio/resources/webhook.rb +65 -0
- data/lib/phaxio/version.rb +1 -1
- data/lib/phaxio.rb +12 -3
- data/spec/phaxio_spec.rb +7 -1
- data/spec/resources/account_spec.rb +1 -7
- data/spec/resources/ata_spec.rb +207 -0
- data/spec/resources/fax_spec.rb +35 -103
- data/spec/resources/phax_code_spec.rb +10 -44
- data/spec/resources/phone_number_spec.rb +19 -30
- data/spec/resources/port_number_note_spec.rb +33 -0
- data/spec/resources/port_number_spec.rb +32 -0
- data/spec/resources/port_order_spec.rb +76 -0
- data/spec/resources/public/area_code_spec.rb +1 -1
- data/spec/resources/public/country_spec.rb +1 -7
- data/spec/resources/{callback_spec.rb → webhook_spec.rb} +8 -8
- data/spec/spec_helper.rb +1 -0
- data/spec/support/{vcr_cassettes/resources/account/status.yml → cassettes/account/get.yml} +7 -9
- data/spec/support/cassettes/ata/add_phone_number.yml +89 -0
- data/spec/support/{vcr_cassettes/resources/fax/resend.yml → cassettes/ata/create.yml} +12 -13
- data/spec/support/cassettes/ata/delete.yml +86 -0
- data/spec/support/cassettes/ata/get.yml +87 -0
- data/spec/support/cassettes/ata/list.yml +67 -0
- data/spec/support/{vcr_cassettes/resources/phax_code/get_id.yml → cassettes/ata/provisioning_urls.yml} +10 -13
- data/spec/support/cassettes/ata/reference.yml +87 -0
- data/spec/support/cassettes/ata/regenerate.yml +89 -0
- data/spec/support/cassettes/ata/remove_phone_number.yml +130 -0
- data/spec/support/cassettes/ata/update.yml +89 -0
- data/spec/support/{vcr_cassettes/resources/fax/create_for_cancel.yml → cassettes/fax/cancel.yml} +51 -11
- data/spec/support/{vcr_cassettes/resources/fax/create_for_reference.yml → cassettes/fax/create.yml} +11 -13
- data/spec/support/{vcr_cassettes/resources/fax/create.yml → cassettes/fax/delete.yml} +49 -11
- data/spec/support/{vcr_cassettes/resources/fax/create_for_delete.yml → cassettes/fax/delete_file.yml} +49 -11
- data/spec/support/cassettes/fax/file.yml +93 -0
- data/spec/support/{vcr_cassettes/resources/fax/create_for_download_file.yml → cassettes/fax/get.yml} +49 -11
- data/spec/support/{vcr_cassettes/resources → cassettes}/fax/list.yml +5 -7
- data/spec/support/cassettes/fax/reference.yml +88 -0
- data/spec/support/{vcr_cassettes/resources/fax/create_for_delete_file.yml → cassettes/fax/resend.yml} +51 -11
- data/spec/support/{vcr_cassettes/resources → cassettes}/fax/test_receive.yml +7 -9
- data/spec/support/{vcr_cassettes/resources → cassettes}/phax_code/create.yml +8 -10
- data/spec/support/{vcr_cassettes/resources → cassettes}/phax_code/create_png.yml +8 -10
- data/spec/support/cassettes/phax_code/get_by_id.yml +86 -0
- data/spec/support/{vcr_cassettes/resources/phax_code/get.yml → cassettes/phax_code/get_default.yml} +8 -10
- data/spec/support/{vcr_cassettes/resources/phax_code/get_png.yml → cassettes/phax_code/get_default_png.yml} +8 -10
- data/spec/support/cassettes/phax_code/get_png_by_id.yml +90 -0
- data/spec/support/{vcr_cassettes/resources → cassettes}/phone_number/create.yml +8 -10
- data/spec/support/{vcr_cassettes/resources → cassettes}/phone_number/get.yml +10 -12
- data/spec/support/cassettes/phone_number/list.yml +72 -0
- data/spec/support/cassettes/phone_number/reference.yml +45 -0
- data/spec/support/cassettes/phone_number/release.yml +86 -0
- data/spec/support/cassettes/port_number/get.yml +88 -0
- data/spec/support/cassettes/port_number_note/list.yml +88 -0
- data/spec/support/cassettes/port_order/create.yml +48 -0
- data/spec/support/cassettes/port_order/get.yml +91 -0
- data/spec/support/cassettes/port_order/list.yml +52 -0
- data/spec/support/{vcr_cassettes/resources/public/area_codes → cassettes/public/area_code}/list.yml +15 -17
- data/spec/support/{vcr_cassettes/resources → cassettes}/public/country/list.yml +5 -7
- data/spec/support/vcr.rb +24 -6
- metadata +115 -41
- data/spec/support/credentials.rb +0 -7
- data/spec/support/vcr_cassettes/resources/fax/cancel.yml +0 -47
- data/spec/support/vcr_cassettes/resources/fax/create_for_get.yml +0 -50
- data/spec/support/vcr_cassettes/resources/fax/create_for_resend.yml +0 -50
- data/spec/support/vcr_cassettes/resources/fax/delete.yml +0 -45
- data/spec/support/vcr_cassettes/resources/fax/delete_file.yml +0 -45
- data/spec/support/vcr_cassettes/resources/fax/file.yml +0 -50
- data/spec/support/vcr_cassettes/resources/fax/get.yml +0 -45
- data/spec/support/vcr_cassettes/resources/fax/reference.yml +0 -45
- data/spec/support/vcr_cassettes/resources/phax_code/get_id_png.yml +0 -50
- data/spec/support/vcr_cassettes/resources/phone_number/list.yml +0 -60
- data/spec/support/vcr_cassettes/resources/phone_number/release.yml +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 508fcbe635de23974bfdefe06aec6811fd7f91bd03377dd4a90b971cd1b6a44f
|
4
|
+
data.tar.gz: e33347de232350332fe604ecae8c0f511a3774fb9ef7c863f6a269bb53bad787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a041ed3d71f144ae2c2776a69be5d947982f1eb76c2a2e748f07b245d48ac8714c9199702b71a9b8c0cd404ea6318518834cb9da9365f569cc6b35633c66e83
|
7
|
+
data.tar.gz: d50baaa1fc873a3a20268fb0c56d1b902d0b922d8fcdb731d40e23d89c74bd9c6fea3e35aa66e8c7472502b5af7ac1ad060b5cec22d3fe244e816d98d9be10d5
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/phaxio/phaxio-ruby)
|
4
4
|
|
5
|
-
A Ruby gem for interacting with the [Phaxio API](https://www.phaxio.com/docs/api/v2).
|
5
|
+
A Ruby gem for interacting with the [Phaxio API](https://www.phaxio.com/docs/api/v2.1).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -26,14 +26,14 @@ $ gem install phaxio
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
Set up your API Key, API Secret, and, optionally,
|
29
|
+
Set up your API Key, API Secret, and, optionally, Webhook Token.
|
30
30
|
|
31
31
|
``` ruby
|
32
32
|
require 'phaxio'
|
33
33
|
|
34
34
|
Phaxio.api_key = '11111'
|
35
35
|
Phaxio.api_secret = '22222'
|
36
|
-
Phaxio.
|
36
|
+
Phaxio.webhook_token = '33333'
|
37
37
|
```
|
38
38
|
|
39
39
|
Try sending a fax:
|
@@ -243,32 +243,32 @@ Account.get
|
|
243
243
|
# => Account(balance: 1000, faxes_today: 0, faxes_this_month: 100)
|
244
244
|
```
|
245
245
|
|
246
|
-
####
|
246
|
+
#### Webhook
|
247
247
|
|
248
|
-
##### `
|
248
|
+
##### `Webhook.valid_signature?`
|
249
249
|
|
250
|
-
Validate the
|
250
|
+
Validate the webhook signature sent with a Phaxio webhook. Requires that Phaxio.webhook_token be
|
251
251
|
set.
|
252
252
|
|
253
253
|
``` ruby
|
254
|
-
|
254
|
+
Webhook.valid_signature? received_signature, webhook_url, received_params, received_files
|
255
255
|
# => true
|
256
256
|
```
|
257
257
|
|
258
|
-
##
|
258
|
+
## Webhook Validation Example with Sinatra
|
259
259
|
|
260
260
|
``` ruby
|
261
261
|
require 'sinatra/base'
|
262
262
|
require 'phaxio'
|
263
263
|
|
264
264
|
class PhaxioWebhookExample < Sinatra::Base
|
265
|
-
Phaxio.
|
266
|
-
|
265
|
+
Phaxio.webhook_token = 'YOUR WEBHOOK TOKEN HERE'
|
266
|
+
|
267
267
|
post '/webhook' do
|
268
268
|
signature = request.env['HTTP_X_PHAXIO_SIGNATURE']
|
269
269
|
url = request.url
|
270
270
|
file_params = params[:file]
|
271
|
-
if Phaxio::
|
271
|
+
if Phaxio::Webhook.valid_signature? signature, url, webhook_params, file_params
|
272
272
|
'Success'
|
273
273
|
else
|
274
274
|
'Invalid webhook signature'
|
@@ -289,22 +289,22 @@ end
|
|
289
289
|
class WebhookController < ApplicationController
|
290
290
|
skip_before_action :verify_authenticity_token
|
291
291
|
|
292
|
-
|
292
|
+
def index
|
293
293
|
signature = request.headers['X-Phaxio-Signature']
|
294
|
-
Phaxio.
|
294
|
+
Phaxio.webhook_token = 'YOUR WEBHOOK TOKEN HERE'
|
295
295
|
url = request.original_url
|
296
296
|
|
297
297
|
Rails.logger.debug "URL: " + url
|
298
298
|
Rails.logger.debug "Signature: " + signature
|
299
299
|
Rails.logger.debug "params: " + params.inspect
|
300
300
|
Rails.logger.debug "webhook_params: " + webhook_params.to_h.inspect
|
301
|
-
|
302
|
-
if Phaxio::
|
301
|
+
|
302
|
+
if Phaxio::Webhook.valid_signature? signature, url, webhook_params.to_h, file_params
|
303
303
|
Rails.logger.debug "Success"
|
304
304
|
render plain: 'Success'
|
305
305
|
else
|
306
|
-
Rails.logger.debug "Invalid
|
307
|
-
render plain: 'Invalid
|
306
|
+
Rails.logger.debug "Invalid webhook signature"
|
307
|
+
render plain: 'Invalid webhook signature'
|
308
308
|
end
|
309
309
|
end
|
310
310
|
|
data/lib/phaxio/client.rb
CHANGED
@@ -44,10 +44,6 @@ module Phaxio
|
|
44
44
|
conn.request :multipart
|
45
45
|
conn.request :url_encoded
|
46
46
|
conn.adapter :net_http
|
47
|
-
|
48
|
-
if Phaxio.api_key && Phaxio.api_secret
|
49
|
-
conn.basic_auth Phaxio.api_key, Phaxio.api_secret
|
50
|
-
end
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
@@ -153,8 +149,8 @@ module Phaxio
|
|
153
149
|
end
|
154
150
|
|
155
151
|
def api_headers params
|
156
|
-
api_key = params
|
157
|
-
api_secret = params
|
152
|
+
api_key = params.delete(:api_key) || Phaxio.api_key
|
153
|
+
api_secret = params.delete(:api_secret) || Phaxio.api_secret
|
158
154
|
return unless api_key && api_secret
|
159
155
|
auth = Base64.strict_encode64("#{api_key}:#{api_secret}")
|
160
156
|
{'Authorization' => "Basic #{auth}"}
|
data/lib/phaxio/config.rb
CHANGED
@@ -13,14 +13,16 @@ module Phaxio
|
|
13
13
|
# To find your API secret, visit https://console.phaxio.com/api_credentials
|
14
14
|
attr_accessor :api_secret
|
15
15
|
|
16
|
-
# Your Phaxio
|
16
|
+
# Your Phaxio webhook token. This will be used to verify that webhook requests are coming
|
17
17
|
# from Phaxio.
|
18
18
|
#
|
19
|
-
# To find your
|
20
|
-
attr_accessor :
|
19
|
+
# To find your webhook token, visit https://console.phaxio.com/user/callbacks/edit
|
20
|
+
attr_accessor :webhook_token
|
21
|
+
alias callback_token webhook_token
|
22
|
+
alias callback_token= webhook_token=
|
21
23
|
|
22
24
|
# The Phaxio API endpoint. Users generally shouldn't need to change it.
|
23
|
-
# Defaults to https://api.phaxio.com/v2/
|
25
|
+
# Defaults to https://api.phaxio.com/v2.1/
|
24
26
|
attr_writer :api_endpoint
|
25
27
|
|
26
28
|
def api_endpoint
|
data/lib/phaxio/resource.rb
CHANGED
@@ -139,12 +139,18 @@ module Phaxio
|
|
139
139
|
#
|
140
140
|
# @see Phaxio::Resource.response_collection
|
141
141
|
def initialize response_data, resource
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
142
|
+
# For some endpoints we'll get a hash with `paging` and `data` attributes.
|
143
|
+
# For others, just an array.
|
144
|
+
if response_data.is_a? Hash
|
145
|
+
if response_data.key? 'paging'
|
146
|
+
self.total = response_data['paging']['total']
|
147
|
+
self.per_page = response_data['paging']['per_page']
|
148
|
+
self.page = response_data['paging']['page']
|
149
|
+
end
|
150
|
+
self.raw_data = response_data['data']
|
151
|
+
else
|
152
|
+
self.raw_data = response_data
|
146
153
|
end
|
147
|
-
self.raw_data = response_data['data']
|
148
154
|
self.collection = raw_data.map { |record_data| resource.response_record record_data }
|
149
155
|
end
|
150
156
|
|
@@ -22,7 +22,7 @@ module Phaxio
|
|
22
22
|
# Any parameters to send to Phaxio. This action does not have any unique parameters.
|
23
23
|
# @return [Phaxio::Resources::Acount] Your account information.
|
24
24
|
# @raise [Phaxio::Error::PhaxioError]
|
25
|
-
# @see https://www.phaxio.com/docs/api/v2/account/status
|
25
|
+
# @see https://www.phaxio.com/docs/api/v2.1/account/status
|
26
26
|
def get params = {}
|
27
27
|
response = Client.request :get, account_status_endpoint, params
|
28
28
|
response_record response
|
data/lib/phaxio/resources/ata.rb
CHANGED
@@ -20,14 +20,37 @@ module Phaxio
|
|
20
20
|
# @return [String] The domain for the ATA.
|
21
21
|
# @!attribute domain
|
22
22
|
|
23
|
+
# @return [String] The user agent for the ATA.
|
24
|
+
# @!attribute user_agent
|
25
|
+
|
26
|
+
# @return [String] The SIP URI for the ATA.
|
27
|
+
# @!attribute sip_uri
|
28
|
+
|
29
|
+
# @return [String] The mac address for the ATA.
|
30
|
+
# @!attribute mac_address
|
31
|
+
|
32
|
+
# @return [String] The name of the group which the ATA belongs to.
|
33
|
+
# @!attribute group
|
34
|
+
|
23
35
|
# @return [String] The username for the ATA.
|
24
|
-
# @!attribute
|
36
|
+
# @!attribute username
|
25
37
|
|
26
38
|
# @return [String] The password for the ATA.
|
27
39
|
# @!attribute password
|
28
40
|
|
29
41
|
has_normal_attributes %w[
|
30
|
-
id name description user_phone_number domain
|
42
|
+
id name description user_phone_number domain user_agent sip_uri
|
43
|
+
mac_address group username password
|
44
|
+
]
|
45
|
+
|
46
|
+
# @return [Time] The time at which the ATA was last registered.
|
47
|
+
# @!attribute last_registered
|
48
|
+
|
49
|
+
# @return [Time] The time at which the ATA's registration expires.
|
50
|
+
# @!attribute expiry_time
|
51
|
+
|
52
|
+
has_time_attributes %w[
|
53
|
+
last_registered expiry_time
|
31
54
|
]
|
32
55
|
|
33
56
|
# A reference to an ATA. This is returned by certain actions which don't
|
@@ -41,6 +64,14 @@ module Phaxio
|
|
41
64
|
id
|
42
65
|
end
|
43
66
|
|
67
|
+
# Gets the referenced ATA.
|
68
|
+
# @return [Phaxio::Resources::ATA]
|
69
|
+
def get
|
70
|
+
Ata.get self
|
71
|
+
end
|
72
|
+
alias :retrieve :get
|
73
|
+
alias :find :get
|
74
|
+
|
44
75
|
private
|
45
76
|
|
46
77
|
def initialize id
|
@@ -48,21 +79,33 @@ module Phaxio
|
|
48
79
|
end
|
49
80
|
end
|
50
81
|
|
51
|
-
# A
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
|
56
|
-
|
82
|
+
# A set of provisioning URLs.
|
83
|
+
class ProvisioningURLs
|
84
|
+
# @return [Hash<String: String>] The hash of provisioning URLs.
|
85
|
+
# @!attribute urls
|
86
|
+
attr_reader :urls
|
87
|
+
|
88
|
+
GRANDSTREAM = 'Grandstream'
|
89
|
+
OBI = 'OBi'
|
90
|
+
NETGEN = 'Netgen'
|
57
91
|
|
58
|
-
def
|
59
|
-
|
92
|
+
def initialize data
|
93
|
+
@urls = data
|
60
94
|
end
|
61
95
|
|
62
|
-
|
96
|
+
# @return [String] The Grandstream provisioning url.
|
97
|
+
def grandstream
|
98
|
+
self.urls.fetch(GRANDSTREAM)
|
99
|
+
end
|
100
|
+
|
101
|
+
# @return [String] The OBi provisioning url.
|
102
|
+
def obi
|
103
|
+
self.urls.fetch(OBI)
|
104
|
+
end
|
63
105
|
|
64
|
-
|
65
|
-
|
106
|
+
# @return [String] The Netgen provisioning url.
|
107
|
+
def netgen
|
108
|
+
self.urls.fetch(NETGEN)
|
66
109
|
end
|
67
110
|
end
|
68
111
|
|
@@ -86,6 +129,7 @@ module Phaxio
|
|
86
129
|
# - *name* [String] - A name used to identify the ATA.
|
87
130
|
# - *description* [String] - A longer description of the ATA.
|
88
131
|
# - *domain* [String] - A domain for the ATA.
|
132
|
+
# - *mac_address* [String] - A mac address for the ATA.
|
89
133
|
# @return [Phaxio::Resources::Ata]
|
90
134
|
# The created ATA, including the generated username and password.
|
91
135
|
# @raise [Phaxio::Error::PhaxioError]
|
@@ -99,7 +143,9 @@ module Phaxio
|
|
99
143
|
# @param id [Integer]
|
100
144
|
# The ID of the ATA to retrieve information about.
|
101
145
|
# @param params [Hash]
|
102
|
-
# Any parameters to send to Phaxio.
|
146
|
+
# Any parameters to send to Phaxio.
|
147
|
+
# - *with_credentials* [Boolean] - If enabled, the username and
|
148
|
+
# password for the ATA will be included in the response.
|
103
149
|
# @return [Phaxio::Resources::Ata]
|
104
150
|
# The requested ATA.
|
105
151
|
# @raise [Phaxio::Error::PhaxioError]
|
@@ -118,7 +164,7 @@ module Phaxio
|
|
118
164
|
# Any parameters to send to Phaxio.
|
119
165
|
# - *name* [String] - A name used to identify the ATA.
|
120
166
|
# - *description* [String] - A longer description of the ATA.
|
121
|
-
# - *
|
167
|
+
# - *mac_address* [String] - A mac address for the ATA.
|
122
168
|
# @return [Phaxio::Resources::Ata]
|
123
169
|
# The updated ATA.
|
124
170
|
# @raise [Phaxio::Error::PhaxioError]
|
@@ -144,7 +190,7 @@ module Phaxio
|
|
144
190
|
|
145
191
|
# Delete an ATA
|
146
192
|
# @param id [Integer]
|
147
|
-
# The
|
193
|
+
# The ID of the ATA to delete.
|
148
194
|
# @param params [Hash]
|
149
195
|
# Any parameters to send to Phaxio. This action takes no unique parameters.
|
150
196
|
# @return [Phaxio::Resources::Ata::Reference]
|
@@ -163,7 +209,7 @@ module Phaxio
|
|
163
209
|
# The phone number to add to the ATA.
|
164
210
|
# @param params [Hash]
|
165
211
|
# Any parameters to send to Phaxio. This action takes no unique parameters.
|
166
|
-
# @return [Phaxio::Resources::
|
212
|
+
# @return [Phaxio::Resources::PhoneNumber::Reference]
|
167
213
|
# A reference to the added phone number.
|
168
214
|
# @raise [Phaxio::Error::PhaxioError]
|
169
215
|
# @see https://www.phaxio.com/docs/api/v2.1/atas/add_phone_number
|
@@ -179,7 +225,7 @@ module Phaxio
|
|
179
225
|
# The phone number you want to remove.
|
180
226
|
# @param params [Hash]
|
181
227
|
# Any parameters to send to Phaxio. This action takes no unique parameters.
|
182
|
-
# @return [Phaxio::Resources::
|
228
|
+
# @return [Phaxio::Resources::PhoneNumber::Reference]
|
183
229
|
# A reference to the removed phone number.
|
184
230
|
# @raise [Phaxio::Error::PhaxioError]
|
185
231
|
# @see https://www.phaxio.com/docs/api/v2.1/atas/remove_phone_number
|
@@ -188,6 +234,18 @@ module Phaxio
|
|
188
234
|
response_phone_number_reference response
|
189
235
|
end
|
190
236
|
|
237
|
+
# Get ATA provisioning URLs for your Phaxio account.
|
238
|
+
# @param params [Hash]
|
239
|
+
# Any parameters to send to Phaxio.
|
240
|
+
# - *group* [String] - If given, this action instead returns
|
241
|
+
# provisioning URLs for the named group.
|
242
|
+
# @return [Phaxio::Resources::Ata::ProvisioningURLs
|
243
|
+
# @see https://www.phaxio.com/docs/api/v2.1/atas/provisioning_urls
|
244
|
+
def provisioning_urls params = {}
|
245
|
+
response = Client.request :get, provisioning_urls_endpoint, params
|
246
|
+
response_provisioning_urls response
|
247
|
+
end
|
248
|
+
|
191
249
|
private
|
192
250
|
|
193
251
|
def response_reference response
|
@@ -195,7 +253,11 @@ module Phaxio
|
|
195
253
|
end
|
196
254
|
|
197
255
|
def response_phone_number_reference response
|
198
|
-
|
256
|
+
PhoneNumber::Reference.new(response['phone_number'])
|
257
|
+
end
|
258
|
+
|
259
|
+
def response_provisioning_urls response
|
260
|
+
ProvisioningURLs.new(response)
|
199
261
|
end
|
200
262
|
|
201
263
|
def atas_endpoint
|
@@ -213,6 +275,10 @@ module Phaxio
|
|
213
275
|
def phone_number_endpoint id, phone_number
|
214
276
|
"#{ata_endpoint(id)}/phone_numbers/#{phone_number}"
|
215
277
|
end
|
278
|
+
|
279
|
+
def provisioning_urls_endpoint
|
280
|
+
"#{atas_endpoint}/provisioning_urls"
|
281
|
+
end
|
216
282
|
end
|
217
283
|
end
|
218
284
|
end
|
@@ -1,63 +1,17 @@
|
|
1
1
|
module Phaxio
|
2
2
|
module Resources
|
3
|
-
#
|
4
|
-
# @see
|
5
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/receive_callback
|
3
|
+
# This class is provided for the sake of backwards compatibility; use the Webhook resource instead.
|
4
|
+
# @see Phaxio::Resources::Webhook
|
6
5
|
class Callback
|
7
|
-
DIGEST = OpenSSL::Digest.new('sha1')
|
8
|
-
private_constant :DIGEST
|
9
|
-
|
10
6
|
class << self
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# @param files [Array<File>]
|
20
|
-
# The files received with the callback, if any.
|
21
|
-
# @return [true, false]
|
22
|
-
# @raise [Phaxio::Error::PhaxioError]
|
23
|
-
# @see https://www.phaxio.com/docs/security/callbacks
|
24
|
-
def valid_signature? signature, url, params, files = []
|
25
|
-
check_signature = generate_check_signature url, params, files
|
26
|
-
check_signature == signature
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def generate_check_signature url, params, files = []
|
32
|
-
params_string = generate_params_string(params)
|
33
|
-
files_string = generate_files_string(files)
|
34
|
-
callback_data = "#{url}#{params_string}#{files_string}"
|
35
|
-
OpenSSL::HMAC.hexdigest(DIGEST, callback_token, callback_data)
|
36
|
-
end
|
37
|
-
|
38
|
-
def callback_token
|
39
|
-
Phaxio.callback_token or raise(Error::PhaxioError, 'No callback token has been set')
|
40
|
-
end
|
41
|
-
|
42
|
-
def generate_params_string(params)
|
43
|
-
sorted_params = params.sort_by { |key, _value| key }
|
44
|
-
params_strings = sorted_params.map { |key, value| "#{key}#{value}" }
|
45
|
-
params_strings.join
|
46
|
-
end
|
47
|
-
|
48
|
-
def generate_files_string(files)
|
49
|
-
files_array = files_to_array(files).reject(&:nil?)
|
50
|
-
sorted_files = files_array.sort_by { |file| file[:name] }
|
51
|
-
files_strings = sorted_files.map { |file| generate_file_string(file) }
|
52
|
-
files_strings.join
|
53
|
-
end
|
54
|
-
|
55
|
-
def files_to_array(files)
|
56
|
-
files.is_a?(Array) ? files : [files]
|
57
|
-
end
|
58
|
-
|
59
|
-
def generate_file_string(file)
|
60
|
-
file[:name] + DIGEST.hexdigest(file[:tempfile].read)
|
7
|
+
def valid_signature? *args
|
8
|
+
Phaxio::Resources::Webhook.valid_signature? *args
|
9
|
+
rescue Error::PhaxioError => error
|
10
|
+
if error.message == 'No webhook token has been set'
|
11
|
+
raise Error::PhaxioError, 'No callback token has been set'
|
12
|
+
else
|
13
|
+
raise error
|
14
|
+
end
|
61
15
|
end
|
62
16
|
end
|
63
17
|
end
|
data/lib/phaxio/resources/fax.rb
CHANGED
@@ -84,7 +84,7 @@ module Phaxio
|
|
84
84
|
attr_accessor :id
|
85
85
|
|
86
86
|
# Gets the referenced fax.
|
87
|
-
# @return [Phaxio::
|
87
|
+
# @return [Phaxio::Resources::Fax]
|
88
88
|
# The referenced Fax.
|
89
89
|
def get
|
90
90
|
Fax.get self
|
@@ -120,7 +120,7 @@ module Phaxio
|
|
120
120
|
# @return [Phaxio::Resource::Collection<Phaxio::Resources::Fax>]
|
121
121
|
# The collection of faxes matching your request.
|
122
122
|
# @raise [Phaxio::Error::PhaxioError]
|
123
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/list_faxes
|
123
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/list_faxes
|
124
124
|
def list params = {}
|
125
125
|
response = Client.request :get, faxes_endpoint, params
|
126
126
|
response_collection response
|
@@ -159,8 +159,8 @@ module Phaxio
|
|
159
159
|
# @return [Phaxio::Resources::Fax]
|
160
160
|
# The created fax.
|
161
161
|
# @raise [Phaxio::Error::PhaxioError]
|
162
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/create_and_send_fax
|
163
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/batching
|
162
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/create_and_send_fax
|
163
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/batching
|
164
164
|
def create params = {}
|
165
165
|
response = Client.request :post, faxes_endpoint, params
|
166
166
|
response_reference response
|
@@ -174,7 +174,7 @@ module Phaxio
|
|
174
174
|
# A hash of parameters to send to Phaxio. This action takes no unique parameters.
|
175
175
|
# @return [Phaxio::Resource::Fax] The requested fax.
|
176
176
|
# @raise [Phaxio::Error::PhaxioError]
|
177
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/get_fax
|
177
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/get_fax
|
178
178
|
def get id, params = {}
|
179
179
|
response = Client.request :get, fax_endpoint(id.to_i), params
|
180
180
|
response_record response
|
@@ -191,7 +191,7 @@ module Phaxio
|
|
191
191
|
# @return [Phaxio::Resources::Fax::Reference]
|
192
192
|
# A reference to the canceled fax.
|
193
193
|
# @raise [Phaxio::Error::PhaxioError]
|
194
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/cancel
|
194
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/cancel
|
195
195
|
def cancel id, params = {}
|
196
196
|
response = Client.request :post, cancel_fax_endpoint(id), params
|
197
197
|
response_reference response
|
@@ -207,7 +207,7 @@ module Phaxio
|
|
207
207
|
# @return [Phaxio::Resources::Fax::Reference]
|
208
208
|
# A reference to the resent fax.
|
209
209
|
# @raise [Phaxio::Error::PhaxioError]
|
210
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/resend
|
210
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/resend
|
211
211
|
def resend id, params = {}
|
212
212
|
response = Client.request :post, resend_fax_endpoint(id), params
|
213
213
|
response_reference response
|
@@ -221,7 +221,7 @@ module Phaxio
|
|
221
221
|
# parameters.
|
222
222
|
# @return [true]
|
223
223
|
# @raise [Phaxio::Error::PhaxioError]
|
224
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/delete_fax
|
224
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/delete_fax
|
225
225
|
def delete id, params = {}
|
226
226
|
Client.request :delete, fax_endpoint(id), params
|
227
227
|
true
|
@@ -235,7 +235,7 @@ module Phaxio
|
|
235
235
|
# parameters.
|
236
236
|
# @return [true]
|
237
237
|
# @raise [Phaxio::Error::PhaxioError]
|
238
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/delete_fax_file
|
238
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/delete_fax_file
|
239
239
|
def delete_file id, params = {}
|
240
240
|
Client.request :delete, fax_file_endpoint(id), params
|
241
241
|
true
|
@@ -252,7 +252,7 @@ module Phaxio
|
|
252
252
|
# @return [File]
|
253
253
|
# The requested fax file.
|
254
254
|
# @raise [Phaxio::Error::PhaxioError]
|
255
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/get_fax_file
|
255
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/get_fax_file
|
256
256
|
def file id, params = {}
|
257
257
|
Client.request :get, fax_file_endpoint(id), params
|
258
258
|
end
|
@@ -269,7 +269,7 @@ module Phaxio
|
|
269
269
|
# number. Default is the public Phaxio phone number.
|
270
270
|
# @return [true]
|
271
271
|
# @raise [Phaxio::Error::PhaxioError]
|
272
|
-
# @see https://www.phaxio.com/docs/api/v2/faxes/test_receive
|
272
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/test_receive
|
273
273
|
def test_receive params = {}
|
274
274
|
Client.request :post, faxes_endpoint, test_receive_params(params)
|
275
275
|
true
|
@@ -28,7 +28,7 @@ module Phaxio
|
|
28
28
|
# file instead of a PhaxCode object.
|
29
29
|
# @return [Phaxio::Resources::PhaxCode | File] The created PhaxCode
|
30
30
|
# @raise [Phaxio::Error::PhaxioError]
|
31
|
-
# @see https://www.phaxio.com/docs/api/v2/phaxcodes/create_phax_code
|
31
|
+
# @see https://www.phaxio.com/docs/api/v2.1/phaxcodes/create_phax_code
|
32
32
|
def create params = {}
|
33
33
|
endpoint = case (params[:type] || params['type']).to_s
|
34
34
|
when 'png' then phax_codes_endpoint_png
|
@@ -48,7 +48,7 @@ module Phaxio
|
|
48
48
|
# PhaxCode object.
|
49
49
|
# @return [Phaxio::Resources::PhaxCode | File]
|
50
50
|
# @raise [Phaxio::Error::PhaxioError]
|
51
|
-
# @see https://www.phaxio.com/docs/api/v2/phaxcodes/retrieve_phax_code
|
51
|
+
# @see https://www.phaxio.com/docs/api/v2.1/phaxcodes/retrieve_phax_code
|
52
52
|
def get params = {}
|
53
53
|
identifier = params[:identifier] || params['identifier']
|
54
54
|
endpoint = case (identifier)
|
@@ -33,6 +33,32 @@ module Phaxio
|
|
33
33
|
|
34
34
|
has_time_attributes %w(provisioned_at last_billed_at)
|
35
35
|
|
36
|
+
# A reference to a phone number, returned by some actions.
|
37
|
+
class Reference
|
38
|
+
# @return [String]
|
39
|
+
# The phone number in E.164 format.
|
40
|
+
attr_accessor :phone_number
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
phone_number
|
44
|
+
end
|
45
|
+
|
46
|
+
# Gets the referenced phone number.
|
47
|
+
# @return [Phaxio::Resources::PhoneNumber]
|
48
|
+
# The referenced phone number.
|
49
|
+
def get
|
50
|
+
PhoneNumber.get self
|
51
|
+
end
|
52
|
+
alias :retrieve :get
|
53
|
+
alias :find :get
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def initialize phone_number
|
58
|
+
self.phone_number = phone_number
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
36
62
|
private
|
37
63
|
|
38
64
|
class << self
|
@@ -44,7 +70,7 @@ module Phaxio
|
|
44
70
|
# - *callback_url* [String] - A callback URL that we'll post to when a fax is received by this number. This will override the global receive callback URL, if you have one specified.
|
45
71
|
# @return [Phaxio::Resources::PhoneNumber] The newly provisioned number.
|
46
72
|
# @raise [Phaxio::Error::PhaxioError]
|
47
|
-
# @see https://www.phaxio.com/docs/api/v2/phone_numbers/provision
|
73
|
+
# @see https://www.phaxio.com/docs/api/v2.1/phone_numbers/provision
|
48
74
|
def create params = {}
|
49
75
|
response = Client.request :post, phone_numbers_endpoint, params
|
50
76
|
response_record response
|
@@ -58,9 +84,9 @@ module Phaxio
|
|
58
84
|
# A hash of parameters to send to Phaxio. This action has no unique parameters.
|
59
85
|
# @return [Phaxio::Resources::PhoneNumber] The requested number.
|
60
86
|
# @raise [Phaxio::Error::PhaxioError]
|
61
|
-
# @see https://www.phaxio.com/docs/api/v2/phone_numbers/get_number
|
87
|
+
# @see https://www.phaxio.com/docs/api/v2.1/phone_numbers/get_number
|
62
88
|
def get phone_number, params = {}
|
63
|
-
response = Client.request :get, phone_number_endpoint(phone_number), params
|
89
|
+
response = Client.request :get, phone_number_endpoint(phone_number.to_s), params
|
64
90
|
response_record response
|
65
91
|
end
|
66
92
|
alias :find :get
|
@@ -76,7 +102,7 @@ module Phaxio
|
|
76
102
|
# @return [Phaxio::Resource::Collection<Phaxio::Resources::PhoneNumber>]
|
77
103
|
# A collection of phone numbers.
|
78
104
|
# @raise [Phaxio::Error::PhaxioError]
|
79
|
-
# @see https://www.phaxio.com/docs/api/v2/phone_numbers/list
|
105
|
+
# @see https://www.phaxio.com/docs/api/v2.1/phone_numbers/list
|
80
106
|
def list params = {}
|
81
107
|
response = Client.request :get, phone_numbers_endpoint, params
|
82
108
|
response_collection response
|
@@ -90,7 +116,7 @@ module Phaxio
|
|
90
116
|
# A hash of parameters to send to Phaxio. This action has no unique parameters.
|
91
117
|
# @return true
|
92
118
|
# @raise [Phaxio::Error::PhaxioError]
|
93
|
-
# @see https://www.phaxio.com/docs/api/v2/phone_numbers/release
|
119
|
+
# @see https://www.phaxio.com/docs/api/v2.1/phone_numbers/release
|
94
120
|
def delete phone_number, params = {}
|
95
121
|
Client.request :delete, phone_number_endpoint(phone_number), params
|
96
122
|
true
|