telnyx 0.0.8 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/scripts/before_install.sh +9 -0
  3. data/.github/workflows/ruby.yml +39 -0
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +6 -36
  6. data/.rubocop_todo.yml +300 -0
  7. data/.travis.yml.bak +48 -0
  8. data/Gemfile +6 -5
  9. data/README.md +42 -3
  10. data/VERSION +1 -1
  11. data/bin/telnyx-console +7 -1
  12. data/examples/2 factor authentication/Gemfile +7 -0
  13. data/examples/2 factor authentication/main.rb +67 -0
  14. data/examples/2 factor authentication/readme.md +5 -0
  15. data/examples/fax/Gemfile +7 -0
  16. data/examples/fax/config.yaml +4 -0
  17. data/examples/fax/fax.rb +42 -0
  18. data/examples/fax/options.rb +41 -0
  19. data/examples/fax/readme.md +18 -0
  20. data/lib/telnyx.rb +22 -2
  21. data/lib/telnyx/address.rb +12 -0
  22. data/lib/telnyx/api_operations/list.rb +1 -1
  23. data/lib/telnyx/api_operations/nested_resource.rb +2 -2
  24. data/lib/telnyx/api_operations/save.rb +1 -1
  25. data/lib/telnyx/api_resource.rb +13 -2
  26. data/lib/telnyx/billing_group.rb +12 -0
  27. data/lib/telnyx/call.rb +3 -1
  28. data/lib/telnyx/call_control_application.rb +12 -0
  29. data/lib/telnyx/conference.rb +36 -0
  30. data/lib/telnyx/connection.rb +9 -0
  31. data/lib/telnyx/credential_connection.rb +12 -0
  32. data/lib/telnyx/fax.rb +13 -0
  33. data/lib/telnyx/fax_application.rb +12 -0
  34. data/lib/telnyx/fqdn.rb +12 -0
  35. data/lib/telnyx/fqdn_connection.rb +12 -0
  36. data/lib/telnyx/ip.rb +12 -0
  37. data/lib/telnyx/ip_connection.rb +12 -0
  38. data/lib/telnyx/list_object.rb +30 -44
  39. data/lib/telnyx/messaging_phone_number.rb +9 -0
  40. data/lib/telnyx/number_lookup.rb +7 -0
  41. data/lib/telnyx/number_order_document.rb +11 -0
  42. data/lib/telnyx/outbound_voice_profile.rb +12 -0
  43. data/lib/telnyx/phone_number.rb +20 -1
  44. data/lib/telnyx/phone_number_regulatory_requirement.rb +10 -0
  45. data/lib/telnyx/portout.rb +12 -0
  46. data/lib/telnyx/regulatory_requirement.rb +9 -0
  47. data/lib/telnyx/sim_card.rb +12 -1
  48. data/lib/telnyx/telnyx_client.rb +17 -26
  49. data/lib/telnyx/util.rb +38 -14
  50. data/lib/telnyx/verification.rb +27 -0
  51. data/lib/telnyx/verify_profile.rb +11 -0
  52. data/lib/telnyx/version.rb +1 -1
  53. data/lib/telnyx/wireless_detail_records_report.rb +12 -0
  54. data/telnyx.gemspec +1 -1
  55. data/test/telnyx/address_test.rb +67 -0
  56. data/test/telnyx/alphanumeric_sender_id_test.rb +4 -0
  57. data/test/telnyx/api_resource_test.rb +14 -5
  58. data/test/telnyx/billing_group_test.rb +40 -0
  59. data/test/telnyx/call_control_application_test.rb +42 -0
  60. data/test/telnyx/call_control_test.rb +54 -30
  61. data/test/telnyx/conference_test.rb +113 -0
  62. data/test/telnyx/connection_test.rb +28 -0
  63. data/test/telnyx/credential_connection_test.rb +44 -0
  64. data/test/telnyx/errors_test.rb +4 -4
  65. data/test/telnyx/fax_application_test.rb +32 -0
  66. data/test/telnyx/fax_test.rb +32 -0
  67. data/test/telnyx/fqdn_connection_test.rb +40 -0
  68. data/test/telnyx/fqdn_test.rb +40 -0
  69. data/test/telnyx/ip_connection_test.rb +40 -0
  70. data/test/telnyx/ip_test.rb +40 -0
  71. data/test/telnyx/list_object_test.rb +48 -90
  72. data/test/telnyx/messaging_phone_number_test.rb +8 -4
  73. data/test/telnyx/messaging_profile_test.rb +16 -5
  74. data/test/telnyx/number_lookup_test.rb +18 -0
  75. data/test/telnyx/number_order_document_test.rb +35 -0
  76. data/test/telnyx/outbound_voice_profile_test.rb +67 -0
  77. data/test/telnyx/phone_number_regulatory_requirement_test.rb +14 -0
  78. data/test/telnyx/phone_number_test.rb +40 -9
  79. data/test/telnyx/public_key_test.rb +1 -0
  80. data/test/telnyx/regulatory_requirement_test.rb +21 -0
  81. data/test/telnyx/sim_card_test.rb +6 -18
  82. data/test/telnyx/telnyx_client_test.rb +1 -1
  83. data/test/telnyx/telnyx_object_test.rb +5 -5
  84. data/test/telnyx/verification_test.rb +22 -0
  85. data/test/telnyx/verify_profile_test.rb +31 -0
  86. data/test/telnyx/wireless_detail_records_report_test.rb +57 -0
  87. data/test/test_helper.rb +1 -1
  88. metadata +93 -12
  89. data/.travis.yml +0 -51
  90. data/lib/telnyx/conferences.rb +0 -19
  91. data/test/telnyx/conferences_test.rb +0 -76
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class ConferenceTest < Test::Unit::TestCase
7
+ setup do
8
+ @conference = Conference.create call_control_id: "foobar", name: "conference!"
9
+ end
10
+ should "create conference" do
11
+ assert_requested :post, "#{Telnyx.api_base}/v2/conferences"
12
+ assert_kind_of Conference, @conference
13
+ end
14
+
15
+ should "retrieve conference" do
16
+ conference = Conference.retrieve "foobar"
17
+ assert_kind_of Conference, conference
18
+ assert_requested :get, "#{Telnyx.api_base}/v2/conferences/foobar"
19
+ end
20
+
21
+ should "list conferences" do
22
+ conferences = Conference.list
23
+
24
+ assert_requested :get, "#{Telnyx.api_base}/v2/conferences"
25
+ assert_kind_of ListObject, conferences
26
+ assert_kind_of Conference, conferences.first
27
+ end
28
+
29
+ should "list participants" do
30
+ participants = @conference.participants
31
+ assert_requested :get, "#{Telnyx.api_base}/v2/conferences/#{@conference.id}/participants"
32
+ assert_kind_of ListObject, participants
33
+ end
34
+
35
+ should "have nested command instance methods" do
36
+ assert defined? @conference.join
37
+ assert defined? @conference.mute
38
+ assert defined? @conference.unmute
39
+ assert defined? @conference.unhold
40
+ assert defined? @conference.play
41
+ assert defined? @conference.start_recording
42
+ assert defined? @conference.stop_recording
43
+ assert defined? @conference.speak
44
+ assert defined? @conference.dial_participant
45
+ assert defined? @conference.update
46
+ end
47
+
48
+ context "commands" do
49
+ should "join" do
50
+ @conference.join call_control_id: "foo_bar_baz"
51
+ assert_requested :post, action_url(@conference, "join")
52
+ end
53
+
54
+ should "mute" do
55
+ @conference.mute
56
+ assert_requested :post, action_url(@conference, "mute")
57
+ end
58
+
59
+ should "unmute" do
60
+ @conference.unmute
61
+ assert_requested :post, action_url(@conference, "unmute")
62
+ end
63
+
64
+ should "hold" do
65
+ @conference.hold
66
+ assert_requested :post, action_url(@conference, "hold")
67
+ end
68
+
69
+ should "unhold" do
70
+ @conference.unhold call_control_ids: %w[foo bar baz]
71
+ assert_requested :post, action_url(@conference, "unhold")
72
+ end
73
+
74
+ should "play" do
75
+ @conference.play audio_url: "https://example.com/audio.mp3"
76
+ assert_requested :post, action_url(@conference, "play")
77
+ end
78
+
79
+ should "start recording" do
80
+ @conference.start_recording channels: "dual", format: "mp3"
81
+ assert_requested :post, action_url(@conference, "record_start")
82
+ end
83
+
84
+ should "stop recording" do
85
+ @conference.stop_recording
86
+ assert_requested :post, action_url(@conference, "record_stop")
87
+ end
88
+
89
+ should "speak" do
90
+ @conference.speak language: "en-US", payload: "test speech", voice: "female"
91
+ assert_requested :post, action_url(@conference, "speak")
92
+ end
93
+
94
+ should "dial participant" do
95
+ @conference.dial_participant call_control_id: "foo", to: "+12223334444", from: "+12223335555"
96
+ assert_requested :post, action_url(@conference, "dial_participant")
97
+ end
98
+
99
+ should "update" do
100
+ @conference.update call_control_id: "foo"
101
+ assert_requested :post, action_url(@conference, "update")
102
+ end
103
+ end
104
+
105
+ def create_call
106
+ Telnyx::Call.create connection_id: "12345", to: "+15550001111", from: "+15550002222"
107
+ end
108
+
109
+ def action_url(conf, action)
110
+ "#{Telnyx.api_base}/v2/conferences/#{conf.id}/actions/#{action}"
111
+ end
112
+ end
113
+ end
@@ -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
@@ -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,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