telnyx 0.0.5 → 2.2.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.
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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class NumberLookup < APIResource
5
+ RESOURCE_PATH = OBJECT_NAME = "number_lookup".freeze
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class NumberOrderDocument < APIResource
5
+ extend APIOperations::Create
6
+ extend APIOperations::List
7
+ include APIOperations::Save
8
+
9
+ OBJECT_NAME = "number_order_document".freeze
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class OutboundVoiceProfile < APIResource
5
+ include Telnyx::APIOperations::Save
6
+ include Telnyx::APIOperations::Delete
7
+ extend Telnyx::APIOperations::List
8
+ extend Telnyx::APIOperations::Create
9
+
10
+ OBJECT_NAME = "outbound_voice_profile".freeze
11
+ end
12
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class PhoneNumber < APIResource
5
+ include Telnyx::APIOperations::Save
6
+ include Telnyx::APIOperations::Delete
7
+ extend Telnyx::APIOperations::List
8
+ extend Telnyx::APIOperations::NestedResource
9
+
10
+ nested_resource_class_methods "voice",
11
+ path: ["voice"],
12
+ operations: %i[update list],
13
+ instance_methods: { list: "voice" }
14
+ nested_resource_class_methods "messaging",
15
+ path: ["messaging"],
16
+ operations: %i[update list],
17
+ instance_methods: { list: "messaging" }
18
+ nested_resource_class_methods "inbound_channel",
19
+ path: ["inbound_channels"],
20
+ operations: %i[update list]
21
+
22
+ def update_messaging(opts)
23
+ self.class.update_messaging(id, nil, opts)
24
+ end
25
+
26
+ def update_voice(opts)
27
+ self.class.update_voice(id, nil, opts)
28
+ end
29
+
30
+ def update_inbound_channels=(val)
31
+ self.class.update_inbound_channel(nil, nil, channels: val)
32
+ end
33
+
34
+ def inbound_channels
35
+ self.class.list_inbound_channels(nil).channels
36
+ end
37
+
38
+ def self.list_voice
39
+ list_voices nil
40
+ end
41
+
42
+ OBJECT_NAME = "phone_number".freeze
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class PhoneNumberRegulatoryRequirement < APIResource
5
+ extend APIOperations::List
6
+
7
+ OBJECT_NAME = "phone_number_regulatory_requirement".freeze
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class Portout < APIResource
5
+ extend APIOperations::List
6
+ extend APIOperations::Create
7
+ include APIOperations::Delete
8
+ include APIOperations::Save
9
+
10
+ OBJECT_NAME = "portout".freeze
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class RegulatoryRequirement < APIResource
5
+ extend APIOperations::List
6
+
7
+ OBJECT_NAME = "regulatory_requirement".freeze
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class SimCard < APIResource
5
+ include Telnyx::APIOperations::Save
6
+ extend APIOperations::NestedResource
7
+ extend APIOperations::List
8
+
9
+ ACTIONS = %w[deactivate activate].freeze
10
+ ACTIONS.each do |action|
11
+ nested_resource_class_methods action,
12
+ path: %W[actions #{action}],
13
+ operations: [:create],
14
+ instance_methods: { create: action }
15
+ end
16
+
17
+ def self.register(params = {}, opts = {})
18
+ resp, opts = request(:post, "/v2/actions/register/sim_cards", params, opts)
19
+ Util.convert_to_telnyx_object(resp.data, opts)
20
+ end
21
+
22
+ OBJECT_NAME = "sim_card".freeze
23
+ end
24
+ end
@@ -358,7 +358,7 @@ module Telnyx
358
358
  message = "Could not connect to Telnyx (#{api_base}). " \
359
359
  "Please check your internet connection and try again. " \
360
360
  "If this problem persists, you should check Telnyx's service status at " \
361
- "https://twitter.com/telnyxstatus, or let us know at support@telnyx.com."
361
+ "https://status.telnyx.com, or let us know at support@telnyx.com."
362
362
 
363
363
  else
364
364
  message = "Unexpected error communicating with Telnyx. " \
@@ -26,7 +26,7 @@ module Telnyx
26
26
  # This may throw JSON::ParserError if the response body is not valid JSON.
27
27
  def self.from_faraday_hash(http_resp)
28
28
  resp = TelnyxResponse.new
29
- resp.data = JSON.parse(http_resp[:body], symbolize_names: true)
29
+ resp.data = JSON.parse(preprocess_response(http_resp[:body]), symbolize_names: true)
30
30
  resp.http_body = http_resp[:body]
31
31
  resp.http_headers = http_resp[:headers]
32
32
  resp.http_status = http_resp[:status]
@@ -39,12 +39,21 @@ module Telnyx
39
39
  # This may throw JSON::ParserError if the response body is not valid JSON.
40
40
  def self.from_faraday_response(http_resp)
41
41
  resp = TelnyxResponse.new
42
- resp.data = JSON.parse(http_resp.body, symbolize_names: true)
42
+ resp.data = JSON.parse(preprocess_response(http_resp.body), symbolize_names: true)
43
43
  resp.http_body = http_resp.body
44
44
  resp.http_headers = http_resp.headers
45
45
  resp.http_status = http_resp.status
46
46
  resp.request_id = http_resp.headers["X-Request-Id"]
47
47
  resp
48
48
  end
49
+
50
+ class << self
51
+ private
52
+
53
+ # Helper to handle when the server responds with a blank body (as is the case with SimCards).
54
+ def preprocess_response(resp)
55
+ resp.empty? ? "{}" : resp
56
+ end
57
+ end
49
58
  end
50
59
  end
@@ -39,16 +39,36 @@ module Telnyx
39
39
  def self.object_classes
40
40
  @object_classes ||= {
41
41
  # business objects
42
- AlphanumericSenderId::OBJECT_NAME => AlphanumericSenderId,
43
- AvailablePhoneNumber::OBJECT_NAME => AvailablePhoneNumber,
44
- Call::OBJECT_NAME => Call,
45
- Conferences::OBJECT_NAME => Conferences,
46
- Message::OBJECT_NAME => Message,
47
- MessagingPhoneNumber::OBJECT_NAME => MessagingPhoneNumber,
48
- MessagingProfile::OBJECT_NAME => MessagingProfile,
49
- NumberOrder::OBJECT_NAME => NumberOrder,
50
- NumberReservation::OBJECT_NAME => NumberReservation,
51
- PublicKey::OBJECT_NAME => PublicKey,
42
+ Address::OBJECT_NAME => Address,
43
+ AlphanumericSenderId::OBJECT_NAME => AlphanumericSenderId,
44
+ AvailablePhoneNumber::OBJECT_NAME => AvailablePhoneNumber,
45
+ BillingGroup::OBJECT_NAME => BillingGroup,
46
+ Call::OBJECT_NAME => Call,
47
+ CallControlApplication::OBJECT_NAME => CallControlApplication,
48
+ Conferences::OBJECT_NAME => Conferences,
49
+ Connection::OBJECT_NAME => Connection,
50
+ CredentialConnection::OBJECT_NAME => CredentialConnection,
51
+ FQDN::OBJECT_NAME => FQDN,
52
+ FQDNConnection::OBJECT_NAME => FQDNConnection,
53
+ IP::OBJECT_NAME => IP,
54
+ IPConnection::OBJECT_NAME => IPConnection,
55
+ Message::OBJECT_NAME => Message,
56
+ MessagingPhoneNumber::OBJECT_NAME => MessagingPhoneNumber,
57
+ MessagingProfile::OBJECT_NAME => MessagingProfile,
58
+ NumberLookup::OBJECT_NAME => NumberLookup,
59
+ NumberOrder::OBJECT_NAME => NumberOrder,
60
+ NumberOrderDocument::OBJECT_NAME => NumberOrderDocument,
61
+ NumberReservation::OBJECT_NAME => NumberReservation,
62
+ OutboundVoiceProfile::OBJECT_NAME => OutboundVoiceProfile,
63
+ PhoneNumber::OBJECT_NAME => PhoneNumber,
64
+ "phone_number_reservation" => NumberReservation,
65
+ PhoneNumberRegulatoryRequirement::OBJECT_NAME => PhoneNumberRegulatoryRequirement,
66
+ "phone_number_regulatory_group" => PhoneNumberRegulatoryRequirement,
67
+ Portout::OBJECT_NAME => Portout,
68
+ PublicKey::OBJECT_NAME => PublicKey,
69
+ RegulatoryRequirement::OBJECT_NAME => RegulatoryRequirement,
70
+ SimCard::OBJECT_NAME => SimCard,
71
+ WirelessDetailRecordsReport::OBJECT_NAME => WirelessDetailRecordsReport,
52
72
  }
53
73
  end
54
74
 
@@ -77,7 +97,7 @@ module Telnyx
77
97
  # Try converting to a known object class. If none available, fall back to generic TelnyxObject
78
98
  if data[:data].is_a?(Array)
79
99
  ListObject.construct_from(data, opts)
80
- elsif data[:data] && data[:data][:record_type]
100
+ elsif data[:data].is_a?(Hash) && data[:data][:record_type]
81
101
  object_classes.fetch(data[:data][:record_type], TelnyxObject).construct_from(data[:data], opts)
82
102
  elsif data[:record_type]
83
103
  object_classes.fetch(data[:record_type], TelnyxObject).construct_from(data, opts)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Telnyx
4
- VERSION = "0.0.5".freeze
4
+ VERSION = "2.2.0".freeze
5
5
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class WirelessDetailRecordsReport < APIResource
5
+ include APIOperations::Delete
6
+ extend APIOperations::List
7
+ extend APIOperations::Create
8
+
9
+ OBJECT_NAME = "detail_records_report".freeze
10
+ RESOURCE_PATH = "wireless/detail_records_reports".freeze
11
+ end
12
+ end
@@ -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")
25
+ s.add_dependency("faraday", "~> 0.13", "!= 0.16.0", "!= 0.16.1", "!= 0.16.2")
26
26
  s.add_dependency("net-http-persistent", "~> 3.0")
27
27
  s.add_dependency("ed25519", "~> 1")
28
28
 
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class AddressTest < Test::Unit::TestCase
7
+ should "list addresses" do
8
+ stub = stub_request(:get, "#{Telnyx.api_base}/v2/addresses")
9
+ .to_return(body: JSON.generate(data: [FIXTURE]))
10
+ addresses = Address.list
11
+ # assert_requested :get, "#{Telnyx.api_base}/v2/addresses"
12
+ assert_requested stub
13
+ assert_kind_of ListObject, addresses
14
+ assert_kind_of Address, addresses.first
15
+ end
16
+
17
+ should "create address" do
18
+ stub = stub_request(:post, "#{Telnyx.api_base}/v2/addresses")
19
+ .to_return(body: JSON.generate(data: FIXTURE))
20
+ address = Address.create
21
+ # assert_requested :post, "#{Telnyx.api_base}/v2/addresses"
22
+ assert_requested stub
23
+ assert_kind_of Address, address
24
+ end
25
+
26
+ should "retrieve address" do
27
+ stub = stub_request(:get, "#{Telnyx.api_base}/v2/addresses/id")
28
+ .to_return(body: JSON.generate(data: FIXTURE))
29
+ address = Address.retrieve("id")
30
+ # assert_requested :get, "#{Telnyx.api_base}/v2/addresses/id"
31
+ assert_requested stub
32
+ assert_kind_of Address, address
33
+ end
34
+
35
+ should "delete address" do
36
+ stub_request(:get, "#{Telnyx.api_base}/v2/addresses/id")
37
+ .to_return(body: JSON.generate(data: FIXTURE))
38
+ stub = stub_request(:delete, "#{Telnyx.api_base}/v2/addresses/id")
39
+ .to_return(body: JSON.generate(data: FIXTURE))
40
+ address = Address.retrieve("id")
41
+
42
+ address.delete
43
+ # assert_requested :delete, "#{Telnyx.api_base}/v2/addresses/id"
44
+ assert_requested stub
45
+ end
46
+
47
+ FIXTURE = {
48
+ "address_book" => false,
49
+ "administrative_area" => "IL",
50
+ "borough" => "Guadalajara",
51
+ "business_name" => "Toy-O'Kon",
52
+ "country_code" => "us",
53
+ "created_at" => "2018-02-02T22:25:27.521Z",
54
+ "extended_address" => "Suite 123",
55
+ "first_name" => "Alfred",
56
+ "id" => "id",
57
+ "last_name" => "Foster",
58
+ "locality" => "Chicago",
59
+ "neighborhood" => "Ciudad de los deportes",
60
+ "phone_number" => "+12125559000",
61
+ "postal_code" => 2904,
62
+ "record_type" => "address",
63
+ "street_address" => "457 Flatley Stream",
64
+ "updated_at" => "2018-02-02T22:25:27.521Z",
65
+ }.freeze
66
+ end
67
+ end
@@ -4,6 +4,10 @@ require ::File.expand_path("../../test_helper", __FILE__)
4
4
 
5
5
  module Telnyx
6
6
  class AlphanumericSenderIdTest < Test::Unit::TestCase
7
+ setup do
8
+ omit "alphanumeric ids mock spec removed"
9
+ end
10
+
7
11
  should "be listable" do
8
12
  alphanumeric_sender_ids = Telnyx::AlphanumericSenderId.list
9
13
  assert_requested :get, "#{Telnyx.api_base}/v2/alphanumeric_sender_ids"
@@ -108,9 +108,12 @@ module Telnyx
108
108
 
109
109
  assert_requested(stub_get)
110
110
 
111
+ stub_get = stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles")
112
+ .with(body: { "foo" => "bar" })
113
+ .to_return(body: JSON.generate(data: [messaging_profile_fixture]))
111
114
  Telnyx::MessagingProfile.create(name: nil, foo: "bar")
112
115
 
113
- assert_requested(:post, "#{Telnyx.api_base}/v2/messaging_profiles", body: { "foo" => "bar" })
116
+ assert_requested stub_get
114
117
  end
115
118
 
116
119
  should "requesting with a unicode ID should result in a request" do
@@ -155,19 +158,25 @@ module Telnyx
155
158
  end
156
159
 
157
160
  should "updating an object should issue a PATCH request with only the changed properties" do
158
- mp = Telnyx::MessagingProfile.construct_from(messaging_profile_fixture)
161
+ stub_patch = stub_request(:patch, "#{Telnyx.api_base}/v2/messaging_profiles/123")
162
+ .with(body: hash_including("name" => "new name"))
163
+ .to_return(body: JSON.generate(data: messaging_profile_fixture))
164
+ mp = Telnyx::MessagingProfile.retrieve("123")
159
165
  mp.name = "new name"
160
166
  mp.save
161
- assert_requested(:patch, "#{Telnyx.api_base}/v2/messaging_profiles/123", body: { "name" => "new name" })
167
+ assert_requested(stub_patch)
162
168
  end
163
169
 
164
170
  should "updating should merge in returned properties" do
171
+ stub_patch = stub_request(:patch, "#{Telnyx.api_base}/v2/messaging_profiles/123")
172
+ .with(body: hash_including("name" => "new name"))
173
+ .to_return(body: JSON.generate(data: messaging_profile_fixture))
165
174
  mp = Telnyx::MessagingProfile.new("123")
166
175
  mp.name = "new name"
167
176
  mp.save
168
177
 
169
- assert_requested(:patch, "#{Telnyx.api_base}/v2/messaging_profiles/123", body: { "name" => "new name" })
170
- assert mp.name == "new name"
178
+ assert_requested(stub_patch)
179
+ assert mp
171
180
  end
172
181
 
173
182
  should "updating should fail if api_key is overwritten with nil" do
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class BillingGroupTest < Test::Unit::TestCase
7
+ should "list billing groups" do
8
+ billing_groups = BillingGroup.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/billing_groups"
10
+ assert_kind_of ListObject, billing_groups
11
+ assert_kind_of BillingGroup, billing_groups.first
12
+ end
13
+
14
+ should "create billing group" do
15
+ BillingGroup.create
16
+ assert_requested :post, "#{Telnyx.api_base}/v2/billing_groups"
17
+ end
18
+
19
+ should "retrieve billing group" do
20
+ billing_group = BillingGroup.retrieve("id")
21
+ assert_requested :get, "#{Telnyx.api_base}/v2/billing_groups/id"
22
+ assert_kind_of BillingGroup, billing_group
23
+ end
24
+
25
+ should "delete billing group" do
26
+ billing_group = BillingGroup.retrieve("id")
27
+
28
+ billing_group.delete
29
+ assert_requested :delete, "#{Telnyx.api_base}/v2/billing_groups/id"
30
+ end
31
+
32
+ should "update billing group" do
33
+ billing_group = BillingGroup.retrieve("id")
34
+
35
+ billing_group.active = false
36
+ billing_group.save
37
+ assert_requested :patch, "#{Telnyx.api_base}/v2/billing_groups/id"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../test_helper"
4
+
5
+ module Telnyx
6
+ class CallControlApplicationTest < Test::Unit::TestCase
7
+ should "list call_control_application" do
8
+ call_control_application = CallControlApplication.list
9
+ assert_requested :get, "#{Telnyx.api_base}/v2/call_control_applications"
10
+ assert_kind_of ListObject, call_control_application
11
+ assert_kind_of CallControlApplication, call_control_application.first
12
+ end
13
+
14
+ should "create call_control_application" do
15
+ CallControlApplication.create webhook_event_url: "example.com", connection_name: "telnyx", application_name: "telnyx"
16
+ assert_requested :post, "#{Telnyx.api_base}/v2/call_control_applications"
17
+ end
18
+
19
+ should "retrieve call_control_application" do
20
+ call_control_application = CallControlApplication.retrieve("id")
21
+ assert_requested :get, "#{Telnyx.api_base}/v2/call_control_applications/id"
22
+ assert_kind_of CallControlApplication, call_control_application
23
+ end
24
+
25
+ should "delete call_control_application" do
26
+ call_control_application = CallControlApplication.retrieve("id")
27
+
28
+ call_control_application.delete
29
+ assert_requested :delete, "#{Telnyx.api_base}/v2/call_control_applications/id"
30
+ end
31
+
32
+ should "update call_control_application" do
33
+ call_control_application = CallControlApplication.retrieve("id")
34
+
35
+ call_control_application.webhook_event_url = "example.com"
36
+ call_control_application.connection_name = "telnyx"
37
+ call_control_application.application_name = "telnyx"
38
+ call_control_application.save
39
+ assert_requested :patch, "#{Telnyx.api_base}/v2/call_control_applications/id"
40
+ end
41
+ end
42
+ end