telnyx 0.0.7 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/scripts/before_install.sh +9 -0
- data/.github/workflows/ruby.yml +39 -0
- data/.rubocop.yml +6 -36
- data/.rubocop_todo.yml +300 -0
- data/.travis.yml.bak +48 -0
- data/Gemfile +6 -5
- data/README.md +42 -3
- data/VERSION +1 -1
- data/bin/telnyx-console +7 -1
- data/examples/2 factor authentication/Gemfile +7 -0
- data/examples/2 factor authentication/main.rb +67 -0
- data/examples/2 factor authentication/readme.md +5 -0
- data/examples/fax/Gemfile +7 -0
- data/examples/fax/config.yaml +4 -0
- data/examples/fax/fax.rb +42 -0
- data/examples/fax/options.rb +41 -0
- data/examples/fax/readme.md +18 -0
- data/lib/telnyx.rb +22 -2
- data/lib/telnyx/address.rb +12 -0
- data/lib/telnyx/api_operations/list.rb +1 -1
- data/lib/telnyx/api_operations/nested_resource.rb +2 -2
- data/lib/telnyx/api_operations/save.rb +1 -1
- data/lib/telnyx/api_resource.rb +13 -2
- data/lib/telnyx/billing_group.rb +12 -0
- data/lib/telnyx/call_control_application.rb +12 -0
- data/lib/telnyx/conference.rb +36 -0
- data/lib/telnyx/connection.rb +9 -0
- data/lib/telnyx/credential_connection.rb +12 -0
- data/lib/telnyx/fax.rb +13 -0
- data/lib/telnyx/fax_application.rb +12 -0
- data/lib/telnyx/fqdn.rb +12 -0
- data/lib/telnyx/fqdn_connection.rb +12 -0
- data/lib/telnyx/ip.rb +12 -0
- data/lib/telnyx/ip_connection.rb +12 -0
- data/lib/telnyx/list_object.rb +30 -44
- data/lib/telnyx/messaging_phone_number.rb +9 -0
- data/lib/telnyx/number_lookup.rb +7 -0
- data/lib/telnyx/number_order_document.rb +11 -0
- data/lib/telnyx/outbound_voice_profile.rb +12 -0
- data/lib/telnyx/phone_number.rb +20 -1
- data/lib/telnyx/phone_number_regulatory_requirement.rb +9 -0
- data/lib/telnyx/portout.rb +12 -0
- data/lib/telnyx/regulatory_requirement.rb +9 -0
- data/lib/telnyx/sim_card.rb +17 -1
- data/lib/telnyx/telnyx_client.rb +16 -25
- data/lib/telnyx/util.rb +38 -14
- data/lib/telnyx/verification.rb +27 -0
- data/lib/telnyx/verify_profile.rb +11 -0
- data/lib/telnyx/version.rb +1 -1
- data/lib/telnyx/wireless_detail_records_report.rb +12 -0
- data/telnyx.gemspec +1 -1
- data/test/telnyx/address_test.rb +67 -0
- data/test/telnyx/alphanumeric_sender_id_test.rb +4 -0
- data/test/telnyx/api_resource_test.rb +14 -5
- data/test/telnyx/billing_group_test.rb +40 -0
- data/test/telnyx/call_control_application_test.rb +42 -0
- data/test/telnyx/call_control_test.rb +3 -3
- data/test/telnyx/conference_test.rb +113 -0
- data/test/telnyx/connection_test.rb +28 -0
- data/test/telnyx/credential_connection_test.rb +44 -0
- data/test/telnyx/errors_test.rb +4 -4
- data/test/telnyx/fax_application_test.rb +32 -0
- data/test/telnyx/fax_test.rb +32 -0
- data/test/telnyx/fqdn_connection_test.rb +40 -0
- data/test/telnyx/fqdn_test.rb +40 -0
- data/test/telnyx/ip_connection_test.rb +40 -0
- data/test/telnyx/ip_test.rb +40 -0
- data/test/telnyx/list_object_test.rb +48 -90
- data/test/telnyx/messaging_phone_number_test.rb +8 -4
- data/test/telnyx/messaging_profile_test.rb +16 -5
- data/test/telnyx/number_lookup_test.rb +18 -0
- data/test/telnyx/number_order_document_test.rb +35 -0
- data/test/telnyx/outbound_voice_profile_test.rb +67 -0
- data/test/telnyx/phone_number_regulatory_requirement_test.rb +14 -0
- data/test/telnyx/phone_number_test.rb +40 -9
- data/test/telnyx/public_key_test.rb +1 -0
- data/test/telnyx/regulatory_requirement_test.rb +21 -0
- data/test/telnyx/sim_card_test.rb +14 -29
- data/test/telnyx/telnyx_client_test.rb +1 -1
- data/test/telnyx/telnyx_object_test.rb +5 -5
- data/test/telnyx/verification_test.rb +22 -0
- data/test/telnyx/verify_profile_test.rb +31 -0
- data/test/telnyx/wireless_detail_records_report_test.rb +57 -0
- data/test/test_helper.rb +1 -1
- metadata +85 -10
- data/.travis.yml +0 -51
- data/lib/telnyx/conferences.rb +0 -19
- data/test/telnyx/conferences_test.rb +0 -76
@@ -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,44 @@
|
|
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
|
+
connection_name: "Test connection_name",
|
17
|
+
user_name: "Test user_name",
|
18
|
+
password: "correct-horse-battery-staple"
|
19
|
+
)
|
20
|
+
assert_requested :post, "#{Telnyx.api_base}/v2/credential_connections"
|
21
|
+
end
|
22
|
+
|
23
|
+
should "retrieve credential connection" do
|
24
|
+
credential_connection = CredentialConnection.retrieve("id")
|
25
|
+
assert_requested :get, "#{Telnyx.api_base}/v2/credential_connections/id"
|
26
|
+
assert_kind_of CredentialConnection, credential_connection
|
27
|
+
end
|
28
|
+
|
29
|
+
should "delete credential connection" do
|
30
|
+
credential_connection = CredentialConnection.retrieve("id")
|
31
|
+
|
32
|
+
credential_connection.delete
|
33
|
+
assert_requested :delete, "#{Telnyx.api_base}/v2/credential_connections/id"
|
34
|
+
end
|
35
|
+
|
36
|
+
should "update credential connection" do
|
37
|
+
credential_connection = CredentialConnection.retrieve("id")
|
38
|
+
|
39
|
+
credential_connection.active = false
|
40
|
+
credential_connection.save
|
41
|
+
assert_requested :patch, "#{Telnyx.api_base}/v2/credential_connections/id"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/test/telnyx/errors_test.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
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,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../test_helper"
|
4
|
+
|
5
|
+
module Telnyx
|
6
|
+
class FaxApplicationTest < Test::Unit::TestCase
|
7
|
+
should "fetch index" do
|
8
|
+
fax_applications = FaxApplication.list
|
9
|
+
assert_requested :get, "#{Telnyx.api_base}/v2/fax_applications"
|
10
|
+
assert_kind_of ListObject, fax_applications
|
11
|
+
assert_kind_of FaxApplication, fax_applications.first
|
12
|
+
end
|
13
|
+
|
14
|
+
should "create" do
|
15
|
+
fax_application = FaxApplication.create application_name: "foo", webhook_event_url: "https://foo.bar.com"
|
16
|
+
assert_requested :post, "#{Telnyx.api_base}/v2/fax_applications"
|
17
|
+
assert_kind_of FaxApplication, fax_application
|
18
|
+
end
|
19
|
+
|
20
|
+
should "retrieve" do
|
21
|
+
fax_application = FaxApplication.retrieve "foo"
|
22
|
+
assert_requested :get, "#{Telnyx.api_base}/v2/fax_applications/foo"
|
23
|
+
assert_kind_of FaxApplication, fax_application
|
24
|
+
end
|
25
|
+
|
26
|
+
should "delete" do
|
27
|
+
fax_application = FaxApplication.retrieve "foo"
|
28
|
+
fax_application.delete
|
29
|
+
assert_requested :delete, "#{Telnyx.api_base}/v2/fax_applications/foo"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../test_helper"
|
4
|
+
module Telnyx
|
5
|
+
class FaxTest < Test::Unit::TestCase
|
6
|
+
should "fetch index" do
|
7
|
+
faxes = Fax.list
|
8
|
+
assert_requested :get, "#{Telnyx.api_base}/v2/faxes"
|
9
|
+
assert_kind_of ListObject, faxes
|
10
|
+
assert_kind_of Fax, faxes.first
|
11
|
+
end
|
12
|
+
|
13
|
+
should "send fax" do
|
14
|
+
fax = Fax.create connection_id: "foo", media_url: "example.com", to: "+13127367276"
|
15
|
+
assert_requested :post, "#{Telnyx.api_base}/v2/faxes"
|
16
|
+
assert_kind_of Fax, fax
|
17
|
+
end
|
18
|
+
|
19
|
+
should "view fax" do
|
20
|
+
fax = Fax.retrieve "foo"
|
21
|
+
assert_requested :get, "#{Telnyx.api_base}/v2/faxes/foo"
|
22
|
+
assert_kind_of Fax, fax
|
23
|
+
end
|
24
|
+
|
25
|
+
should "delete fax" do
|
26
|
+
omit "!!waiting for mock!!"
|
27
|
+
fax = Fax.retrieve "foo"
|
28
|
+
fax.delete
|
29
|
+
assert_requested :delete, "#{Telnyx.api_base}/v2/faxes/foo"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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(connection_name: "test")
|
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", dns_record_type: "A", connection_id: "abc"
|
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
|