telnyx 0.0.5 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/Gemfile +1 -0
  4. data/README.md +42 -3
  5. data/VERSION +1 -1
  6. data/bin/telnyx-console +2 -1
  7. data/lib/telnyx.rb +19 -1
  8. data/lib/telnyx/address.rb +12 -0
  9. data/lib/telnyx/api_operations/list.rb +1 -1
  10. data/lib/telnyx/api_operations/nested_resource.rb +17 -4
  11. data/lib/telnyx/api_resource.rb +1 -1
  12. data/lib/telnyx/billing_group.rb +12 -0
  13. data/lib/telnyx/call_control_application.rb +12 -0
  14. data/lib/telnyx/{conferences.rb → conference.rb} +2 -1
  15. data/lib/telnyx/connection.rb +9 -0
  16. data/lib/telnyx/credential_connection.rb +12 -0
  17. data/lib/telnyx/fqdn.rb +12 -0
  18. data/lib/telnyx/fqdn_connection.rb +12 -0
  19. data/lib/telnyx/ip.rb +12 -0
  20. data/lib/telnyx/ip_connection.rb +12 -0
  21. data/lib/telnyx/list_object.rb +30 -44
  22. data/lib/telnyx/number_lookup.rb +7 -0
  23. data/lib/telnyx/number_order_document.rb +11 -0
  24. data/lib/telnyx/outbound_voice_profile.rb +12 -0
  25. data/lib/telnyx/phone_number.rb +44 -0
  26. data/lib/telnyx/phone_number_regulatory_requirement.rb +9 -0
  27. data/lib/telnyx/portout.rb +12 -0
  28. data/lib/telnyx/regulatory_requirement.rb +9 -0
  29. data/lib/telnyx/sim_card.rb +24 -0
  30. data/lib/telnyx/telnyx_client.rb +1 -1
  31. data/lib/telnyx/telnyx_response.rb +11 -2
  32. data/lib/telnyx/util.rb +31 -11
  33. data/lib/telnyx/version.rb +1 -1
  34. data/lib/telnyx/wireless_detail_records_report.rb +12 -0
  35. data/telnyx.gemspec +1 -1
  36. data/test/telnyx/address_test.rb +67 -0
  37. data/test/telnyx/alphanumeric_sender_id_test.rb +4 -0
  38. data/test/telnyx/api_resource_test.rb +14 -5
  39. data/test/telnyx/billing_group_test.rb +40 -0
  40. data/test/telnyx/call_control_application_test.rb +42 -0
  41. data/test/telnyx/{conferences_test.rb → conference_test.rb} +5 -5
  42. data/test/telnyx/connection_test.rb +28 -0
  43. data/test/telnyx/credential_connection_test.rb +40 -0
  44. data/test/telnyx/errors_test.rb +4 -4
  45. data/test/telnyx/fqdn_connection_test.rb +40 -0
  46. data/test/telnyx/fqdn_test.rb +40 -0
  47. data/test/telnyx/ip_connection_test.rb +40 -0
  48. data/test/telnyx/ip_test.rb +40 -0
  49. data/test/telnyx/list_object_test.rb +48 -90
  50. data/test/telnyx/messaging_profile_test.rb +15 -4
  51. data/test/telnyx/number_lookup_test.rb +18 -0
  52. data/test/telnyx/number_order_document_test.rb +35 -0
  53. data/test/telnyx/outbound_voice_profile_test.rb +67 -0
  54. data/test/telnyx/phone_number_regulatory_requirement_test.rb +14 -0
  55. data/test/telnyx/phone_number_test.rb +157 -0
  56. data/test/telnyx/public_key_test.rb +1 -0
  57. data/test/telnyx/regulatory_requirement_test.rb +21 -0
  58. data/test/telnyx/sim_card_test.rb +44 -0
  59. data/test/telnyx/telnyx_client_test.rb +11 -10
  60. data/test/telnyx/wireless_detail_records_report_test.rb +57 -0
  61. data/test/test_helper.rb +1 -1
  62. metadata +74 -10
@@ -3,22 +3,22 @@
3
3
  require_relative "../test_helper"
4
4
 
5
5
  module Telnyx
6
- class ConferencesTest < Test::Unit::TestCase
6
+ class ConferenceTest < Test::Unit::TestCase
7
7
  setup do
8
8
  @call = create_call
9
- @conference = Conferences.create call_control_id: @call.id, name: "conference!"
9
+ @conference = Conference.create call_control_id: @call.id, name: "conference!"
10
10
  end
11
11
  should "create conference" do
12
12
  assert_requested :post, "#{Telnyx.api_base}/v2/conferences"
13
- assert_kind_of Conferences, @conference
13
+ assert_kind_of Conference, @conference
14
14
  end
15
15
 
16
16
  should "list conferences" do
17
- conferences = Conferences.list
17
+ conferences = Conference.list
18
18
 
19
19
  assert_requested :get, "#{Telnyx.api_base}/v2/conferences"
20
20
  assert_kind_of ListObject, conferences
21
- assert_kind_of Conferences, conferences.first
21
+ assert_kind_of Conference, conferences.first
22
22
  end
23
23
 
24
24
  should "have nested command instance methods" do
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class ConnectionTest < Test::Unit::TestCase
7
+ should "list connections" do
8
+ connections = Connection.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/connections"
10
+ assert_kind_of ListObject, connections
11
+ assert connections.first.is_a?(Connection) ||
12
+ connections.first.is_a?(IPConnection) ||
13
+ connections.first.is_a?(FQDNConnection) ||
14
+ connections.first.is_a?(CredentialConnection),
15
+ "Unexpected type: #{connections.first.class}"
16
+ end
17
+
18
+ should "retrieve a connection" do
19
+ connection = Connection.retrieve("id")
20
+ assert_requested :get, "#{Telnyx.api_base}/v2/connections/id"
21
+ assert connection.is_a?(Connection) ||
22
+ connection.is_a?(IPConnection) ||
23
+ connection.is_a?(FQDNConnection) ||
24
+ connection.is_a?(CredentialConnection),
25
+ "Unexpected type: #{connection.class}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class CredentialConnectionTest < Test::Unit::TestCase
7
+ should "list credential connections" do
8
+ credential_connections = CredentialConnection.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/credential_connections"
10
+ assert_kind_of ListObject, credential_connections
11
+ assert_kind_of CredentialConnection, credential_connections.first
12
+ end
13
+
14
+ should "create credential connection" do
15
+ CredentialConnection.create
16
+ assert_requested :post, "#{Telnyx.api_base}/v2/credential_connections"
17
+ end
18
+
19
+ should "retrieve credential connection" do
20
+ credential_connection = CredentialConnection.retrieve("id")
21
+ assert_requested :get, "#{Telnyx.api_base}/v2/credential_connections/id"
22
+ assert_kind_of CredentialConnection, credential_connection
23
+ end
24
+
25
+ should "delete credential connection" do
26
+ credential_connection = CredentialConnection.retrieve("id")
27
+
28
+ credential_connection.delete
29
+ assert_requested :delete, "#{Telnyx.api_base}/v2/credential_connections/id"
30
+ end
31
+
32
+ should "update credential connection" do
33
+ credential_connection = CredentialConnection.retrieve("id")
34
+
35
+ credential_connection.active = false
36
+ credential_connection.save
37
+ assert_requested :patch, "#{Telnyx.api_base}/v2/credential_connections/id"
38
+ end
39
+ end
40
+ end
@@ -7,16 +7,16 @@ module Telnyx
7
7
  context "#to_s" do
8
8
  should "convert to string" do
9
9
  e = TelnyxError.new([{ "title" => "Missing required attributes" }])
10
- assert_equal "Missing required attributes Full details: [{\"title\"=>\"Missing required attributes\"}]", e.to_s
10
+ assert_equal 'Missing required attributes Full details: [{"title"=>"Missing required attributes"}]', e.to_s
11
11
 
12
12
  e = TelnyxError.new([{ "title" => "Missing required attributes" }], http_status: 422)
13
- assert_equal "(Status 422) Missing required attributes Full details: [{\"title\"=>\"Missing required attributes\"}]", e.to_s
13
+ assert_equal '(Status 422) Missing required attributes Full details: [{"title"=>"Missing required attributes"}]', e.to_s
14
14
 
15
15
  e = TelnyxError.new([{ "title" => "Missing required attributes" }], http_status: nil, http_body: nil, json_body: nil, http_headers: { request_id: "request-id" })
16
- assert_equal "(Request request-id) Missing required attributes Full details: [{\"title\"=>\"Missing required attributes\"}]", e.to_s
16
+ assert_equal '(Request request-id) Missing required attributes Full details: [{"title"=>"Missing required attributes"}]', e.to_s
17
17
 
18
18
  e = TelnyxError.new([{ "title" => "Missing required attributes" }, { "title" => "Phone number must be in +E.164 format" }], http_status: nil, http_body: nil, json_body: nil, http_headers: { request_id: "request-id" })
19
- assert_equal "(Request request-id) Missing required attributes plus 1 other error. Full details: [{\"title\"=>\"Missing required attributes\"}, {\"title\"=>\"Phone number must be in +E.164 format\"}]", e.to_s
19
+ assert_equal '(Request request-id) Missing required attributes plus 1 other error. Full details: [{"title"=>"Missing required attributes"}, {"title"=>"Phone number must be in +E.164 format"}]', e.to_s
20
20
  end
21
21
  end
22
22
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class FQDNConnectionTest < Test::Unit::TestCase
7
+ should "list fqdn connections" do
8
+ fqdn_connections = FQDNConnection.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/fqdn_connections"
10
+ assert_kind_of ListObject, fqdn_connections
11
+ assert_kind_of FQDNConnection, fqdn_connections.first
12
+ end
13
+
14
+ should "create fqdn connection" do
15
+ FQDNConnection.create
16
+ assert_requested :post, "#{Telnyx.api_base}/v2/fqdn_connections"
17
+ end
18
+
19
+ should "retrieve fqdn connection" do
20
+ fqdn_connection = FQDNConnection.retrieve("id")
21
+ assert_requested :get, "#{Telnyx.api_base}/v2/fqdn_connections/id"
22
+ assert_kind_of FQDNConnection, fqdn_connection
23
+ end
24
+
25
+ should "delete fqdn connection" do
26
+ fqdn_connection = FQDNConnection.retrieve("id")
27
+
28
+ fqdn_connection.delete
29
+ assert_requested :delete, "#{Telnyx.api_base}/v2/fqdn_connections/id"
30
+ end
31
+
32
+ should "update fqdn connection" do
33
+ fqdn_connection = FQDNConnection.retrieve("id")
34
+
35
+ fqdn_connection.active = false
36
+ fqdn_connection.save
37
+ assert_requested :patch, "#{Telnyx.api_base}/v2/fqdn_connections/id"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class FQDNTest < Test::Unit::TestCase
7
+ should "list fqdns" do
8
+ fqdn = FQDN.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/fqdns"
10
+ assert_kind_of ListObject, fqdn
11
+ assert_kind_of FQDN, fqdn.first
12
+ end
13
+
14
+ should "create fqdn" do
15
+ FQDN.create fqdn: "example.com"
16
+ assert_requested :post, "#{Telnyx.api_base}/v2/fqdns"
17
+ end
18
+
19
+ should "retrieve fqdn" do
20
+ fqdn = FQDN.retrieve("id")
21
+ assert_requested :get, "#{Telnyx.api_base}/v2/fqdns/id"
22
+ assert_kind_of FQDN, fqdn
23
+ end
24
+
25
+ should "delete fqdn" do
26
+ fqdn = FQDN.retrieve("id")
27
+
28
+ fqdn.delete
29
+ assert_requested :delete, "#{Telnyx.api_base}/v2/fqdns/id"
30
+ end
31
+
32
+ should "update fqdn" do
33
+ fqdn = FQDN.retrieve("id")
34
+
35
+ fqdn.fqdn = "example.com"
36
+ fqdn.save
37
+ assert_requested :patch, "#{Telnyx.api_base}/v2/fqdns/id"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class IPConnectionTest < Test::Unit::TestCase
7
+ should "list ip connections" do
8
+ ip_connections = IPConnection.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/ip_connections"
10
+ assert_kind_of ListObject, ip_connections
11
+ assert_kind_of IPConnection, ip_connections.first
12
+ end
13
+
14
+ should "create ip connection" do
15
+ IPConnection.create
16
+ assert_requested :post, "#{Telnyx.api_base}/v2/ip_connections"
17
+ end
18
+
19
+ should "retrieve ip connection" do
20
+ ip_connection = IPConnection.retrieve("id")
21
+ assert_requested :get, "#{Telnyx.api_base}/v2/ip_connections/id"
22
+ assert_kind_of IPConnection, ip_connection
23
+ end
24
+
25
+ should "delete ip connection" do
26
+ ip_connection = IPConnection.retrieve("id")
27
+
28
+ ip_connection.delete
29
+ assert_requested :delete, "#{Telnyx.api_base}/v2/ip_connections/id"
30
+ end
31
+
32
+ should "update ip connection" do
33
+ ip_connection = IPConnection.retrieve("id")
34
+
35
+ ip_connection.active = false
36
+ ip_connection.save
37
+ assert_requested :patch, "#{Telnyx.api_base}/v2/ip_connections/id"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class IPTest < Test::Unit::TestCase
7
+ should "list ips" do
8
+ ip = IP.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/ips"
10
+ assert_kind_of ListObject, ip
11
+ assert_kind_of IP, ip.first
12
+ end
13
+
14
+ should "create ip" do
15
+ IP.create ip_address: "0.0.0.0"
16
+ assert_requested :post, "#{Telnyx.api_base}/v2/ips"
17
+ end
18
+
19
+ should "retrieve ip" do
20
+ ip = IP.retrieve("id")
21
+ assert_requested :get, "#{Telnyx.api_base}/v2/ips/id"
22
+ assert_kind_of IP, ip
23
+ end
24
+
25
+ should "delete ip" do
26
+ ip = IP.retrieve("id")
27
+
28
+ ip.delete
29
+ assert_requested :delete, "#{Telnyx.api_base}/v2/ips/id"
30
+ end
31
+
32
+ should "update ip" do
33
+ ip = IP.retrieve("id")
34
+
35
+ ip.ip_address = "0.0.0.0"
36
+ ip.save
37
+ assert_requested :patch, "#{Telnyx.api_base}/v2/ips/id"
38
+ end
39
+ end
40
+ end
@@ -78,59 +78,6 @@ module Telnyx
78
78
  assert_equal expected, actual
79
79
  end
80
80
 
81
- should "provide #auto_paging_each_by_token" do
82
- arr = [
83
- { id: 1 },
84
- { id: 2 },
85
- { id: 3 },
86
- ]
87
- expected = Util.convert_to_telnyx_object(arr, {})
88
-
89
- list = TestListObject.construct_from(data: [{ id: 1 }],
90
- meta: { next_page_token: "123" },
91
- url: "/things")
92
- stub_request(:get, "#{Telnyx.api_base}/things")
93
- .with(query: { page: { token: "123" } })
94
- .to_return(body: JSON.generate(data: [{ id: 2 }], meta: { next_page_token: "456" }))
95
- stub_request(:get, "#{Telnyx.api_base}/things")
96
- .with(query: { page: { token: "456" } })
97
- .to_return(body: JSON.generate(data: [{ id: 3 }], meta: { next_page_token: "789" }))
98
- stub_request(:get, "#{Telnyx.api_base}/things")
99
- .with(query: { page: { token: "789" } })
100
- .to_return(body: JSON.generate(data: [], meta: { next_page_token: nil }))
101
-
102
- assert_equal expected, list.auto_paging_each_by_token.to_a
103
- end
104
-
105
- should "provide #auto_paging_each_by_token that responds to a block" do
106
- arr = [
107
- { id: 1 },
108
- { id: 2 },
109
- { id: 3 },
110
- ]
111
- expected = Util.convert_to_telnyx_object(arr, {})
112
-
113
- list = TestListObject.construct_from(data: [{ id: 1 }],
114
- meta: { next_page_token: "123" },
115
- url: "/things")
116
- stub_request(:get, "#{Telnyx.api_base}/things")
117
- .with(query: { page: { token: "123" } })
118
- .to_return(body: JSON.generate(data: [{ id: 2 }], meta: { next_page_token: "456" }))
119
- stub_request(:get, "#{Telnyx.api_base}/things")
120
- .with(query: { page: { token: "456" } })
121
- .to_return(body: JSON.generate(data: [{ id: 3 }], meta: { next_page_token: "789" }))
122
- stub_request(:get, "#{Telnyx.api_base}/things")
123
- .with(query: { page: { token: "789" } })
124
- .to_return(body: JSON.generate(data: [], meta: { next_page_token: nil }))
125
-
126
- actual = []
127
- list.auto_paging_each_by_token do |obj|
128
- actual << obj
129
- end
130
-
131
- assert_equal expected, actual
132
- end
133
-
134
81
  should "provide #empty?" do
135
82
  list = Telnyx::ListObject.construct_from(data: [])
136
83
  assert list.empty?
@@ -138,6 +85,52 @@ module Telnyx
138
85
  refute list.empty?
139
86
  end
140
87
 
88
+ #
89
+ # page_size
90
+ #
91
+
92
+ should "fetch the current page size via #page_size" do
93
+ list = TestListObject.construct_from(
94
+ data: [
95
+ { id: 1 },
96
+ { id: 2 },
97
+ { id: 3 },
98
+ ],
99
+ meta: {
100
+ page_size: 5,
101
+ total_results: 3,
102
+ total_pages: 1,
103
+ page_number: 1,
104
+ },
105
+ url: "/things"
106
+ )
107
+
108
+ assert_equal(list.page_size, 5)
109
+ end
110
+
111
+ #
112
+ # page_number
113
+ #
114
+
115
+ should "fetch the current page number via #page_number" do
116
+ list = TestListObject.construct_from(
117
+ data: [
118
+ { id: 1 },
119
+ { id: 2 },
120
+ { id: 3 },
121
+ ],
122
+ meta: {
123
+ page_size: 5,
124
+ total_results: 3,
125
+ total_pages: 1,
126
+ page_number: 1,
127
+ },
128
+ url: "/things"
129
+ )
130
+
131
+ assert_equal(list.page_number, 1)
132
+ end
133
+
141
134
  #
142
135
  # next_page
143
136
  #
@@ -162,7 +155,7 @@ module Telnyx
162
155
  .with(query: { page: { number: 2, size: 20 }, enabled: true })
163
156
  .to_return(body: JSON.generate(data: [{ id: 2 }], meta: { page_number: 2, total_pages: 2 }))
164
157
  next_list = list.next_page
165
- assert_equal({ enabled: true }, next_list.filters)
158
+ assert_equal({ enabled: true, page: { number: 2, size: 20 } }, next_list.filters)
166
159
  end
167
160
 
168
161
  should "fetch an empty page through #next_page" do
@@ -173,41 +166,6 @@ module Telnyx
173
166
  assert_equal Telnyx::ListObject.empty_list, next_list
174
167
  end
175
168
 
176
- #
177
- # next page by token
178
- #
179
-
180
- should "fetch a next page through #next_page_by_token" do
181
- list = TestListObject.construct_from(data: [{ id: 1 }],
182
- meta: { next_page_token: "123" },
183
- url: "/things")
184
- stub_request(:get, "#{Telnyx.api_base}/things")
185
- .with(query: { page: { token: "123" } })
186
- .to_return(body: JSON.generate(data: [{ id: 2 }]))
187
- next_list = list.next_page_by_token
188
- refute next_list.empty?
189
- end
190
-
191
- should "fetch a next page through #next_page_by_token and respect filters" do
192
- list = TestListObject.construct_from(data: [{ id: 1 }],
193
- meta: { next_page_token: "123" },
194
- url: "/things")
195
- list.filters = { enabled: true }
196
- stub_request(:get, "#{Telnyx.api_base}/things")
197
- .with(query: { page: { token: "123" }, enabled: true })
198
- .to_return(body: JSON.generate(data: [{ id: 2 }], meta: { next_page_token: "456" }))
199
- next_list = list.next_page_by_token
200
- assert_equal({ enabled: true }, next_list.filters)
201
- end
202
-
203
- should "fetch an empty page through #next_page_by_token" do
204
- list = TestListObject.construct_from(data: [{ id: 1 }],
205
- meta: {},
206
- url: "/things")
207
- next_list = list.next_page_by_token
208
- assert_equal Telnyx::ListObject.empty_list, next_list
209
- end
210
-
211
169
  #
212
170
  # previous_page
213
171
  #
@@ -234,7 +192,7 @@ module Telnyx
234
192
 
235
193
  next_list = list.previous_page
236
194
  assert_requested(stub_get)
237
- assert_equal({ enabled: true }, next_list.filters)
195
+ assert_equal({ enabled: true, page: { number: 1, size: 20 } }, next_list.filters)
238
196
  end
239
197
  end
240
198
  end