Skip to content

Commit da2f567

Browse files
authored
Merge pull request #40 from phaxio/port-orders-api
Port orders api
2 parents 22048ea + e71df30 commit da2f567

8 files changed

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

0 commit comments

Comments
 (0)