phaxio 2.1.0.pre → 2.1.1
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 +14 -12
- data/lib/phaxio/config.rb +6 -4
- data/lib/phaxio/error.rb +1 -0
- 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/client_spec.rb +17 -0
- 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
|
@@ -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
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Phaxio
|
|
2
|
+
module Resources
|
|
3
|
+
# Provides functionality for viewing port numbers.
|
|
4
|
+
class PortNumber < Resource
|
|
5
|
+
PORT_NUMBERS_PATH = 'port_numbers'.freeze
|
|
6
|
+
private_constant :PORT_NUMBERS_PATH
|
|
7
|
+
|
|
8
|
+
# @return [Integer] the ID associated with this number.
|
|
9
|
+
# @!attribute id
|
|
10
|
+
|
|
11
|
+
# @return [String] the E.164 number.
|
|
12
|
+
# @!attribute port_number
|
|
13
|
+
|
|
14
|
+
# @return [String] the status of this number.
|
|
15
|
+
# @!attribute status
|
|
16
|
+
|
|
17
|
+
has_normal_attributes %w(id port_number status)
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
# Get port number info.
|
|
21
|
+
# @param id [Integer] The ID of the number to retrieve.
|
|
22
|
+
# @param params [Hash]
|
|
23
|
+
# A hash of parameters to send to Phaxio. This action takes no unique parameters.
|
|
24
|
+
# @return [Phaxio::Resource::PortNumber]
|
|
25
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
26
|
+
# @see https://www.phaxio.com/docs/api/v2/port_numbers/get_port_number
|
|
27
|
+
def get id, params = {}
|
|
28
|
+
response = Client.request :get, port_number_endpoint(id.to_i), params
|
|
29
|
+
response_record response
|
|
30
|
+
end
|
|
31
|
+
alias :retrieve :get
|
|
32
|
+
alias :find :get
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def port_number_endpoint id
|
|
37
|
+
"#{PORT_NUMBERS_PATH}/#{id}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Phaxio
|
|
2
|
+
module Resources
|
|
3
|
+
# Provides functionality for viewing port number notes.
|
|
4
|
+
class PortNumberNote < Resource
|
|
5
|
+
PORT_NUMBERS_PATH = 'port_numbers'.freeze
|
|
6
|
+
private_constant :PORT_NUMBERS_PATH
|
|
7
|
+
NOTES_PATH = 'notes'.freeze
|
|
8
|
+
private_constant :NOTES_PATH
|
|
9
|
+
|
|
10
|
+
# @return [Integer] the ID associated with this note.
|
|
11
|
+
# @!attribute id
|
|
12
|
+
|
|
13
|
+
# @return [String] the author of this note.
|
|
14
|
+
# @!attribute author
|
|
15
|
+
|
|
16
|
+
# @return [String] the content of the note
|
|
17
|
+
# @!attribute note
|
|
18
|
+
|
|
19
|
+
has_normal_attributes %w[id note author]
|
|
20
|
+
|
|
21
|
+
# @return [Time] the time this note was created.
|
|
22
|
+
# @!attribute created_at
|
|
23
|
+
|
|
24
|
+
# @return [Time] the time this note was updated.
|
|
25
|
+
# @!attribute updated_at
|
|
26
|
+
|
|
27
|
+
has_time_attributes %w[created_at updated_at]
|
|
28
|
+
|
|
29
|
+
class << self
|
|
30
|
+
# List notes for a port number.
|
|
31
|
+
# @param port_number_id [Integer]
|
|
32
|
+
# The ID of the port number to list notes for.
|
|
33
|
+
# @param params [Hash]
|
|
34
|
+
# Any parameters to send to Phaxio. This action takes no unique parameters.
|
|
35
|
+
# @return [Phaxio::Resource::Collection<Phaxio::Resources::PortNumberNote>]
|
|
36
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
37
|
+
# @see https://www.phaxio.com/docs/api/v2/port_number_notes/list_notes
|
|
38
|
+
def list port_number_id, params = {}
|
|
39
|
+
response = Client.request :get, port_number_notes_endpoint(port_number_id.to_i), params
|
|
40
|
+
response_collection response
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def port_number_notes_endpoint port_number_id
|
|
46
|
+
"#{PORT_NUMBERS_PATH}/#{port_number_id}/#{NOTES_PATH}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
module Phaxio
|
|
2
|
+
module Resources
|
|
3
|
+
# Provides functionality for viewing and managing port orders.
|
|
4
|
+
class PortOrder < Resource
|
|
5
|
+
PORT_ORDERS_PATH = 'port_orders'.freeze
|
|
6
|
+
private_constant :PORT_ORDERS_PATH
|
|
7
|
+
|
|
8
|
+
# @return [Integer] the ID associated with this order.
|
|
9
|
+
# @!attribute id
|
|
10
|
+
|
|
11
|
+
# @return [String] the status of this order.
|
|
12
|
+
# @!attribute status
|
|
13
|
+
|
|
14
|
+
# @return [String] the E.164 contact number.
|
|
15
|
+
# @!attribute contact_number
|
|
16
|
+
|
|
17
|
+
# @return [String] The email address for the order.
|
|
18
|
+
# @!attribute contact_email
|
|
19
|
+
|
|
20
|
+
# @return [String] The identifier for the account associated with the numbers.
|
|
21
|
+
# @!attribute account_identifier
|
|
22
|
+
|
|
23
|
+
# @return [String] Type of numbers to be ported. Either "business" or "residential".
|
|
24
|
+
# @!attribute port_type
|
|
25
|
+
|
|
26
|
+
# @return [String] The PIN or password needed to port out the numbers.
|
|
27
|
+
# @!attribute port_out_pin
|
|
28
|
+
|
|
29
|
+
# @return [String] the name associated with the account.
|
|
30
|
+
# @!attribute name_on_account
|
|
31
|
+
|
|
32
|
+
# @return [String] the name of the business.
|
|
33
|
+
# @!attribute name_of_business
|
|
34
|
+
|
|
35
|
+
# @return [String] the provider name.
|
|
36
|
+
# @!attribute provider_name
|
|
37
|
+
|
|
38
|
+
# @return [String] the E.164 billing number.
|
|
39
|
+
# @!attribute billing_number
|
|
40
|
+
|
|
41
|
+
# @return [String] the first billing address line.
|
|
42
|
+
# @!attribute billing_address1
|
|
43
|
+
|
|
44
|
+
# @return [String] the second billing address line.
|
|
45
|
+
# @!attribute billing_address2
|
|
46
|
+
|
|
47
|
+
# @return [String] the billing address city.
|
|
48
|
+
# @!attribute billing_city
|
|
49
|
+
|
|
50
|
+
# @return [String] the billing address state.
|
|
51
|
+
# @!attribute billing_state
|
|
52
|
+
|
|
53
|
+
# @return [String] the billing address zip.
|
|
54
|
+
# @!attribute billing_zip
|
|
55
|
+
|
|
56
|
+
# @return [String] the electronic signature used to sign the order.
|
|
57
|
+
# @!attribute esig
|
|
58
|
+
|
|
59
|
+
# @return [true | false]
|
|
60
|
+
# whether or not a bill will be provided. (only present on new orders)
|
|
61
|
+
# @!attribute has_bill
|
|
62
|
+
|
|
63
|
+
# @return [true | false]
|
|
64
|
+
# whether or not the legal agreement is accepted. (only present on new orders)
|
|
65
|
+
# @!attribute legal_agreement
|
|
66
|
+
|
|
67
|
+
has_normal_attributes %w[
|
|
68
|
+
id contact_number contact_email name_on_account name_of_business provider_name
|
|
69
|
+
billing_number billing_address1 billing_address2 account_identifier
|
|
70
|
+
billing_city billing_state billing_zip esig legal_agreement port_type port_out_pin
|
|
71
|
+
status
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
# @return [Time] the time the order was created.
|
|
75
|
+
# @!attribute created_at
|
|
76
|
+
|
|
77
|
+
# @return [Time] the time the order was updated.
|
|
78
|
+
# @!attribute updated_at
|
|
79
|
+
|
|
80
|
+
# @return [Time] the time the bill for the order was received.
|
|
81
|
+
# @!attribute bill_received_at
|
|
82
|
+
|
|
83
|
+
# @return [Time] the time the order was requested for.
|
|
84
|
+
# @!attribute requested_for
|
|
85
|
+
|
|
86
|
+
# @return [Time] the time the order was completed.
|
|
87
|
+
# @!attribute completed_at
|
|
88
|
+
|
|
89
|
+
has_time_attributes %w[
|
|
90
|
+
created_at updated_at bill_received_at requested_for completed_at
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
# @return [Phaxio::Resource::Collection<Phaxio::Resources::PortNumber>]
|
|
94
|
+
# a collection of port numbers associated with the order
|
|
95
|
+
# @!attribute port_numbers
|
|
96
|
+
|
|
97
|
+
has_collection_attributes({port_numbers: PortNumber})
|
|
98
|
+
|
|
99
|
+
class << self
|
|
100
|
+
# @macro paging
|
|
101
|
+
# List port orders in date range.
|
|
102
|
+
# @param params [Hash]
|
|
103
|
+
# Any parameters to send to Phaxio.
|
|
104
|
+
# - *created_before* [String] - RFC 3339 timestamp representing the end of the range.
|
|
105
|
+
# - *created_after* [String] - RFC 3339 timestamp representing the beginning of the range.
|
|
106
|
+
# @return [Phaxio::Resource::Collection<Phaxio::Resources::PortOrder>]
|
|
107
|
+
# The collection of port orders matching your request.
|
|
108
|
+
# @raise [Phaxio::Error::PhaxioError
|
|
109
|
+
# @see https://www.phaxio.com/docs/api/v2/port_orders/list_port_orders
|
|
110
|
+
def list params = {}
|
|
111
|
+
response = Client.request :get, port_orders_endpoint, params
|
|
112
|
+
response_collection response
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Create a port order.
|
|
116
|
+
# @param params [Hash]
|
|
117
|
+
# Any parameters to send to Phaxio.
|
|
118
|
+
# - *port_numbers* [Array<String>] - Numbers to port.
|
|
119
|
+
# - *contact_number* [String] - Number to contact about the port.
|
|
120
|
+
# - *contact_email* [String] - The email address for the order.
|
|
121
|
+
# - *account_identifier* [String] - The identifier for the account associated with the numbers.
|
|
122
|
+
# - *port_type* [String] - Type of numbers to be ported. Either "business" or "residential".
|
|
123
|
+
# - *port_out_pin* [String] - The PIN or password needed to port out the numbers.
|
|
124
|
+
# - *name_on_account* [String] - Name on the account for the port.
|
|
125
|
+
# - *name_of_business* [String] - Name of business associated with the port.
|
|
126
|
+
# - *provider_name* [String] - Name of provider for the port.
|
|
127
|
+
# - *esig* [String] - Electronic signature used to sign the order.
|
|
128
|
+
# - *legal_agreement* [true | false] - Indicates acceptance of the legal agreement.
|
|
129
|
+
# - *has_bill* [true | false] - Indicates whether or not a bill will be provided. If true, billing number
|
|
130
|
+
# and address fields are not needed.
|
|
131
|
+
# - *billing_number* [String] - Billing number.
|
|
132
|
+
# - *billing_address1* [String] - Billing address line 1
|
|
133
|
+
# - *billing_address2* [String] - Billing address line 2
|
|
134
|
+
# - *billing_city* [String] - Billing address city.
|
|
135
|
+
# - *billing_state* [String] - Billing address state.
|
|
136
|
+
# - *billing_zip* [String] - Billing address zip.
|
|
137
|
+
# @return [Phaxio::Resources::PortOrder]
|
|
138
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
139
|
+
# @see https://www.phaxio.com/docs/api/v2/port_orders/create_port_order
|
|
140
|
+
def create params = {}
|
|
141
|
+
response = Client.request :post, port_orders_endpoint, params
|
|
142
|
+
response_record response
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Get port order info.
|
|
146
|
+
# @param id [Integer]
|
|
147
|
+
# The ID of the order to retrieve.
|
|
148
|
+
# @param params [Hash]
|
|
149
|
+
# A hash of parameters to send to Phaxio. This action takes no unique parameters.
|
|
150
|
+
# @return [Phaxio::Resource::PortOrder]
|
|
151
|
+
# @raise [Phaxio::Error::PhaxioError]
|
|
152
|
+
# @see https://www.phaxio.com/docs/api/v2/port_orders/get_port_order
|
|
153
|
+
def get id, params = {}
|
|
154
|
+
response = Client.request :get, port_order_endpoint(id.to_i), params
|
|
155
|
+
response_record response
|
|
156
|
+
end
|
|
157
|
+
alias :retrieve :get
|
|
158
|
+
alias :find :get
|
|
159
|
+
|
|
160
|
+
private
|
|
161
|
+
|
|
162
|
+
def port_orders_endpoint
|
|
163
|
+
PORT_ORDERS_PATH
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def port_order_endpoint id
|
|
167
|
+
"#{PORT_ORDERS_PATH}/#{id}"
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
@@ -46,7 +46,7 @@ module Phaxio
|
|
|
46
46
|
# @return [Phaxio::Resource::Collection<Phaxio::Resources::AreaCode>] A collection of
|
|
47
47
|
# AreaCode objects.
|
|
48
48
|
# @raise [Phaxio::Error::PhaxioError]
|
|
49
|
-
# @see https://www.phaxio.com/docs/api/v2/public/list_area_codes
|
|
49
|
+
# @see https://www.phaxio.com/docs/api/v2.1/public/list_area_codes
|
|
50
50
|
def list params = {}
|
|
51
51
|
response = Client.request :get, available_area_codes_endpoint, params
|
|
52
52
|
AreaCode.response_collection response
|
|
@@ -36,7 +36,7 @@ module Phaxio
|
|
|
36
36
|
# @return [Phaxio::Resource::Collection<Phaxio::Resources::Country>]
|
|
37
37
|
# A collection of supported countries.
|
|
38
38
|
# @raise Phaxio::Error::PhaxioError
|
|
39
|
-
# @see https://www.phaxio.com/docs/api/v2/public/list_countries
|
|
39
|
+
# @see https://www.phaxio.com/docs/api/v2.1/public/list_countries
|
|
40
40
|
def list params = {}
|
|
41
41
|
response = Client.request :get, supported_countries_endpoint, params
|
|
42
42
|
Country.response_collection response
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Phaxio
|
|
2
|
+
module Resources
|
|
3
|
+
# Provides utilities for working with webhooks.
|
|
4
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/send_webhook
|
|
5
|
+
# @see https://www.phaxio.com/docs/api/v2.1/faxes/receive_webhooks
|
|
6
|
+
class Webhook
|
|
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 webhook URL used in this request.
|
|
17
|
+
# @param params [Hash]
|
|
18
|
+
# The parameters received with the webhook, excluding files.
|
|
19
|
+
# @param files [Array<File>]
|
|
20
|
+
# The files received with the webhook, 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
|
+
webhook_data = "#{url}#{params_string}#{files_string}"
|
|
35
|
+
OpenSSL::HMAC.hexdigest(DIGEST, webhook_token, webhook_data)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def webhook_token
|
|
39
|
+
Phaxio.webhook_token or raise(Error::PhaxioError, 'No webhook 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
|
data/lib/phaxio/version.rb
CHANGED
data/lib/phaxio.rb
CHANGED
|
@@ -17,7 +17,10 @@ Dir[File.expand_path(File.join('..', 'phaxio', 'helpers', '*.rb'), __FILE__)].ea
|
|
|
17
17
|
require file
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
%w[
|
|
20
|
+
%w[
|
|
21
|
+
fax_recipient fax account callback webhook phax_code phone_number public ata
|
|
22
|
+
port_number_note port_number port_order
|
|
23
|
+
].each do |filename|
|
|
21
24
|
require File.expand_path(File.join('..', 'phaxio', 'resources', filename), __FILE__)
|
|
22
25
|
end
|
|
23
26
|
|
|
@@ -29,11 +32,13 @@ module Phaxio
|
|
|
29
32
|
# @see Config.api_key
|
|
30
33
|
# @!attribute api_secret
|
|
31
34
|
# @see Config.api_secret
|
|
35
|
+
# @!attribute webhook_token
|
|
36
|
+
# @see Config.webhook_token
|
|
32
37
|
# @!attribute callback_token
|
|
33
|
-
# @see Config.
|
|
38
|
+
# @see Config.webhook_token
|
|
34
39
|
# @!attribute api_endpoint
|
|
35
40
|
# @see Config.api_endpoint
|
|
36
|
-
%w(api_key api_secret callback_token api_endpoint).each do |config_attribute|
|
|
41
|
+
%w(api_key api_secret webhook_token callback_token api_endpoint).each do |config_attribute|
|
|
37
42
|
# Define getters
|
|
38
43
|
define_method(config_attribute) do
|
|
39
44
|
Config.public_send config_attribute
|
|
@@ -45,5 +50,9 @@ module Phaxio
|
|
|
45
50
|
Config.public_send setter, value
|
|
46
51
|
end
|
|
47
52
|
end
|
|
53
|
+
|
|
54
|
+
# for backwards compatibility
|
|
55
|
+
alias callback_token webhook_token
|
|
56
|
+
alias callback_token= webhook_token=
|
|
48
57
|
end
|
|
49
58
|
end
|
data/spec/client_spec.rb
CHANGED
|
@@ -19,6 +19,16 @@ RSpec.describe Phaxio::Client do
|
|
|
19
19
|
)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
def test_response_503
|
|
23
|
+
instance_double(
|
|
24
|
+
Faraday::Response,
|
|
25
|
+
status: 503,
|
|
26
|
+
success?: false,
|
|
27
|
+
headers: {},
|
|
28
|
+
body: nil
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
22
32
|
describe 'making a request' do
|
|
23
33
|
it 'sends the request to Phaxio' do
|
|
24
34
|
endpoint = 'public/countries/'
|
|
@@ -118,6 +128,13 @@ RSpec.describe Phaxio::Client do
|
|
|
118
128
|
}.to raise_error(Phaxio::Error::RateLimitExceededError, '429: This is a test.')
|
|
119
129
|
end
|
|
120
130
|
|
|
131
|
+
it 'raises a service unavailable error if the response status is 503' do
|
|
132
|
+
expect(test_connection).to receive(:get) { test_response_503 }
|
|
133
|
+
expect {
|
|
134
|
+
client.request :get, 'test'
|
|
135
|
+
}.to raise_error(Phaxio::Error::ServiceUnavailableError, '503: ')
|
|
136
|
+
end
|
|
137
|
+
|
|
121
138
|
it 'raises a general error for if the response status is 5XX' do
|
|
122
139
|
expect(test_connection).to receive(:get) { test_response 500 }
|
|
123
140
|
expect {
|
data/spec/phaxio_spec.rb
CHANGED
|
@@ -13,8 +13,14 @@ RSpec.describe Phaxio do
|
|
|
13
13
|
expect(subject.api_secret).to eq('test-api-secret')
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
it 'sets the
|
|
16
|
+
it 'sets the webhook token' do
|
|
17
|
+
subject.webhook_token = 'test-webhook-token'
|
|
18
|
+
expect(subject.webhook_token).to eq('test-webhook-token')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'sets and gets the webhook token as callback_token' do
|
|
17
22
|
subject.callback_token = 'test-callback-token'
|
|
18
23
|
expect(subject.callback_token).to eq('test-callback-token')
|
|
24
|
+
expect(subject.webhook_token).to eq('test-callback-token')
|
|
19
25
|
end
|
|
20
26
|
end
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
RSpec.describe Account do
|
|
4
|
-
describe 'getting account information' do
|
|
4
|
+
describe 'getting account information', vcr: 'account/get' do
|
|
5
5
|
let(:action) { Account.get params }
|
|
6
6
|
let(:params) { {} }
|
|
7
7
|
|
|
8
|
-
around do |example|
|
|
9
|
-
VCR.use_cassette('resources/account/status') do
|
|
10
|
-
example.run
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
8
|
it 'sends the request to Phaxio' do
|
|
15
9
|
expect_api_request :get, 'account/status', params
|
|
16
10
|
action
|