telnyx 2.2.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) 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 +3 -0
  5. data/.rubocop.yml +6 -36
  6. data/.rubocop_todo.yml +300 -0
  7. data/.travis.yml.bak +48 -0
  8. data/Gemfile +10 -6
  9. data/README.md +1 -1
  10. data/VERSION +1 -1
  11. data/bin/telnyx-console +5 -0
  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 +5 -1
  21. data/lib/telnyx/api_operations/create.rb +6 -1
  22. data/lib/telnyx/api_operations/save.rb +1 -1
  23. data/lib/telnyx/api_resource.rb +24 -3
  24. data/lib/telnyx/call.rb +3 -1
  25. data/lib/telnyx/conference.rb +17 -1
  26. data/lib/telnyx/fax.rb +13 -0
  27. data/lib/telnyx/fax_application.rb +12 -0
  28. data/lib/telnyx/messaging_phone_number.rb +4 -0
  29. data/lib/telnyx/phone_number.rb +7 -3
  30. data/lib/telnyx/phone_number_regulatory_requirement.rb +1 -0
  31. data/lib/telnyx/sim_card.rb +12 -1
  32. data/lib/telnyx/telnyx_client.rb +16 -25
  33. data/lib/telnyx/util.rb +12 -34
  34. data/lib/telnyx/verification.rb +36 -0
  35. data/lib/telnyx/verify_profile.rb +11 -0
  36. data/lib/telnyx/version.rb +1 -1
  37. data/telnyx.gemspec +2 -2
  38. data/test/telnyx/alphanumeric_sender_id_test.rb +1 -1
  39. data/test/telnyx/api_operations_test.rb +1 -1
  40. data/test/telnyx/api_resource_test.rb +1 -1
  41. data/test/telnyx/available_phone_number_test.rb +1 -1
  42. data/test/telnyx/call_control_test.rb +50 -47
  43. data/test/telnyx/conference_test.rb +57 -20
  44. data/test/telnyx/credential_connection_test.rb +5 -1
  45. data/test/telnyx/errors_test.rb +1 -1
  46. data/test/telnyx/fax_application_test.rb +32 -0
  47. data/test/telnyx/fax_test.rb +33 -0
  48. data/test/telnyx/fqdn_connection_test.rb +1 -1
  49. data/test/telnyx/fqdn_test.rb +1 -1
  50. data/test/telnyx/list_object_test.rb +1 -1
  51. data/test/telnyx/message_test.rb +1 -1
  52. data/test/telnyx/messaging_phone_number_test.rb +9 -5
  53. data/test/telnyx/messaging_profile_test.rb +2 -2
  54. data/test/telnyx/number_reservation_test.rb +2 -0
  55. data/test/telnyx/phone_number_regulatory_requirement_test.rb +1 -1
  56. data/test/telnyx/phone_number_test.rb +9 -21
  57. data/test/telnyx/public_key_test.rb +1 -1
  58. data/test/telnyx/sim_card_test.rb +6 -6
  59. data/test/telnyx/telnyx_client_test.rb +43 -49
  60. data/test/telnyx/telnyx_object_test.rb +17 -19
  61. data/test/telnyx/telnyx_response_test.rb +1 -1
  62. data/test/telnyx/util_test.rb +1 -1
  63. data/test/telnyx/verification_test.rb +24 -0
  64. data/test/telnyx/verify_profile_test.rb +33 -0
  65. data/test/telnyx/webhook_test.rb +1 -1
  66. data/test/telnyx/wireless_detail_records_report_test.rb +1 -0
  67. data/test/telnyx_test.rb +20 -24
  68. data/test/test_helper.rb +1 -1
  69. metadata +52 -11
  70. data/.travis.yml +0 -51
@@ -5,14 +5,19 @@ require_relative "../test_helper"
5
5
  module Telnyx
6
6
  class ConferenceTest < Test::Unit::TestCase
7
7
  setup do
8
- @call = create_call
9
- @conference = Conference.create call_control_id: @call.id, name: "conference!"
8
+ @conference = Conference.create call_control_id: "foobar", name: "conference!"
10
9
  end
11
10
  should "create conference" do
12
11
  assert_requested :post, "#{Telnyx.api_base}/v2/conferences"
13
12
  assert_kind_of Conference, @conference
14
13
  end
15
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
+
16
21
  should "list conferences" do
17
22
  conferences = Conference.list
18
23
 
@@ -21,47 +26,79 @@ module Telnyx
21
26
  assert_kind_of Conference, conferences.first
22
27
  end
23
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
+
24
35
  should "have nested command instance methods" do
25
36
  assert defined? @conference.join
26
37
  assert defined? @conference.mute
27
38
  assert defined? @conference.unmute
28
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
29
46
  end
30
47
 
31
48
  context "commands" do
32
49
  should "join" do
33
- stub = stub_request(:post, format_url(@conference, "join"))
34
- .to_return(body: JSON.generate(result: "ok"))
35
- @conference.join
36
- assert_requested stub
50
+ @conference.join call_control_id: "foo_bar_baz"
51
+ assert_requested :post, action_url(@conference, "join")
37
52
  end
38
53
 
39
54
  should "mute" do
40
- stub = stub_request(:post, format_url(@conference, "mute"))
41
- .to_return(body: JSON.generate(result: "ok"))
42
55
  @conference.mute
43
- assert_requested stub
56
+ assert_requested :post, action_url(@conference, "mute")
44
57
  end
45
58
 
46
59
  should "unmute" do
47
- stub = stub_request(:post, format_url(@conference, "unmute"))
48
- .to_return(body: JSON.generate(result: "ok"))
49
60
  @conference.unmute
50
- assert_requested stub
61
+ assert_requested :post, action_url(@conference, "unmute")
51
62
  end
52
63
 
53
64
  should "hold" do
54
- stub = stub_request(:post, format_url(@conference, "hold"))
55
- .to_return(body: JSON.generate(result: "ok"))
56
65
  @conference.hold
57
- assert_requested stub
66
+ assert_requested :post, action_url(@conference, "hold")
58
67
  end
59
68
 
60
69
  should "unhold" do
61
- stub = stub_request(:post, format_url(@conference, "unhold"))
62
- .to_return(body: JSON.generate(result: "ok"))
63
- @conference.unhold
64
- assert_requested stub
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", supervisor_role: "barge"
101
+ assert_requested :post, action_url(@conference, "update")
65
102
  end
66
103
  end
67
104
 
@@ -69,7 +106,7 @@ module Telnyx
69
106
  Telnyx::Call.create connection_id: "12345", to: "+15550001111", from: "+15550002222"
70
107
  end
71
108
 
72
- def format_url(conf, action)
109
+ def action_url(conf, action)
73
110
  "#{Telnyx.api_base}/v2/conferences/#{conf.id}/actions/#{action}"
74
111
  end
75
112
  end
@@ -12,7 +12,11 @@ module Telnyx
12
12
  end
13
13
 
14
14
  should "create credential connection" do
15
- CredentialConnection.create
15
+ CredentialConnection.create(
16
+ connection_name: "Test connection_name",
17
+ user_name: "Test user_name",
18
+ password: "correct-horse-battery-staple"
19
+ )
16
20
  assert_requested :post, "#{Telnyx.api_base}/v2/credential_connections"
17
21
  end
18
22
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require_relative "../test_helper"
4
4
 
5
5
  module Telnyx
6
6
  class TelnyxErrorTest < Test::Unit::TestCase
@@ -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,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class FaxTest < Test::Unit::TestCase
7
+ should "fetch index" do
8
+ faxes = Fax.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/faxes"
10
+ assert_kind_of ListObject, faxes
11
+ assert_kind_of Fax, faxes.first
12
+ end
13
+
14
+ should "send fax" do
15
+ fax = Fax.create connection_id: "foo", media_url: "example.com", to: "+13127367276"
16
+ assert_requested :post, "#{Telnyx.api_base}/v2/faxes"
17
+ assert_kind_of Fax, fax
18
+ end
19
+
20
+ should "view fax" do
21
+ fax = Fax.retrieve "foo"
22
+ assert_requested :get, "#{Telnyx.api_base}/v2/faxes/foo"
23
+ assert_kind_of Fax, fax
24
+ end
25
+
26
+ should "delete fax" do
27
+ omit "!!waiting for mock!!"
28
+ fax = Fax.retrieve "foo"
29
+ fax.delete
30
+ assert_requested :delete, "#{Telnyx.api_base}/v2/faxes/foo"
31
+ end
32
+ end
33
+ end
@@ -12,7 +12,7 @@ module Telnyx
12
12
  end
13
13
 
14
14
  should "create fqdn connection" do
15
- FQDNConnection.create
15
+ FQDNConnection.create(connection_name: "test")
16
16
  assert_requested :post, "#{Telnyx.api_base}/v2/fqdn_connections"
17
17
  end
18
18
 
@@ -12,7 +12,7 @@ module Telnyx
12
12
  end
13
13
 
14
14
  should "create fqdn" do
15
- FQDN.create fqdn: "example.com"
15
+ FQDN.create fqdn: "example.com", dns_record_type: "A", connection_id: "abc"
16
16
  assert_requested :post, "#{Telnyx.api_base}/v2/fqdns"
17
17
  end
18
18
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require_relative "../test_helper"
4
4
 
5
5
  module Telnyx
6
6
  class ListObjectTest < Test::Unit::TestCase
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require_relative "../test_helper"
4
4
 
5
5
  module Telnyx
6
6
  class MessageTest < Test::Unit::TestCase
@@ -1,19 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require_relative "../test_helper"
4
4
 
5
5
  module Telnyx
6
6
  class MessagingPhoneNumberTest < Test::Unit::TestCase
7
7
  should "be listable" do
8
8
  messaging_phone_numbers = Telnyx::MessagingPhoneNumber.list
9
- assert_requested :get, "#{Telnyx.api_base}/v2/messaging_phone_numbers"
9
+ # assert_requested :get, "#{Telnyx.api_base}/v2/messaging_phone_numbers"
10
+ assert_requested :get, "#{Telnyx.api_base}/v2/phone_numbers/messaging"
10
11
  assert messaging_phone_numbers.data.is_a?(Array)
11
12
  assert messaging_phone_numbers.first.is_a?(Telnyx::MessagingPhoneNumber)
12
13
  end
13
14
 
14
15
  should "be retrievable" do
15
16
  messaging_phone_number = Telnyx::MessagingPhoneNumber.retrieve("123")
16
- assert_requested :get, "#{Telnyx.api_base}/v2/messaging_phone_numbers/123"
17
+ # assert_requested :get, "#{Telnyx.api_base}/v2/messaging_phone_numbers/123"
18
+ assert_requested :get, "#{Telnyx.api_base}/v2/phone_numbers/123/messaging"
17
19
  assert messaging_phone_number.is_a?(Telnyx::MessagingPhoneNumber)
18
20
  end
19
21
 
@@ -21,12 +23,14 @@ module Telnyx
21
23
  messaging_phone_number = Telnyx::MessagingPhoneNumber.retrieve("123")
22
24
  messaging_phone_number.messaging_profile_id = "value"
23
25
  messaging_phone_number.save
24
- assert_requested :patch, "#{Telnyx.api_base}/v2/messaging_phone_numbers/#{messaging_phone_number.id}"
26
+ # assert_requested :patch, "#{Telnyx.api_base}/v2/messaging_phone_numbers/#{messaging_phone_number.id}"
27
+ assert_requested :patch, "#{Telnyx.api_base}/v2/phone_numbers/#{messaging_phone_number.id}/messaging"
25
28
  end
26
29
 
27
30
  should "be updateable" do
28
31
  messaging_phone_number = Telnyx::MessagingPhoneNumber.update("123", messaging_profile_id: "456")
29
- assert_requested :patch, "#{Telnyx.api_base}/v2/messaging_phone_numbers/123"
32
+ # assert_requested :patch, "#{Telnyx.api_base}/v2/messaging_phone_numbers/123"
33
+ assert_requested :patch, "#{Telnyx.api_base}/v2/phone_numbers/123/messaging"
30
34
  assert messaging_phone_number.is_a?(Telnyx::MessagingPhoneNumber)
31
35
  end
32
36
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require_relative "../test_helper"
4
4
 
5
5
  module Telnyx
6
6
  class MessagingProfileTest < Test::Unit::TestCase
@@ -58,7 +58,7 @@ module Telnyx
58
58
  phone_numbers = messaging_profile.phone_numbers
59
59
  assert_requested :get, "#{Telnyx.api_base}/v2/messaging_profiles/123/phone_numbers"
60
60
  assert phone_numbers.data.is_a?(Array)
61
- assert phone_numbers.data[0].is_a?(Telnyx::MessagingPhoneNumber)
61
+ assert_kind_of Telnyx::MessagingPhoneNumber, phone_numbers.data[0]
62
62
  end
63
63
 
64
64
  should "be able to list alphanumeric sender ids" do
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../test_helper"
4
+
3
5
  module Telnyx
4
6
  class NumberReservationTest < Test::Unit::TestCase
5
7
  should "be listable" do
@@ -7,7 +7,7 @@ module Telnyx
7
7
  class PhoneNumberRegulatoryRequirementTest < Test::Unit::TestCase
8
8
  should "be listable" do
9
9
  phone_number_reg_req = PhoneNumberRegulatoryRequirement.list
10
- assert_requested :get, "#{Telnyx.api_base}/v2/phone_number_regulatory_requirements"
10
+ assert_requested :get, "#{Telnyx.api_base}/v2/phone_numbers_regulatory_requirements"
11
11
  assert_kind_of PhoneNumberRegulatoryRequirement, phone_number_reg_req.first
12
12
  end
13
13
  end
@@ -69,41 +69,29 @@ module Telnyx
69
69
  assert_equal voice.data.connection_id, "456"
70
70
  end
71
71
 
72
+ should "list messaging" do
73
+ list = Telnyx::PhoneNumber.messaging
74
+ assert_kind_of Telnyx::ListObject, list
75
+ assert_requested :get, "#{Telnyx.api_base}/v2/phone_numbers/messaging"
76
+ end
77
+
72
78
  should "get messaging" do
73
- stub_request(:get, "#{Telnyx.api_base}/v2/phone_numbers/123")
74
- .to_return(body: JSON.generate(data: mock_response("123")))
75
- command_stub = stub_request(:get, "#{Telnyx.api_base}/v2/phone_numbers/123/messaging")
76
- .to_return(body: JSON.generate(data: mock_messaging_response("456")))
77
79
  phone_number = Telnyx::PhoneNumber.retrieve("123")
78
80
  phone_number.messaging
79
- assert_requested command_stub
81
+ assert_requested :get, "#{Telnyx.api_base}/v2/phone_numbers/123/messaging"
80
82
  end
81
83
 
82
84
  should "update messaging" do
83
- stub_request(:get, "#{Telnyx.api_base}/v2/phone_numbers/123")
84
- .to_return(body: JSON.generate(data: mock_response("123")))
85
- command_stub = stub_request(:patch, "#{Telnyx.api_base}/v2/phone_numbers/123/messaging")
86
- .with(body: { messaging_profile_id: "12345", messaging_product: "P2P" })
87
- .to_return(body: JSON.generate(data: mock_messaging_response))
88
85
  phone_number = Telnyx::PhoneNumber.retrieve("123")
89
86
  phone_number.update_messaging(messaging_profile_id: "12345", messaging_product: "P2P")
90
- assert_requested command_stub
87
+ assert_requested :patch, "#{Telnyx.api_base}/v2/phone_numbers/123/messaging"
91
88
  end
92
89
 
93
90
  should "list inbound channels" do
94
- stub_request(:get, "#{Telnyx.api_base}/v2/phone_numbers/123")
95
- .to_return(body: JSON.generate(data: mock_response("123")))
96
- command_stub = stub_request(:get, "#{Telnyx.api_base}/v2/phone_numbers/inbound_channels")
97
- .to_return(body: JSON.generate(
98
- data: {
99
- channels: 7,
100
- record_type: "inbound_channels",
101
- }
102
- ))
103
91
  phone_number = Telnyx::PhoneNumber.retrieve("123")
104
92
  inbound_channels = phone_number.inbound_channels
105
93
  assert_equal inbound_channels, 7
106
- assert_requested command_stub
94
+ assert_requested :get, "#{Telnyx.api_base}/v2/phone_numbers/inbound_channels"
107
95
  end
108
96
 
109
97
  should "update inbound channel" do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require_relative "../test_helper"
4
4
 
5
5
  module Telnyx
6
6
  class PublicKeyTest < Test::Unit::TestCase
@@ -28,16 +28,16 @@ module Telnyx
28
28
  end
29
29
 
30
30
  context "actions" do
31
- should "deactivate" do
31
+ should "disable" do
32
32
  sim = Telnyx::SimCard.retrieve "123"
33
- sim.deactivate
34
- assert_requested(:post, "#{Telnyx.api_base}/v2/sim_cards/#{sim.id}/actions/deactivate")
33
+ sim.disable
34
+ assert_requested(:post, "#{Telnyx.api_base}/v2/sim_cards/#{sim.id}/actions/disable")
35
35
  end
36
36
 
37
- should "activate" do
37
+ should "enable" do
38
38
  sim = Telnyx::SimCard.retrieve "123"
39
- sim.activate
40
- assert_requested(:post, "#{Telnyx.api_base}/v2/sim_cards/#{sim.id}/actions/activate")
39
+ sim.enable
40
+ assert_requested(:post, "#{Telnyx.api_base}/v2/sim_cards/#{sim.id}/actions/enable")
41
41
  end
42
42
  end
43
43
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require_relative "../test_helper"
4
4
 
5
5
  module Telnyx
6
6
  class TelnyxClientTest < Test::Unit::TestCase
@@ -235,19 +235,17 @@ module Telnyx
235
235
 
236
236
  context "Telnyx-Account header" do
237
237
  should "use a globally set header" do
238
- begin
239
- old = Telnyx.telnyx_account
240
- Telnyx.telnyx_account = "acct_1234"
238
+ old = Telnyx.telnyx_account
239
+ Telnyx.telnyx_account = "acct_1234"
241
240
 
242
- stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles")
243
- .with(headers: { "Telnyx-Account" => Telnyx.telnyx_account })
244
- .to_return(body: JSON.generate(object: "account"))
241
+ stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles")
242
+ .with(headers: { "Telnyx-Account" => Telnyx.telnyx_account })
243
+ .to_return(body: JSON.generate(object: "account"))
245
244
 
246
- client = TelnyxClient.new
247
- client.execute_request(:post, "/v2/messaging_profiles", params: { name: "foobar" })
248
- ensure
249
- Telnyx.telnyx_account = old
250
- end
245
+ client = TelnyxClient.new
246
+ client.execute_request(:post, "/v2/messaging_profiles", params: { name: "foobar" })
247
+ ensure
248
+ Telnyx.telnyx_account = old
251
249
  end
252
250
 
253
251
  should "use a locally set header" do
@@ -274,40 +272,38 @@ module Telnyx
274
272
 
275
273
  context "app_info" do
276
274
  should "send app_info if set" do
277
- begin
278
- old = Telnyx.app_info
279
- Telnyx.set_app_info(
280
- "MyAwesomePlugin",
281
- partner_id: "partner_1234",
282
- url: "https://myawesomeplugin.info",
283
- version: "1.2.34"
284
- )
275
+ old = Telnyx.app_info
276
+ Telnyx.set_app_info(
277
+ "MyAwesomePlugin",
278
+ partner_id: "partner_1234",
279
+ url: "https://myawesomeplugin.info",
280
+ version: "1.2.34"
281
+ )
285
282
 
286
- stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles")
287
- .with do |req|
288
- assert_equal \
289
- "Telnyx/v2 RubyBindings/#{Telnyx::VERSION} " \
290
- "MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)",
291
- req.headers["User-Agent"]
283
+ stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles")
284
+ .with do |req|
285
+ assert_equal \
286
+ "Telnyx/v2 RubyBindings/#{Telnyx::VERSION} " \
287
+ "MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)",
288
+ req.headers["User-Agent"]
292
289
 
293
- data = JSON.parse(req.headers["X-Telnyx-Client-User-Agent"],
294
- symbolize_names: true)
290
+ data = JSON.parse(req.headers["X-Telnyx-Client-User-Agent"],
291
+ symbolize_names: true)
295
292
 
296
- assert_equal({
297
- name: "MyAwesomePlugin",
298
- partner_id: "partner_1234",
299
- url: "https://myawesomeplugin.info",
300
- version: "1.2.34",
301
- }, data[:application])
293
+ assert_equal({
294
+ name: "MyAwesomePlugin",
295
+ partner_id: "partner_1234",
296
+ url: "https://myawesomeplugin.info",
297
+ version: "1.2.34",
298
+ }, data[:application])
302
299
 
303
- true
304
- end.to_return(body: JSON.generate(record_type: "messaging_profile"))
300
+ true
301
+ end.to_return(body: JSON.generate(record_type: "messaging_profile"))
305
302
 
306
- client = TelnyxClient.new
307
- client.execute_request(:post, "/v2/messaging_profiles")
308
- ensure
309
- Telnyx.app_info = old
310
- end
303
+ client = TelnyxClient.new
304
+ client.execute_request(:post, "/v2/messaging_profiles")
305
+ ensure
306
+ Telnyx.app_info = old
311
307
  end
312
308
  end
313
309
 
@@ -591,16 +587,14 @@ module Telnyx
591
587
  end
592
588
 
593
589
  should "reset local thread state after a call" do
594
- begin
595
- Thread.current[:telnyx_client] = :telnyx_client
590
+ Thread.current[:telnyx_client] = :telnyx_client
596
591
 
597
- client = TelnyxClient.new
598
- client.request {}
592
+ client = TelnyxClient.new
593
+ client.request {}
599
594
 
600
- assert_equal :telnyx_client, Thread.current[:telnyx_client]
601
- ensure
602
- Thread.current[:telnyx_client] = nil
603
- end
595
+ assert_equal :telnyx_client, Thread.current[:telnyx_client]
596
+ ensure
597
+ Thread.current[:telnyx_client] = nil
604
598
  end
605
599
  end
606
600
  end