Skip to content

Commit 43dcb9a

Browse files
committed
Add ATA actions
FAX-1989
1 parent eafb873 commit 43dcb9a

17 files changed

Lines changed: 1190 additions & 24 deletions

File tree

lib/phaxio/resources/ata.rb

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,37 @@ class Ata < Resource
2020
# @return [String] The domain for the ATA.
2121
# @!attribute domain
2222

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+
2329
# @return [String] The mac address for the ATA.
2430
# @!attribute mac_address
2531

32+
# @return [String] The name of the group which the ATA belongs to.
33+
# @!attribute group
34+
2635
# @return [String] The username for the ATA.
27-
# @!attribute uername
36+
# @!attribute username
2837

2938
# @return [String] The password for the ATA.
3039
# @!attribute password
3140

3241
has_normal_attributes %w[
33-
id name description user_phone_number domain username password mac_address
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
3454
]
3555

3656
# A reference to an ATA. This is returned by certain actions which don't
@@ -44,28 +64,48 @@ def to_i
4464
id
4565
end
4666

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+
4775
private
4876

4977
def initialize id
5078
self.id = id
5179
end
5280
end
5381

54-
# A reference to a phone number, returned by ATA phone number management
55-
# actions.
56-
class PhoneNumberReference
57-
# @return [String]
58-
# The phone number.
59-
attr_accessor :phone_number
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'
6091

61-
def to_s
62-
phone_number
92+
def initialize data
93+
@urls = data
6394
end
6495

65-
private
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
66105

67-
def initialize phone_number
68-
self.phone_number = phone_number
106+
# @return [String] The Netgen provisioning url.
107+
def netgen
108+
self.urls.fetch(NETGEN)
69109
end
70110
end
71111

@@ -103,7 +143,9 @@ def create params = {}
103143
# @param id [Integer]
104144
# The ID of the ATA to retrieve information about.
105145
# @param params [Hash]
106-
# Any parameters to send to Phaxio. This action takes no unique parameters.
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.
107149
# @return [Phaxio::Resources::Ata]
108150
# The requested ATA.
109151
# @raise [Phaxio::Error::PhaxioError]
@@ -148,7 +190,7 @@ def regenerate_credentials id, params = {}
148190

149191
# Delete an ATA
150192
# @param id [Integer]
151-
# The Id of the ATA to delete.
193+
# The ID of the ATA to delete.
152194
# @param params [Hash]
153195
# Any parameters to send to Phaxio. This action takes no unique parameters.
154196
# @return [Phaxio::Resources::Ata::Reference]
@@ -167,7 +209,7 @@ def delete id, params = {}
167209
# The phone number to add to the ATA.
168210
# @param params [Hash]
169211
# Any parameters to send to Phaxio. This action takes no unique parameters.
170-
# @return [Phaxio::Resources::Ata::PhoneNumberReference]
212+
# @return [Phaxio::Resources::PhoneNumber::Reference]
171213
# A reference to the added phone number.
172214
# @raise [Phaxio::Error::PhaxioError]
173215
# @see https://www.phaxio.com/docs/api/v2.1/atas/add_phone_number
@@ -183,7 +225,7 @@ def add_phone_number id, phone_number, params = {}
183225
# The phone number you want to remove.
184226
# @param params [Hash]
185227
# Any parameters to send to Phaxio. This action takes no unique parameters.
186-
# @return [Phaxio::Resources::Ata::PhoneNumberReference]
228+
# @return [Phaxio::Resources::PhoneNumber::Reference]
187229
# A reference to the removed phone number.
188230
# @raise [Phaxio::Error::PhaxioError]
189231
# @see https://www.phaxio.com/docs/api/v2.1/atas/remove_phone_number
@@ -192,14 +234,30 @@ def remove_phone_number id, phone_number, params = {}
192234
response_phone_number_reference response
193235
end
194236

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+
195249
private
196250

197251
def response_reference response
198252
Reference.new Integer(response['id'])
199253
end
200254

201255
def response_phone_number_reference response
202-
PhoneNumberReference.new(response['phone_number'])
256+
PhoneNumber::Reference.new(response['phone_number'])
257+
end
258+
259+
def response_provisioning_urls response
260+
ProvisioningURLs.new(response)
203261
end
204262

205263
def atas_endpoint
@@ -217,6 +275,10 @@ def regenerate_credentials_endpoint id
217275
def phone_number_endpoint id, phone_number
218276
"#{ata_endpoint(id)}/phone_numbers/#{phone_number}"
219277
end
278+
279+
def provisioning_urls_endpoint
280+
"#{atas_endpoint}/provisioning_urls"
281+
end
220282
end
221283
end
222284
end

lib/phaxio/resources/fax.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Reference
8484
attr_accessor :id
8585

8686
# Gets the referenced fax.
87-
# @return [Phaxio::Resource::Fax]
87+
# @return [Phaxio::Resources::Fax]
8888
# The referenced Fax.
8989
def get
9090
Fax.get self

lib/phaxio/resources/phone_number.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ class PhoneNumber < Resource
3333

3434
has_time_attributes %w(provisioned_at last_billed_at)
3535

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+
3662
private
3763

3864
class << self
@@ -60,7 +86,7 @@ def create params = {}
6086
# @raise [Phaxio::Error::PhaxioError]
6187
# @see https://www.phaxio.com/docs/api/v2.1/phone_numbers/get_number
6288
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
6490
response_record response
6591
end
6692
alias :find :get

0 commit comments

Comments
 (0)