Skip to content

Commit ecd8a4d

Browse files
jtnegrottoAndrei Motinga
authored andcommitted
Implement port orders API
1 parent 669a967 commit ecd8a4d

8 files changed

Lines changed: 420 additions & 1 deletion

File tree

lib/phaxio.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
require file
1818
end
1919

20-
%w[fax_recipient fax account callback phax_code phone_number public ata].each do |filename|
20+
%w[
21+
fax_recipient fax account callback phax_code phone_number public ata
22+
port_number_note port_number port_order
23+
].each do |filename|
2124
require File.expand_path(File.join('..', 'phaxio', 'resources', filename), __FILE__)
2225
end
2326

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/phaxio/resources/port_order.rb

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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 name associated with the account.
18+
# @!attribute name_on_account
19+
20+
# @return [String] the name of the business.
21+
# @!attribute name_of_business
22+
23+
# @return [String] the provider name.
24+
# @!attribute provider_name
25+
26+
# @return [String] the E.164 billing number.
27+
# @!attribute billing_number
28+
29+
# @return [String] the first billing address line.
30+
# @!attribute billing_address1
31+
32+
# @return [String] the second billing address line.
33+
# @!attribute billing_address2
34+
35+
# @return [String] the billing address city.
36+
# @!attribute billing_city
37+
38+
# @return [String] the billing address state.
39+
# @!attribute billing_state
40+
41+
# @return [String] the billing address zip.
42+
# @!attribute billing_zip
43+
44+
# @return [String] the electronic signature used to sign the order.
45+
# @!attribute esig
46+
47+
# @return [true | false]
48+
# whether or not a bill will be provided. (only present on new orders)
49+
# @!attribute has_bill
50+
51+
# @return [true | false]
52+
# whether or not the legal agreement is accepted. (only present on new orders)
53+
# @!attribute legal_agreement
54+
55+
has_normal_attributes %w[
56+
id contact_number name_on_account name_of_business provider_name
57+
billing_number billing_address1 billing_address2
58+
billing_city billing_state billing_zip esig legal_agreement
59+
]
60+
61+
# @return [Time] the time the order was created.
62+
# @!attribute created_at
63+
64+
# @return [Time] the time the order was updated.
65+
# @!attribute updated_at
66+
67+
# @return [Time] the time the bill for the order was received.
68+
# @!attribute bill_received_at
69+
70+
# @return [Time] the time the order was requested for.
71+
# @!attribute requested_for
72+
73+
# @return [Time] the time the order was completed.
74+
# @!attribute completed_at
75+
76+
has_time_attributes %w[
77+
created_at updated_at bill_received_at requested_for completed_at
78+
]
79+
80+
# @return [Phaxio::Resource::Collection<Phaxio::Resources::PortNumber>]
81+
# a collection of port numbers associated with the order
82+
# @!attribute port_numbers
83+
84+
has_collection_attributes({port_numbers: PortNumber})
85+
86+
class << self
87+
# @macro paging
88+
# List port orders in date range.
89+
# @param params [Hash]
90+
# Any parameters to send to Phaxio.
91+
# - *created_before* [String] - RFC 3339 timestamp representing the end of the range.
92+
# - *created_after* [String] - RFC 3339 timestamp representing the beginning of the range.
93+
# @return [Phaxio::Resource::Collection<Phaxio::Resources::PortOrder>]
94+
# The collection of port orders matching your request.
95+
# @raise [Phaxio::Error::PhaxioError
96+
# @see https://www.phaxio.com/docs/api/v2/port_orders/list_port_orders
97+
def list params = {}
98+
response = Client.request :get, port_orders_endpoint, params
99+
response_collection response
100+
end
101+
102+
# Create a port order.
103+
# @param params [Hash]
104+
# Any parameters to send to Phaxio.
105+
# - *port_numbers* [Array<String>] - Numbers to port.
106+
# - *contact_number* [String] - Number to contact about the port.
107+
# - *name_on_account* [String] - Name on the account for the port.
108+
# - *name_of_business* [String] - Name of business associated with the port.
109+
# - *provider_name* [String] - Name of provider for the port.
110+
# - *esig* [String] - Electronic signature used to sign the order.
111+
# - *legal_agreement* [true | false] - Indicates acceptance of the legal agreement.
112+
# - *has_bill* [true | false] - Indicates whether or not a bill will be provided. If true, billing number
113+
# and address fields are not needed.
114+
# - *billing_number* [String] - Billing number.
115+
# - *billing_address1* [String] - Billing address line 1
116+
# - *billing_address2* [String] - Billing address line 2
117+
# - *billing_city* [String] - Billing address city.
118+
# - *billing_state* [String] - Billing address state.
119+
# - *billing_zip* [String] - Billing address zip.
120+
# @return [Phaxio::Resources::PortOrder]
121+
# @raise [Phaxio::Error::PhaxioError]
122+
# @see https://www.phaxio.com/docs/api/v2/port_orders/create_port_order
123+
def create params = {}
124+
response = Client.request :post, port_orders_endpoint, params
125+
response_record response
126+
end
127+
128+
# Get port order info.
129+
# @param id [Integer]
130+
# The ID of the order to retrieve.
131+
# @param params [Hash]
132+
# A hash of parameters to send to Phaxio. This action takes no unique parameters.
133+
# @return [Phaxio::Resource::PortOrder]
134+
# @raise [Phaxio::Error::PhaxioError]
135+
# @see https://www.phaxio.com/docs/api/v2/port_orders/get_port_order
136+
def get id, params = {}
137+
response = Client.request :get, port_order_endpoint(id.to_i), params
138+
response_record response
139+
end
140+
alias :retrieve :get
141+
alias :find :get
142+
143+
private
144+
145+
def port_orders_endpoint
146+
PORT_ORDERS_PATH
147+
end
148+
149+
def port_order_endpoint id
150+
"#{PORT_ORDERS_PATH}/#{id}"
151+
end
152+
end
153+
end
154+
end
155+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe PortNumberNote do
4+
describe 'getting a list of notes' do
5+
let(:action) { PortNumberNote.get port_number_id, params }
6+
let(:port_number_id) { 1234 }
7+
let(:params) { {} }
8+
9+
around do |example|
10+
VCR.use_cassette('resources/port_number_note/get') do
11+
example.run
12+
end
13+
end
14+
15+
it 'makes the request to phaxio' do
16+
expect_api_request :get, "port_numbers/#{id}/notes", params
17+
action
18+
end
19+
20+
it 'returns a collection of port number note objects' do
21+
result = action
22+
expect(result).to be_a(Phaxio::Resource::Collection)
23+
expect(result.first).to be_a(PortNumberNote)
24+
end
25+
end
26+
end

spec/resources/port_number_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe PortNumber do
4+
describe 'getting information about a number' do
5+
let(:action) { PortNumber.get id, params }
6+
let(:id) { 1234 }
7+
let(:params) { {} }
8+
9+
around do |example|
10+
VCR.use_cassette('resources/port_number/get') do
11+
example.run
12+
end
13+
end
14+
15+
it 'makes the request to phaxio' do
16+
expect_api_request :get, "port_numbers/#{id}", params
17+
action
18+
end
19+
20+
it 'returns a port number object' do
21+
result = action
22+
expect(result).to be_a(PortNumber)
23+
end
24+
end
25+
end

spec/resources/port_order_spec.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe PortOrder do
4+
describe 'creating an order' do
5+
let(:action) { PortOrder.create params }
6+
let(:params) {
7+
{
8+
port_numbers: ['+12251231234'],
9+
contact_number: '+12251231234',
10+
name_on_account: 'THIS IS A TEST',
11+
provider_name: 'DO NOT PORT --Julien',
12+
has_bill: true,
13+
legal_agreement: true,
14+
esig: 'NOT A VALID SIGNATURE'
15+
}
16+
}
17+
18+
around do |example|
19+
VCR.use_cassette('resources/port_order/create') do
20+
example.run
21+
end
22+
end
23+
24+
it 'makes the request to Phaxio' do
25+
expect_api_request :post, 'port_orders', params
26+
action
27+
end
28+
29+
it 'returns a port order object' do
30+
result = action
31+
expect(result).to be_a(PortOrder)
32+
end
33+
end
34+
35+
describe 'getting information about an order' do
36+
let(:action) { PortOrder.get id, params }
37+
let(:id) { 1234 }
38+
let(:params) { {} }
39+
40+
around do |example|
41+
VCR.use_cassette('resources/port_order/get') do
42+
example.run
43+
end
44+
end
45+
46+
it 'makes the request to Phaxio' do
47+
expect_api_request :get, "port_orders/#{id}", params
48+
action
49+
end
50+
51+
it 'returns a port order object' do
52+
result = action
53+
expect(result).to be_a(PortOrder)
54+
end
55+
end
56+
57+
describe 'listing port orders' do
58+
let(:action) { PortOrder.list params }
59+
let(:params) { {} }
60+
61+
around do |example|
62+
VCR.use_cassette('resources/port_order/list') do
63+
example.run
64+
end
65+
end
66+
67+
it 'makes the request to Phaxio' do
68+
expect_api_request :get, 'port_orders', params
69+
action
70+
end
71+
72+
it 'returns a collection of port order objects' do
73+
result = action
74+
expect(result).to be_a(Phaxio::Resource::Collection)
75+
expect(result.first).to be_a(PortOrder)
76+
end
77+
end
78+
end

0 commit comments

Comments
 (0)