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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5bbc50edcbe6c58e9156791b9f5a47b3ca39b6f0232d26cbb684867370d2ce5
4
- data.tar.gz: fe789738cfcf20050f518e2c7dbfa285664b4d1887fa1594d525ae5bf5922eb6
3
+ metadata.gz: 312011d0dba1f1fc11299f526a0d628f40814e7ed43c233f4d9fc5acd5758b5f
4
+ data.tar.gz: 8f3c7bd28ec643dda8ff88d9896fb510bd5fa5832837dc15b5a1692e8efcb365
5
5
  SHA512:
6
- metadata.gz: c96e81e18925c27e272d0fab270b5db295394a0229077c3a26e298a68c42fade4e5d391ed817290bd591682013cd4a934ba29639566d875a316fcccce7bb25a2
7
- data.tar.gz: f955905baf21c295adf7c2efb5accf4e0074104ca0c2ccfe2611b163cb9fdfc2332213dda525d66ab536c23190f0d83bcd3ec063647b5bf1fae60af968cb9dc1
6
+ metadata.gz: d1552a7725c8cfb0da9195f507e3a02ec491c1ab1395358938dddc777c138ca5bf0af084fb1c15c379a71a1ac115f08d8c6fd5a5c9e0938e9e0cf35a8adccdc6
7
+ data.tar.gz: a0dac15edc3a119ec1b049733a679bff27a91fa2740e78b31669a392ddb79185523ff42cda40e7e821dd56cff6ca519ba033bacb3251a8d3ebf434eabb68316d
@@ -11,7 +11,7 @@ rvm:
11
11
 
12
12
  matrix:
13
13
  include:
14
- - rvm: jruby-head
14
+ - rvm: jruby-9.2.11.0
15
15
  jdk: oraclejdk11
16
16
 
17
17
 
@@ -26,7 +26,7 @@ sudo: false
26
26
  env:
27
27
  global:
28
28
  # If changing this number, please also change it in `test/test_helper.rb`.
29
- - TELNYX_MOCK_VERSION=0.4.0
29
+ - TELNYX_MOCK_VERSION=0.8.9
30
30
 
31
31
  cache:
32
32
  directories:
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ gemspec
6
6
 
7
7
  group :development do
8
8
  gem "coveralls", require: false
9
+ gem "faraday", "0.15.4"
9
10
  gem "mocha", "~> 0.13.2"
10
11
  gem "rake"
11
12
  gem "shoulda-context"
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Telnyx Ruby Library
2
2
 
3
- [![Build Status](https://travis-ci.org/team-telnyx/telnyx-ruby.svg?branch=master)](https://travis-ci.org/telnyx/telnyx-ruby)
4
- [![Coverage Status](https://coveralls.io/repos/github/team-telnyx/telnyx-ruby/badge.svg?branch=master)](https://coveralls.io/github/telnyx/telnyx-ruby?branch=master)
3
+ [![Build Status](https://travis-ci.org/team-telnyx/telnyx-ruby.svg?branch=master)](https://travis-ci.org/team-telnyx/telnyx-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/team-telnyx/telnyx-ruby/badge.svg?branch=master)](https://coveralls.io/github/team-telnyx/telnyx-ruby?branch=master)
5
+ [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://joinslack.telnyx.com/)
5
6
 
6
7
  The Telnyx Ruby library provides convenient access to the Telnyx API from
7
8
  applications written in the Ruby language. It includes a pre-defined set of
@@ -34,7 +35,7 @@ If you want to build the gem from source:
34
35
 
35
36
  ### Requirements
36
37
 
37
- * Ruby 2.0+.
38
+ * Ruby 2.1.0+
38
39
 
39
40
  ### Bundler
40
41
 
@@ -65,6 +66,44 @@ Telnyx::MessagingProfile.list()
65
66
  Telnyx::MessagingProfile.retrieve("123")
66
67
  ```
67
68
 
69
+
70
+ ### Iterating over a resource
71
+
72
+ API resources are paginated and the library comes with a handful of methods to
73
+ ease dealing with them seemlessly.
74
+
75
+ ```ruby
76
+ # list messaging profiles
77
+ first_page = Telnyx::MessagingProfile.list()
78
+
79
+ # check whether there are more pages to go through
80
+ if first_page.more?
81
+ puts("There are still more pages to go.")
82
+ else
83
+ puts("This is the last page.")
84
+ end
85
+
86
+ # get current page's size and number
87
+ first_page.page_size
88
+ first_page.page_number
89
+
90
+ # fetch the next and previous pages
91
+ second_page = first_page.next_page
92
+ first_page = second_page.previous_page
93
+
94
+ # iterate over the results of a *single page*
95
+ second_page.each do |messaging_profile|
96
+ puts(messaging_profile.id)
97
+ end
98
+
99
+ # iterate over *all of the messaging profiles* starting at `first_page`
100
+ # similar to `each`, but requests subsequent pages as needed
101
+ first_page.auto_paging_each do |messaging_profile|
102
+ puts(messaging_profile.id)
103
+ end
104
+ ```
105
+
106
+
68
107
  ### Configuring a Client
69
108
 
70
109
  While a default HTTP client is used by default, it's also possible to have the
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.1
@@ -5,7 +5,8 @@
5
5
  require "irb"
6
6
  require "irb/completion"
7
7
 
8
- require "#{::File.dirname(__FILE__)}/../lib/telnyx"
8
+ $LOAD_PATH.unshift File.expand_path("lib")
9
+ require "telnyx"
9
10
 
10
11
  # Config IRB to enable --simple-prompt and auto indent
11
12
  IRB.conf[:PROMPT_MODE] = :SIMPLE
@@ -36,17 +36,35 @@ require "telnyx/api_resource"
36
36
  require "telnyx/singleton_api_resource"
37
37
  require "telnyx/webhook"
38
38
 
39
+ require "telnyx/address"
39
40
  require "telnyx/alphanumeric_sender_id"
40
41
  require "telnyx/available_phone_number"
42
+ require "telnyx/billing_group"
41
43
  require "telnyx/call"
42
- require "telnyx/conferences"
44
+ require "telnyx/conference"
45
+ require "telnyx/connection"
46
+ require "telnyx/call_control_application"
47
+ require "telnyx/credential_connection"
43
48
  require "telnyx/event"
49
+ require "telnyx/fqdn_connection"
50
+ require "telnyx/fqdn"
51
+ require "telnyx/ip_connection"
52
+ require "telnyx/ip"
44
53
  require "telnyx/message"
45
54
  require "telnyx/messaging_phone_number"
46
55
  require "telnyx/messaging_profile"
56
+ require "telnyx/number_lookup"
57
+ require "telnyx/number_order_document"
47
58
  require "telnyx/number_order"
48
59
  require "telnyx/number_reservation"
60
+ require "telnyx/outbound_voice_profile"
61
+ require "telnyx/phone_number_regulatory_requirement"
62
+ require "telnyx/phone_number"
63
+ require "telnyx/portout"
49
64
  require "telnyx/public_key"
65
+ require "telnyx/regulatory_requirement"
66
+ require "telnyx/sim_card"
67
+ require "telnyx/wireless_detail_records_report"
50
68
 
51
69
  module Telnyx
52
70
  @app_info = nil
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telnyx
4
+ class Address < APIResource
5
+ include APIOperations::Delete
6
+ extend APIOperations::List
7
+ extend APIOperations::Create
8
+
9
+ OBJECT_NAME = "address".freeze
10
+ RESOURCE_PATH = "addresses".freeze
11
+ end
12
+ end
@@ -14,7 +14,7 @@ module Telnyx
14
14
  #
15
15
  # just for general cleanliness, remove any paging options
16
16
  obj.filters = filters.dup
17
- obj.filters.delete(:page)
17
+ # obj.filters.delete(:page) # undo this as it interferes with the pagination system...
18
18
 
19
19
  obj
20
20
  end
@@ -6,11 +6,12 @@ module Telnyx
6
6
  # that it's possible to do so from a static context (i.e. without a
7
7
  # pre-existing collection of subresources on the parent).
8
8
  #
9
- # For examle, a transfer gains the static methods for reversals so that the
9
+ # For example, a transfer gains the static methods for reversals so that the
10
10
  # methods `.create_reversal`, `.retrieve_reversal`, `.update_reversal`,
11
11
  # etc. all become available.
12
12
  # rubocop:disable Metrics/AbcSize
13
13
  # rubocop:disable Metrics/MethodLength
14
+ # rubocop:disable Metrics/CyclomaticComplexity
14
15
  module NestedResource
15
16
  def nested_resource_class_methods(resource, path: nil, operations: nil, instance_methods: {})
16
17
  path ||= "#{resource}s"
@@ -19,7 +20,8 @@ module Telnyx
19
20
 
20
21
  resource_url_method = :"#{resource}s_url"
21
22
  define_singleton_method(resource_url_method) do |id, nested_id = nil|
22
- url = "#{resource_url}/#{CGI.escape(id)}/#{path}"
23
+ # raise ArgumentError, "id is required" if id.nil?
24
+ url = id.nil? ? "#{resource_url}/#{path}" : "#{resource_url}/#{CGI.escape(id)}/#{path}"
23
25
  url += "/#{CGI.escape(nested_id)}" unless nested_id.nil?
24
26
  url
25
27
  end
@@ -28,8 +30,19 @@ module Telnyx
28
30
  define_instance_method = lambda do |target_name, operation|
29
31
  return unless instance_methods.keys.include? operation
30
32
 
31
- define_method(instance_methods[operation] || target_name) do |*opts|
32
- self.class.send(target_name, id, *opts)
33
+ case operation
34
+ when :create, :list
35
+ define_method(instance_methods[operation] || target_name) do |*opts|
36
+ self.class.send(target_name, id, *opts)
37
+ end
38
+ when :retrieve
39
+ define_method(instance_methods[operation] || target_name) do |nested_id|
40
+ self.class.send(target_name, id, nested_id)
41
+ end
42
+ when :update, :delete
43
+ define_method(instance_methods[operation] || target_name) do |nested_id, *opts|
44
+ self.class.send(target_name, id, nested_id, *opts)
45
+ end
33
46
  end
34
47
  end
35
48
 
@@ -20,7 +20,7 @@ module Telnyx
20
20
  end
21
21
  # Namespaces are separated in object names with periods (.) and in URLs
22
22
  # with forward slashes (/), so replace the former with the latter.
23
- "/v2/#{self::OBJECT_NAME.downcase.tr('.', '/')}s"
23
+ const_defined?("RESOURCE_PATH") ? "/v2/#{self::RESOURCE_PATH}" : "/v2/#{self::OBJECT_NAME.downcase.tr('.', '/')}s"
24
24
  end
25
25
 
26
26
  # A metaprogramming call that specifies that a field of a resource can be
@@ -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
@@ -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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Telnyx
4
- class Conferences < APIResource
4
+ class Conference < APIResource
5
5
  extend APIOperations::List
6
6
  extend APIOperations::Create
7
7
  extend APIOperations::NestedResource
@@ -16,4 +16,5 @@ module Telnyx
16
16
  end
17
17
  OBJECT_NAME = "conference".freeze
18
18
  end
19
+ Conferences = Conference # Name change without breaking existing code
19
20
  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
@@ -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
@@ -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