phaxio 0.4.0 → 2.1.0.pre
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 +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +11 -5
- data/README.md +296 -40
- data/Rakefile +7 -9
- data/lib/phaxio.rb +48 -3
- data/lib/phaxio/client.rb +151 -241
- 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/ata.rb +219 -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 +10 -8
- data/spec/client_spec.rb +164 -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 +248 -0
- data/spec/resources/phax_code_spec.rb +111 -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/files/test.txt +1 -0
- data/spec/support/vcr.rb +8 -0
- data/spec/support/vcr_cassettes/resources/account/status.yml +45 -0
- data/spec/support/vcr_cassettes/resources/fax/cancel.yml +47 -0
- data/spec/support/vcr_cassettes/resources/fax/create.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/create_for_cancel.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/create_for_delete.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/create_for_delete_file.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/create_for_download_file.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/create_for_get.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/create_for_reference.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/create_for_resend.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/delete.yml +45 -0
- data/spec/support/vcr_cassettes/resources/fax/delete_file.yml +45 -0
- data/spec/support/vcr_cassettes/resources/fax/file.yml +50 -0
- data/spec/support/vcr_cassettes/resources/fax/get.yml +45 -0
- data/spec/support/vcr_cassettes/resources/fax/list.yml +51 -0
- data/spec/support/vcr_cassettes/resources/fax/reference.yml +45 -0
- data/spec/support/vcr_cassettes/resources/fax/resend.yml +47 -0
- data/spec/support/vcr_cassettes/resources/fax/test_receive.yml +51 -0
- data/spec/support/vcr_cassettes/resources/phax_code/create.yml +47 -0
- data/spec/support/vcr_cassettes/resources/phax_code/create_png.yml +52 -0
- data/spec/support/vcr_cassettes/resources/phax_code/get.yml +45 -0
- data/spec/support/vcr_cassettes/resources/phax_code/get_id.yml +46 -0
- data/spec/support/vcr_cassettes/resources/phax_code/get_id_png.yml +50 -0
- data/spec/support/vcr_cassettes/resources/phax_code/get_png.yml +50 -0
- data/spec/support/vcr_cassettes/resources/phone_number/create.yml +48 -0
- data/spec/support/vcr_cassettes/resources/phone_number/get.yml +46 -0
- data/spec/support/vcr_cassettes/resources/phone_number/list.yml +60 -0
- data/spec/support/vcr_cassettes/resources/phone_number/release.yml +45 -0
- data/spec/support/vcr_cassettes/resources/public/area_codes/list.yml +79 -0
- data/spec/support/vcr_cassettes/resources/public/country/list.yml +55 -0
- metadata +103 -73
- 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 -53
- data/test/test_phaxio.rb +0 -72
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Phaxio
|
|
2
|
+
module Resources
|
|
3
|
+
# Provides utilities for working with callbacks.
|
|
4
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/send_callback
|
|
5
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/receive_callback
|
|
6
|
+
class Callback
|
|
7
|
+
DIGEST = OpenSSL::Digest.new('sha1')
|
|
8
|
+
private_constant :DIGEST
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
# Determines whether or not the passed signature is valid for the given
|
|
12
|
+
# url, params, and files.
|
|
13
|
+
# @param signature [String]
|
|
14
|
+
# The signature received from Phaxio.
|
|
15
|
+
# @param url [String]
|
|
16
|
+
# The callback URL used in this request.
|
|
17
|
+
# @param params [Hash]
|
|
18
|
+
# The parameters received with the callback, excluding files.
|
|
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)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
module Phaxio
|
|
2
|
+
module Resources
|
|
3
|
+
# Provides functionality for viewing and managing faxes.
|
|
4
|
+
class Fax < Resource
|
|
5
|
+
FAXES_PATH = 'faxes'.freeze
|
|
6
|
+
private_constant :FAXES_PATH
|
|
7
|
+
|
|
8
|
+
# @return [Integer] the ID associated with this fax.
|
|
9
|
+
# @!attribute id
|
|
10
|
+
|
|
11
|
+
# @return ["sent" | "received"] the direction of the fax.
|
|
12
|
+
# @!attribute direction
|
|
13
|
+
|
|
14
|
+
# @return [Integer] the number of pages in the fax.
|
|
15
|
+
# @!attribute num_pages
|
|
16
|
+
|
|
17
|
+
# @return [Integer] the cost of the fax in cents.
|
|
18
|
+
# @!attribute cost
|
|
19
|
+
|
|
20
|
+
# @return [String] the status of the fax.
|
|
21
|
+
# @!attribute status
|
|
22
|
+
|
|
23
|
+
# @return [true | false]
|
|
24
|
+
# an indication of whether or not this is a test fax.
|
|
25
|
+
# @!attribute is_test
|
|
26
|
+
|
|
27
|
+
# @return [String]
|
|
28
|
+
# for sent faxes only, the number set as the Caller ID when sending the
|
|
29
|
+
# fax.
|
|
30
|
+
# @!attribute caller_id
|
|
31
|
+
|
|
32
|
+
# @return [String]
|
|
33
|
+
# for received faxes only, the sender's E.164 phone number.
|
|
34
|
+
# @!attribute from_number
|
|
35
|
+
|
|
36
|
+
# @return [String]
|
|
37
|
+
# for received faxes only, the Phaxio phone number that was used to
|
|
38
|
+
# receive the call.
|
|
39
|
+
# @!attribute to_number
|
|
40
|
+
|
|
41
|
+
# @return [String]
|
|
42
|
+
# one of the Phaxio error types. Will give you a general idea of what
|
|
43
|
+
# went wrong for a failed fax.
|
|
44
|
+
# @!attribute error_type
|
|
45
|
+
|
|
46
|
+
# @return [String]
|
|
47
|
+
# a more detailed description of what went wrong for a failed fax.
|
|
48
|
+
# @!attribute error_message
|
|
49
|
+
|
|
50
|
+
# @return [Integer]
|
|
51
|
+
# a numeric error code that corresponds to the error message, if any.
|
|
52
|
+
# @!attribute error_id
|
|
53
|
+
|
|
54
|
+
# @return [Hash]
|
|
55
|
+
# a hash of tag name and value pairs. If a fax was sent with tag
|
|
56
|
+
# metadata, it will appear here.
|
|
57
|
+
# @!attribute tags
|
|
58
|
+
has_normal_attributes %w[
|
|
59
|
+
id direction num_pages cost status is_test caller_id from_number
|
|
60
|
+
to_number error_type error_message error_id tags
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
# @return [Time]
|
|
64
|
+
# the time the fax was created.
|
|
65
|
+
# @!attribute created_at
|
|
66
|
+
|
|
67
|
+
# @return [Time]
|
|
68
|
+
# the time the fax was completed.
|
|
69
|
+
# @!attribute completed_at
|
|
70
|
+
|
|
71
|
+
has_time_attributes %w[created_at completed_at]
|
|
72
|
+
|
|
73
|
+
# @return [Phaxio::Resource::Collection<Phaxio::Resources::FaxRecipient>]
|
|
74
|
+
# a collection of this fax's recipients.
|
|
75
|
+
# @!attribute recipients
|
|
76
|
+
|
|
77
|
+
has_collection_attributes({recipients: FaxRecipient})
|
|
78
|
+
|
|
79
|
+
# A reference to a fax. This is returned by certain actions which don't
|
|
80
|
+
# return the full fax.
|
|
81
|
+
class Reference
|
|
82
|
+
# @return [Integer]
|
|
83
|
+
# The ID of the fax being referenced.
|
|
84
|
+
attr_accessor :id
|
|
85
|
+
|
|
86
|
+
# Gets the referenced fax.
|
|
87
|
+
# @return [Phaxio::Resource::Fax]
|
|
88
|
+
# The referenced Fax.
|
|
89
|
+
def get
|
|
90
|
+
Fax.get self
|
|
91
|
+
end
|
|
92
|
+
alias :retrieve :get
|
|
93
|
+
alias :find :get
|
|
94
|
+
|
|
95
|
+
def to_i
|
|
96
|
+
id
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
def initialize id
|
|
102
|
+
self.id = id
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
class << self
|
|
107
|
+
# @macro paging
|
|
108
|
+
# List faxes in date range.
|
|
109
|
+
# @param params [Hash]
|
|
110
|
+
# Any parameters to send to Phaxio.
|
|
111
|
+
# - *direction* [String] - Either "sent" or "received". Limits results
|
|
112
|
+
# to faxes with the specified direction.
|
|
113
|
+
# - *status* [String] - Limits results to faxes with the specified
|
|
114
|
+
# status.
|
|
115
|
+
# - *phone_number* [String] - A phone number in E.164 format that you
|
|
116
|
+
# want to use to filter results. The phone number must be an exact
|
|
117
|
+
# match, not a number fragment.
|
|
118
|
+
# - *tag* [Hash<String: String>] - A tag name and value that you want
|
|
119
|
+
# to use to filter results.
|
|
120
|
+
# @return [Phaxio::Resource::Collection<Phaxio::Resources::Fax>]
|
|
121
|
+
# The collection of faxes matching your request.
|
|
122
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
123
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/list_faxes
|
|
124
|
+
def list params = {}
|
|
125
|
+
response = Client.request :get, faxes_endpoint, params
|
|
126
|
+
response_collection response
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Create and send a fax.
|
|
130
|
+
# @param params [Hash]
|
|
131
|
+
# Any parameters to send to Phaxio. At least one *to* number is
|
|
132
|
+
# required, as well as at least one *file* or *content_url*.
|
|
133
|
+
# - *to* [String | Array<String>] - One or more phone numbers in E.164
|
|
134
|
+
# format where this fax should be sent.
|
|
135
|
+
# - *file* [File | Array<File>] - The fax file(s) to be sent.
|
|
136
|
+
# - *content_url* [String, Array<String>] - URL(s) to be rendered and
|
|
137
|
+
# sent as the fax content. If the *file* param is included as well,
|
|
138
|
+
# URL content will come first in the transmitted files.
|
|
139
|
+
# - *header_text* [String] - Text that will be displayed at the top of
|
|
140
|
+
# each page of the fax. 50-character maximum. Defaults to "-".
|
|
141
|
+
# - *batch_delay* [Integer] - Enabled batching and specifies the
|
|
142
|
+
# amount of time, in seconds, before the batch is fired. Max is 3600
|
|
143
|
+
# (one hour).
|
|
144
|
+
# - *batch_collision_avoidance* [true | false] - When *batch_delay* is
|
|
145
|
+
# set, the fax will be blocked until the receiving machine is no
|
|
146
|
+
# longer busy.
|
|
147
|
+
# - *callback_url* [String] - You can specify a callback URL that will
|
|
148
|
+
# override one set globally in your account.
|
|
149
|
+
# - *cancel_timeout* [Integer] - Number of minutes after which the fax
|
|
150
|
+
# will be canceled if it hasn't yet completed. Must be between 3 and
|
|
151
|
+
# \60. Additionally, for faxes with *batch_delay* set, it must be at
|
|
152
|
+
# least 3 minutes after the *batch_delay*. If not, it will be
|
|
153
|
+
# automatically extended when batching.
|
|
154
|
+
# - *tag* [Hash<String: Object>] - A tag that contains metadata
|
|
155
|
+
# relevant to your application. For example, you may wish to tag a
|
|
156
|
+
# fax with an order id in your application. You could pass Phaxio
|
|
157
|
+
# the following parameter: +tag: {order_id: 1234}+. You may specify
|
|
158
|
+
# up to 10 tags.
|
|
159
|
+
# @return [Phaxio::Resources::Fax]
|
|
160
|
+
# The created fax.
|
|
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
|
|
164
|
+
def create params = {}
|
|
165
|
+
response = Client.request :post, faxes_endpoint, params
|
|
166
|
+
response_reference response
|
|
167
|
+
end
|
|
168
|
+
alias :send :create
|
|
169
|
+
|
|
170
|
+
# Get fax info.
|
|
171
|
+
# @param id [Integer]
|
|
172
|
+
# The ID of the fax to retrieve information about.
|
|
173
|
+
# @param params [Hash]
|
|
174
|
+
# A hash of parameters to send to Phaxio. This action takes no unique parameters.
|
|
175
|
+
# @return [Phaxio::Resource::Fax] The requested fax.
|
|
176
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
177
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/get_fax
|
|
178
|
+
def get id, params = {}
|
|
179
|
+
response = Client.request :get, fax_endpoint(id.to_i), params
|
|
180
|
+
response_record response
|
|
181
|
+
end
|
|
182
|
+
alias :retrieve :get
|
|
183
|
+
alias :find :get
|
|
184
|
+
|
|
185
|
+
# Cancel a fax.
|
|
186
|
+
# @param id [Integer]
|
|
187
|
+
# The ID of the fax to cancel.
|
|
188
|
+
# @param params [Hash]
|
|
189
|
+
# A hash of parameters to send to Phaxio. This action takes no unique
|
|
190
|
+
# parameters.
|
|
191
|
+
# @return [Phaxio::Resources::Fax::Reference]
|
|
192
|
+
# A reference to the canceled fax.
|
|
193
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
194
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/cancel
|
|
195
|
+
def cancel id, params = {}
|
|
196
|
+
response = Client.request :post, cancel_fax_endpoint(id), params
|
|
197
|
+
response_reference response
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Resend a fax.
|
|
201
|
+
# @param id [Integer]
|
|
202
|
+
# The ID of the fax to resend.
|
|
203
|
+
# @param params [Hash]
|
|
204
|
+
# A hash of parameters to send to Phaxio.
|
|
205
|
+
# - *callback_url* [String] - This parameter may be used to set a
|
|
206
|
+
# different callback URL for the new fax.
|
|
207
|
+
# @return [Phaxio::Resources::Fax::Reference]
|
|
208
|
+
# A reference to the resent fax.
|
|
209
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
210
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/resend
|
|
211
|
+
def resend id, params = {}
|
|
212
|
+
response = Client.request :post, resend_fax_endpoint(id), params
|
|
213
|
+
response_reference response
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# Delete a fax. May only be used with test API credentials.
|
|
217
|
+
# @param id [Integer]
|
|
218
|
+
# The ID of the fax to delete.
|
|
219
|
+
# @param params [Hash]
|
|
220
|
+
# A hash of parameters to send to Phaxio. This action takes no unique
|
|
221
|
+
# parameters.
|
|
222
|
+
# @return [true]
|
|
223
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
224
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/delete_fax
|
|
225
|
+
def delete id, params = {}
|
|
226
|
+
Client.request :delete, fax_endpoint(id), params
|
|
227
|
+
true
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Delete fax files.
|
|
231
|
+
# @param id [Integer]
|
|
232
|
+
# The ID of the fax for which you want to delete files.
|
|
233
|
+
# @param params [Hash]
|
|
234
|
+
# A hash of parameters to send to Phaxio. This action takes no unique
|
|
235
|
+
# parameters.
|
|
236
|
+
# @return [true]
|
|
237
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
238
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/delete_fax_file
|
|
239
|
+
def delete_file id, params = {}
|
|
240
|
+
Client.request :delete, fax_file_endpoint(id), params
|
|
241
|
+
true
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# Get fax content file or thumbnail.
|
|
245
|
+
# @param id [Integer]
|
|
246
|
+
# The ID of the fax for which you want to get a file.
|
|
247
|
+
# @param params [Hash]
|
|
248
|
+
# A hash of parameters to send to Phaxio.
|
|
249
|
+
# - *thumbnail* ["s" | "l"] - If set to +"s"+ (small) or +"l"+
|
|
250
|
+
# (large), a thumbnail of the requested size will be returned.
|
|
251
|
+
# If unset, returns a PDF of the fax image.
|
|
252
|
+
# @return [File]
|
|
253
|
+
# The requested fax file.
|
|
254
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
255
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/get_fax_file
|
|
256
|
+
def file id, params = {}
|
|
257
|
+
Client.request :get, fax_file_endpoint(id), params
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# Test receiving a fax. May only be used with test API credentials.
|
|
261
|
+
# @param params [Hash]
|
|
262
|
+
# A hash of parameters to send to Phaxio.
|
|
263
|
+
# - *file* [File] - A PDF file to simulate receiving.
|
|
264
|
+
# - *from_number* [String] - The phone number of the simulated sender
|
|
265
|
+
# in E.164 format. Default is the public Phaxio phone number.
|
|
266
|
+
# - *to_number* [String] - The phone number, in E.164 format, that is
|
|
267
|
+
# receiving the fax. Specifically, a Phaxio phone number in your
|
|
268
|
+
# account that is "receiving" the fax, or the public Phaxio phone
|
|
269
|
+
# number. Default is the public Phaxio phone number.
|
|
270
|
+
# @return [true]
|
|
271
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
272
|
+
# @see https://www.phaxio.com/docs/api/v2/faxes/test_receive
|
|
273
|
+
def test_receive params = {}
|
|
274
|
+
Client.request :post, faxes_endpoint, test_receive_params(params)
|
|
275
|
+
true
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
private
|
|
279
|
+
|
|
280
|
+
def response_reference response
|
|
281
|
+
Reference.new response['id']
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def faxes_endpoint
|
|
285
|
+
FAXES_PATH
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def fax_endpoint id
|
|
289
|
+
"#{FAXES_PATH}/#{id}"
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def fax_file_endpoint id
|
|
293
|
+
"#{fax_endpoint(id)}/file"
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def cancel_fax_endpoint id
|
|
297
|
+
"#{fax_endpoint(id)}/cancel"
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def resend_fax_endpoint id
|
|
301
|
+
"#{fax_endpoint(id)}/resend"
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
def test_receive_params params
|
|
305
|
+
{direction: 'received'}.merge(params)
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Phaxio
|
|
2
|
+
module Resources
|
|
3
|
+
class FaxRecipient < Resource
|
|
4
|
+
# @return [String] The phone number of the recipient in E.164 format.
|
|
5
|
+
# @!attribute phone_number
|
|
6
|
+
|
|
7
|
+
# @return [String] The status of the recipient.
|
|
8
|
+
# @!attribute status
|
|
9
|
+
|
|
10
|
+
# @return [Integer] The number of retries for this recipient.
|
|
11
|
+
# @!attribute retry_count
|
|
12
|
+
|
|
13
|
+
# @return [Integer] The bitrate in bits/second that the fax was transmitted at.
|
|
14
|
+
# @!attribute bitrate
|
|
15
|
+
|
|
16
|
+
# @return [Integer]
|
|
17
|
+
# The horizontal resolution that the fax was transmitted at in pixels per meter.
|
|
18
|
+
# @!attribute resolution
|
|
19
|
+
|
|
20
|
+
# @return [String]
|
|
21
|
+
# One of the Phaxio Error types. Will give you a general idea of what went wrong for this
|
|
22
|
+
# recipient.
|
|
23
|
+
# @!attribute error_type
|
|
24
|
+
|
|
25
|
+
# @return [String] A more detailed description of what went wrong for this receipient.
|
|
26
|
+
# @!attribute error_message
|
|
27
|
+
|
|
28
|
+
# @return [Integer] A numeric error code that corresponds to the error message, if any.
|
|
29
|
+
# @!attribute error_id
|
|
30
|
+
|
|
31
|
+
has_normal_attributes %w[
|
|
32
|
+
phone_number status retry_count bitrate resolution error_type error_message error_id
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
# @return [Time] The time the job was completed for this recipient.
|
|
36
|
+
# @!attribute completed_at
|
|
37
|
+
|
|
38
|
+
has_time_attributes %w[completed_at]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module Phaxio
|
|
2
|
+
module Resources
|
|
3
|
+
# Provides functionality for viewing and managing PhaxCodes.
|
|
4
|
+
class PhaxCode < Resource
|
|
5
|
+
PHAX_CODES_PATH = 'phax_codes'.freeze
|
|
6
|
+
DEFAULT_PHAX_CODE_PATH = 'phax_code'.freeze
|
|
7
|
+
private_constant :PHAX_CODES_PATH, :DEFAULT_PHAX_CODE_PATH
|
|
8
|
+
|
|
9
|
+
# @return [String] The identifier for the PhaxCode.
|
|
10
|
+
# @!attribute identifier
|
|
11
|
+
|
|
12
|
+
# @return [String] The metadata associated with the PhaxCode.
|
|
13
|
+
# @!attribute metadata
|
|
14
|
+
|
|
15
|
+
has_normal_attributes %w[identifier metadata]
|
|
16
|
+
|
|
17
|
+
# @return [Time] The time that the PhaxCode was created.
|
|
18
|
+
# @!attribute created_at
|
|
19
|
+
|
|
20
|
+
has_time_attributes %w[created_at]
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
# Create a PhaxCode.
|
|
24
|
+
# @param params [Hash]
|
|
25
|
+
# A hash of parameters to send to Phaxio.
|
|
26
|
+
# - *metadata* [String] - Metadata to be associated with the PhaxCode.
|
|
27
|
+
# - *type* [String] - If set to "png", this method will return a PNG
|
|
28
|
+
# file instead of a PhaxCode object.
|
|
29
|
+
# @return [Phaxio::Resources::PhaxCode | File] The created PhaxCode
|
|
30
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
31
|
+
# @see https://www.phaxio.com/docs/api/v2/phaxcodes/create_phax_code
|
|
32
|
+
def create params = {}
|
|
33
|
+
endpoint = case (params[:type] || params['type']).to_s
|
|
34
|
+
when 'png' then phax_codes_endpoint_png
|
|
35
|
+
else phax_codes_endpoint
|
|
36
|
+
end
|
|
37
|
+
result = Client.request :post, endpoint, params
|
|
38
|
+
return result if result.is_a? File
|
|
39
|
+
response_record result
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Retrieve a PhaxCode.
|
|
43
|
+
# @param params [Hash]
|
|
44
|
+
# A hash of parameters to send to Phaxio.
|
|
45
|
+
# - *identifier* [String] - The identifier for the PhaxCode you want to get. If blank, the
|
|
46
|
+
# default PhaxCode will be returned.
|
|
47
|
+
# - *type* [String] - If set to "png", this method will return a PNG file instead of a
|
|
48
|
+
# PhaxCode object.
|
|
49
|
+
# @return [Phaxio::Resources::PhaxCode | File]
|
|
50
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
51
|
+
# @see https://www.phaxio.com/docs/api/v2/phaxcodes/retrieve_phax_code
|
|
52
|
+
def get params = {}
|
|
53
|
+
identifier = params[:identifier] || params['identifier']
|
|
54
|
+
endpoint = case (identifier)
|
|
55
|
+
when nil then default_phax_code_path
|
|
56
|
+
else phax_code_endpoint(identifier)
|
|
57
|
+
end
|
|
58
|
+
endpoint = case (params[:type] || params['type']).to_s
|
|
59
|
+
when 'png' then "#{endpoint}.png"
|
|
60
|
+
else endpoint
|
|
61
|
+
end
|
|
62
|
+
result = Client.request :get, endpoint, {}
|
|
63
|
+
return result if result.is_a? File
|
|
64
|
+
response_record result
|
|
65
|
+
end
|
|
66
|
+
alias :find :get
|
|
67
|
+
alias :retrieve :get
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def phax_codes_endpoint
|
|
72
|
+
PHAX_CODES_PATH
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def phax_codes_endpoint_png
|
|
76
|
+
"#{phax_codes_endpoint}.png"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def phax_code_endpoint(identifier)
|
|
80
|
+
"#{phax_codes_endpoint}/#{identifier}"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def default_phax_code_path
|
|
84
|
+
DEFAULT_PHAX_CODE_PATH
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|