telnyx 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 -6
- data/README.md +1 -1
- data/VERSION +1 -1
- data/bin/telnyx-console +5 -0
- 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 +5 -1
- data/lib/telnyx/api_operations/save.rb +1 -1
- data/lib/telnyx/api_resource.rb +14 -3
- data/lib/telnyx/conference.rb +17 -1
- data/lib/telnyx/fax.rb +13 -0
- data/lib/telnyx/fax_application.rb +12 -0
- data/lib/telnyx/messaging_phone_number.rb +9 -0
- data/lib/telnyx/phone_number.rb +5 -1
- data/lib/telnyx/sim_card.rb +12 -1
- data/lib/telnyx/telnyx_client.rb +15 -24
- data/lib/telnyx/util.rb +7 -1
- data/lib/telnyx/verification.rb +27 -0
- data/lib/telnyx/verify_profile.rb +11 -0
- data/lib/telnyx/version.rb +1 -1
- data/telnyx.gemspec +1 -1
- data/test/telnyx/call_control_test.rb +3 -3
- data/test/telnyx/conference_test.rb +57 -20
- data/test/telnyx/credential_connection_test.rb +5 -1
- data/test/telnyx/fax_application_test.rb +32 -0
- data/test/telnyx/fax_test.rb +32 -0
- data/test/telnyx/fqdn_connection_test.rb +1 -1
- data/test/telnyx/fqdn_test.rb +1 -1
- data/test/telnyx/messaging_phone_number_test.rb +8 -4
- data/test/telnyx/messaging_profile_test.rb +1 -1
- data/test/telnyx/phone_number_test.rb +9 -21
- data/test/telnyx/sim_card_test.rb +6 -6
- 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/test_helper.rb +1 -1
- metadata +36 -7
- data/.travis.yml +0 -51
data/lib/telnyx/telnyx_client.rb
CHANGED
@@ -310,30 +310,21 @@ module Telnyx
|
|
310
310
|
json_body: resp.data,
|
311
311
|
}
|
312
312
|
|
313
|
-
case resp.http_status
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
when 429
|
329
|
-
RateLimitError.new(error_list, opts)
|
330
|
-
when 500
|
331
|
-
APIError.new(error_list, opts)
|
332
|
-
when 503
|
333
|
-
ServiceUnavailableError.new(error_list, opts)
|
334
|
-
else
|
335
|
-
APIError.new(error_list, opts)
|
336
|
-
end
|
313
|
+
err_class = case resp.http_status
|
314
|
+
when 400 then InvalidRequestError
|
315
|
+
when 401 then AuthenticationError
|
316
|
+
when 403 then PermissionError
|
317
|
+
when 404 then ResourceNotFoundError
|
318
|
+
when 405 then MethodNotSupportedError
|
319
|
+
when 408 then TimeoutError
|
320
|
+
when 422 then InvalidParametersError
|
321
|
+
when 429 then RateLimitError
|
322
|
+
when 500 then APIError
|
323
|
+
when 503 then ServiceUnavailableError
|
324
|
+
else APIError
|
325
|
+
end
|
326
|
+
|
327
|
+
err_class.new(error_list, **opts)
|
337
328
|
end
|
338
329
|
|
339
330
|
def handle_network_error(e, context, num_retries, api_base = nil)
|
data/lib/telnyx/util.rb
CHANGED
@@ -48,12 +48,15 @@ module Telnyx
|
|
48
48
|
Conferences::OBJECT_NAME => Conferences,
|
49
49
|
Connection::OBJECT_NAME => Connection,
|
50
50
|
CredentialConnection::OBJECT_NAME => CredentialConnection,
|
51
|
+
Fax::OBJECT_NAME => Fax,
|
52
|
+
FaxApplication::OBJECT_NAME => FaxApplication,
|
51
53
|
FQDN::OBJECT_NAME => FQDN,
|
52
54
|
FQDNConnection::OBJECT_NAME => FQDNConnection,
|
53
55
|
IP::OBJECT_NAME => IP,
|
54
56
|
IPConnection::OBJECT_NAME => IPConnection,
|
55
57
|
Message::OBJECT_NAME => Message,
|
56
58
|
MessagingPhoneNumber::OBJECT_NAME => MessagingPhoneNumber,
|
59
|
+
"messaging_settings" => MessagingPhoneNumber,
|
57
60
|
MessagingProfile::OBJECT_NAME => MessagingProfile,
|
58
61
|
NumberLookup::OBJECT_NAME => NumberLookup,
|
59
62
|
NumberOrder::OBJECT_NAME => NumberOrder,
|
@@ -65,9 +68,12 @@ module Telnyx
|
|
65
68
|
PhoneNumberRegulatoryRequirement::OBJECT_NAME => PhoneNumberRegulatoryRequirement,
|
66
69
|
"phone_number_regulatory_group" => PhoneNumberRegulatoryRequirement,
|
67
70
|
Portout::OBJECT_NAME => Portout,
|
71
|
+
VerifyProfile::OBJECT_NAME => VerifyProfile,
|
68
72
|
PublicKey::OBJECT_NAME => PublicKey,
|
69
73
|
RegulatoryRequirement::OBJECT_NAME => RegulatoryRequirement,
|
70
74
|
SimCard::OBJECT_NAME => SimCard,
|
75
|
+
Verification::OBJECT_NAME => Verification,
|
76
|
+
"verification" => Verification::Response,
|
71
77
|
WirelessDetailRecordsReport::OBJECT_NAME => WirelessDetailRecordsReport,
|
72
78
|
}
|
73
79
|
end
|
@@ -86,7 +92,7 @@ module Telnyx
|
|
86
92
|
#
|
87
93
|
# ==== Attributes
|
88
94
|
#
|
89
|
-
# * +
|
95
|
+
# * +Data+ - Hash of fields and values to be converted into a TelnyxObject.
|
90
96
|
# * +opts+ - Options for +TelnyxObject+ like an API key that will be reused
|
91
97
|
# on subsequent API calls.
|
92
98
|
def self.convert_to_telnyx_object(data, opts = {})
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telnyx
|
4
|
+
class Verification < APIResource
|
5
|
+
# Type for verification responses
|
6
|
+
class Response < TelnyxObject; end
|
7
|
+
|
8
|
+
extend APIOperations::Create
|
9
|
+
extend APIOperations::NestedResource
|
10
|
+
|
11
|
+
nested_resource_class_methods "by_telephone",
|
12
|
+
path: "by_tn",
|
13
|
+
operations: [:retrieve],
|
14
|
+
instance_methods: {
|
15
|
+
retrieve: "by_telephone",
|
16
|
+
}
|
17
|
+
|
18
|
+
def self.submit_code(phone_number: nil, code: nil)
|
19
|
+
url = "#{resource_url}/by_phone_number/#{CGI.escape phone_number}/actions/verify"
|
20
|
+
resp, _opts = request(:post, url, code: code)
|
21
|
+
Response.construct_from resp.data[:data]
|
22
|
+
end
|
23
|
+
|
24
|
+
OBJECT_NAME = "verify_verification".freeze
|
25
|
+
RESOURCE_PATH = "verifications".freeze
|
26
|
+
end
|
27
|
+
end
|
data/lib/telnyx/version.rb
CHANGED
data/telnyx.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
"source_code_uri" => "https://github.com/team-telnyx/telnyx-ruby",
|
23
23
|
}
|
24
24
|
|
25
|
-
s.add_dependency("faraday", "~> 0.13", "!= 0.16.0", "!= 0.16.1", "!= 0.16.2")
|
25
|
+
s.add_dependency("faraday", "~> 0.13", "!= 0.16.0", "!= 0.16.1", "!= 0.16.2", "!= 0.17.1")
|
26
26
|
s.add_dependency("net-http-persistent", "~> 3.0")
|
27
27
|
s.add_dependency("ed25519", "~> 1")
|
28
28
|
|
@@ -66,7 +66,7 @@ module Telnyx
|
|
66
66
|
should "send all commands" do
|
67
67
|
@call = Call.new
|
68
68
|
@call.id = "1234"
|
69
|
-
@call.reject
|
69
|
+
@call.reject cause: "CALL_REJECTED"
|
70
70
|
assert_requested :post, format_url(@call, "reject")
|
71
71
|
@call.answer
|
72
72
|
assert_requested :post, format_url(@call, "answer")
|
@@ -97,7 +97,7 @@ module Telnyx
|
|
97
97
|
|
98
98
|
context "commands" do
|
99
99
|
should "reject" do
|
100
|
-
@call.reject
|
100
|
+
@call.reject cause: "CALL_REJECTED"
|
101
101
|
assert_requested :post, format_url(@call, "reject")
|
102
102
|
end
|
103
103
|
should "answer" do
|
@@ -151,7 +151,7 @@ module Telnyx
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def create_call
|
154
|
-
Telnyx::Call.create connection_id: "12345", to: "+15550001111", from: "+15550002222"
|
154
|
+
Telnyx::Call.create connection_id: "12345", to: "+15550001111", from: "+15550002222", cause: "test"
|
155
155
|
end
|
156
156
|
|
157
157
|
def format_url(call, action)
|
@@ -5,14 +5,19 @@ require_relative "../test_helper"
|
|
5
5
|
module Telnyx
|
6
6
|
class ConferenceTest < Test::Unit::TestCase
|
7
7
|
setup do
|
8
|
-
@
|
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
|
-
|
34
|
-
|
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
|
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
|
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
|
66
|
+
assert_requested :post, action_url(@conference, "hold")
|
58
67
|
end
|
59
68
|
|
60
69
|
should "unhold" do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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")
|
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
|
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
|
|
@@ -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
|
data/test/telnyx/fqdn_test.rb
CHANGED
@@ -6,14 +6,16 @@ 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
|
@@ -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
|
-
|
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
|