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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class BillingGroup < APIResource
5
+ extend APIOperations::List
6
+ extend APIOperations::Create
7
+ include APIOperations::Delete
8
+ include APIOperations::Save
9
+
10
+ OBJECT_NAME = "billing_group".freeze
11
+ end
12
+ end
data/lib/telnyx/call.rb CHANGED
@@ -33,7 +33,9 @@ module Telnyx
33
33
 
34
34
  ACTIONS = %w[reject answer hangup bridge speak fork_start fork_stop
35
35
  gather_using_audio gather_using_speak playback_start
36
- playback_stop record_start record_stop send_dtmf transfer].freeze
36
+ playback_stop record_start record_stop send_dtmf transfer
37
+ transcription_start transcription_stop record_pause
38
+ record_resume gather_stop refer].freeze
37
39
 
38
40
  ACTIONS.each do |action|
39
41
  nested_resource_class_methods action,
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class CallControlApplication < APIResource
5
+ extend APIOperations::List
6
+ extend APIOperations::Create
7
+ include APIOperations::Delete
8
+ include APIOperations::Save
9
+
10
+ OBJECT_NAME = "call_control_application".freeze
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class Conference < APIResource
5
+ extend APIOperations::List
6
+ extend APIOperations::Create
7
+ extend APIOperations::NestedResource
8
+
9
+ ACTIONS = %w[join mute unmute hold unhold speak play dial_participant update].freeze
10
+
11
+ ACTIONS.each do |action|
12
+ nested_resource_class_methods action,
13
+ path: ["actions", action],
14
+ operations: [:create],
15
+ instance_methods: { create: action }
16
+ end
17
+
18
+ nested_resource_class_methods "record_start",
19
+ path: ["actions", "record_start"],
20
+ operations: [:create],
21
+ instance_methods: { create: "start_recording" }
22
+
23
+ nested_resource_class_methods "record_stop",
24
+ path: ["actions", "record_stop"],
25
+ operations: [:create],
26
+ instance_methods: { create: "stop_recording" }
27
+
28
+ nested_resource_class_methods "participants",
29
+ path: "participants",
30
+ operations: [:list],
31
+ instance_methods: { list: "participants" }
32
+
33
+ OBJECT_NAME = "conference".freeze
34
+ end
35
+ Conferences = Conference # Name change without breaking existing code
36
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class Connection < APIResource
5
+ extend Telnyx::APIOperations::List
6
+
7
+ OBJECT_NAME = "connection".freeze
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class CredentialConnection < APIResource
5
+ extend Telnyx::APIOperations::List
6
+ extend Telnyx::APIOperations::Create
7
+ include Telnyx::APIOperations::Save
8
+ include Telnyx::APIOperations::Delete
9
+
10
+ OBJECT_NAME = "credential_connection".freeze
11
+ end
12
+ end
data/lib/telnyx/fax.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class Fax < APIResource
5
+ extend Telnyx::APIOperations::List
6
+ extend Telnyx::APIOperations::Create
7
+ include Telnyx::APIOperations::Delete
8
+ include Telnyx::APIOperations::Save
9
+
10
+ OBJECT_NAME = "fax".freeze
11
+ RESOURCE_PATH = "faxes".freeze
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class FaxApplication < APIResource
5
+ extend Telnyx::APIOperations::List
6
+ extend Telnyx::APIOperations::Create
7
+ include Telnyx::APIOperations::Delete
8
+ include Telnyx::APIOperations::Save
9
+
10
+ OBJECT_NAME = "fax_application".freeze
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class FQDN < APIResource
5
+ extend Telnyx::APIOperations::List
6
+ extend Telnyx::APIOperations::Create
7
+ include Telnyx::APIOperations::Delete
8
+ include Telnyx::APIOperations::Save
9
+
10
+ OBJECT_NAME = "fqdn".freeze
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class FQDNConnection < APIResource
5
+ extend Telnyx::APIOperations::List
6
+ extend Telnyx::APIOperations::Create
7
+ include Telnyx::APIOperations::Delete
8
+ include Telnyx::APIOperations::Save
9
+
10
+ OBJECT_NAME = "fqdn_connection".freeze
11
+ end
12
+ end
data/lib/telnyx/ip.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class IP < APIResource
5
+ extend Telnyx::APIOperations::List
6
+ extend Telnyx::APIOperations::Create
7
+ include Telnyx::APIOperations::Delete
8
+ include Telnyx::APIOperations::Save
9
+
10
+ OBJECT_NAME = "ip".freeze
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class IPConnection < APIResource
5
+ extend APIOperations::List
6
+ extend APIOperations::Create
7
+ include APIOperations::Delete
8
+ include APIOperations::Save
9
+
10
+ OBJECT_NAME = "ip_connection".freeze
11
+ end
12
+ end
@@ -59,23 +59,6 @@ module Telnyx
59
59
  end
60
60
  end
61
61
 
62
- # Iterates through each resource in all pages, making additional fetches to
63
- # the API as necessary.
64
- #
65
- # Note that this method will make as many API calls as necessary to fetch
66
- # all resources. For more granular control, please see +each+ and
67
- # +next_page_by_token+.
68
- def auto_paging_each_by_token(&blk)
69
- return enum_for(:auto_paging_each_by_token) unless block_given?
70
-
71
- page = self
72
- loop do
73
- page.each(&blk)
74
- page = page.next_page_by_token
75
- break if page.empty?
76
- end
77
- end
78
-
79
62
  # Returns true if the page object contains no elements.
80
63
  def empty?
81
64
  data.empty?
@@ -98,15 +81,7 @@ module Telnyx
98
81
  def next_page(params = {}, opts = {})
99
82
  return self.class.empty_list(opts) unless more?
100
83
  next_page_number = page_number.to_i + 1
101
- pagination = { number: next_page_number, size: page_size(filters) }
102
- params = filters.merge(params).merge(page: pagination)
103
-
104
- list(params, opts)
105
- end
106
-
107
- def next_page_by_token(params = {}, opts = {})
108
- return self.class.empty_list(opts) unless token
109
- pagination = { token: token }
84
+ pagination = { number: next_page_number, size: filter_page_size }
110
85
  params = filters.merge(params).merge(page: pagination)
111
86
 
112
87
  list(params, opts)
@@ -119,37 +94,48 @@ module Telnyx
119
94
  def previous_page(params = {}, opts = {})
120
95
  prev_page_number = page_number.to_i - 1
121
96
  prev_page_number = [prev_page_number, 1].max
122
- pagination = { number: prev_page_number, size: page_size(filters) }
97
+ pagination = { number: prev_page_number, size: filter_page_size }
123
98
  params = filters.merge(params).merge(page: pagination)
124
99
 
125
100
  list(params, opts)
126
101
  end
127
102
 
128
- # Fetch the current page size
129
- def page_size(params)
130
- if params && params[:page] && params[:page][:size]
131
- params[:page][:size]
132
- else
133
- 20
134
- end
103
+ # Fetch the current page size from metadata.
104
+ def page_size
105
+ from_meta(:page_size, 20)
135
106
  end
136
107
 
137
- # Fetch the current page number
108
+ # Fetch the current page number from metadata.
138
109
  def page_number
139
- if meta && meta[:page_number]
140
- meta.page_number
141
- else
142
- 1
143
- end
144
- end
145
-
146
- def token
147
- return meta.next_page_token if meta && meta[:next_page_token]
110
+ from_meta(:page_number, 1)
148
111
  end
149
112
 
150
113
  def resource_url
151
114
  url ||
152
115
  raise(ArgumentError, "List object does not contain a 'url' field.")
153
116
  end
117
+
118
+ private
119
+
120
+ # Determine page size from filters
121
+ def filter_page_size
122
+ if filters && filters[:page] && filters[:page][:size]
123
+ filters[:page][:size]
124
+ else
125
+ 20
126
+ end
127
+ end
128
+
129
+ # Fetches `attribute` from current page metada. If it's not found returns
130
+ # `default`, which defaults to `nil`.
131
+ def from_meta(attribute, default = nil)
132
+ attribute = attribute.to_sym
133
+
134
+ if meta && meta[attribute]
135
+ meta.public_send(attribute)
136
+ else
137
+ default
138
+ end
139
+ end
154
140
  end
155
141
  end
@@ -5,6 +5,15 @@ module Telnyx
5
5
  include Telnyx::APIOperations::Save
6
6
  extend Telnyx::APIOperations::List
7
7
 
8
+ def initialize(*)
9
+ super
10
+ warn "[DEPRECATION] MessagingPhoneNumber is deprecated, use PhoneNumber instead"
11
+ end
12
+
8
13
  OBJECT_NAME = "messaging_phone_number".freeze
14
+ def self.resource_path(id = nil)
15
+ return "phone_numbers/#{CGI.escape(id)}/messaging" if id
16
+ "phone_numbers/messaging"
17
+ end
9
18
  end
10
19
  end
@@ -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
@@ -13,8 +13,11 @@ module Telnyx
13
13
  instance_methods: { list: "voice" }
14
14
  nested_resource_class_methods "messaging",
15
15
  path: ["messaging"],
16
- operations: %i[update list],
16
+ operations: %i[update list retrieve],
17
17
  instance_methods: { list: "messaging" }
18
+ nested_resource_class_methods "inbound_channel",
19
+ path: ["inbound_channels"],
20
+ operations: %i[update list]
18
21
 
19
22
  def update_messaging(opts)
20
23
  self.class.update_messaging(id, nil, opts)
@@ -24,6 +27,22 @@ module Telnyx
24
27
  self.class.update_voice(id, nil, opts)
25
28
  end
26
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
+ def self.messaging
43
+ list_messagings(nil)
44
+ end
45
+
27
46
  OBJECT_NAME = "phone_number".freeze
28
47
  end
29
48
  end
@@ -0,0 +1,10 @@
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
+ RESOURCE_PATH = "phone_numbers_regulatory_requirements".freeze
9
+ end
10
+ 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
@@ -6,7 +6,7 @@ module Telnyx
6
6
  extend APIOperations::NestedResource
7
7
  extend APIOperations::List
8
8
 
9
- ACTIONS = %w[deactivate activate].freeze
9
+ ACTIONS = %w[enable disable].freeze
10
10
  ACTIONS.each do |action|
11
11
  nested_resource_class_methods action,
12
12
  path: %W[actions #{action}],
@@ -20,5 +20,16 @@ module Telnyx
20
20
  end
21
21
 
22
22
  OBJECT_NAME = "sim_card".freeze
23
+
24
+ # depreciated api
25
+ def activate
26
+ warn "[DEPRECATION] SimCard#activate is deprecated, use enable instead."
27
+ enable
28
+ end
29
+
30
+ def deactivate
31
+ warn "[DEPRECATION] SimCard#deactivate is deprecated, use enable instead."
32
+ disable
33
+ end
23
34
  end
24
35
  end