telnyx 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile +1 -0
- data/README.md +41 -3
- data/VERSION +1 -1
- data/bin/telnyx-console +2 -1
- data/lib/telnyx.rb +17 -2
- data/lib/telnyx/address.rb +12 -0
- data/lib/telnyx/api_operations/list.rb +1 -1
- data/lib/telnyx/api_operations/nested_resource.rb +2 -2
- data/lib/telnyx/api_resource.rb +1 -1
- data/lib/telnyx/billing_group.rb +12 -0
- data/lib/telnyx/call_control_application.rb +12 -0
- data/lib/telnyx/{conferences.rb → conference.rb} +2 -1
- data/lib/telnyx/connection.rb +9 -0
- data/lib/telnyx/credential_connection.rb +12 -0
- data/lib/telnyx/fqdn.rb +12 -0
- data/lib/telnyx/fqdn_connection.rb +12 -0
- data/lib/telnyx/ip.rb +12 -0
- data/lib/telnyx/ip_connection.rb +12 -0
- data/lib/telnyx/list_object.rb +30 -44
- data/lib/telnyx/number_order_document.rb +11 -0
- data/lib/telnyx/outbound_voice_profile.rb +12 -0
- data/lib/telnyx/phone_number.rb +11 -0
- data/lib/telnyx/phone_number_regulatory_requirement.rb +9 -0
- data/lib/telnyx/portout.rb +12 -0
- data/lib/telnyx/regulatory_requirement.rb +9 -0
- data/lib/telnyx/telnyx_client.rb +1 -1
- data/lib/telnyx/util.rb +31 -13
- data/lib/telnyx/version.rb +1 -1
- data/lib/telnyx/wireless_detail_records_report.rb +12 -0
- data/test/telnyx/address_test.rb +67 -0
- data/test/telnyx/alphanumeric_sender_id_test.rb +4 -0
- data/test/telnyx/api_resource_test.rb +14 -5
- data/test/telnyx/billing_group_test.rb +40 -0
- data/test/telnyx/call_control_application_test.rb +42 -0
- data/test/telnyx/{conferences_test.rb → conference_test.rb} +5 -5
- data/test/telnyx/connection_test.rb +28 -0
- data/test/telnyx/credential_connection_test.rb +40 -0
- data/test/telnyx/errors_test.rb +4 -4
- data/test/telnyx/fqdn_connection_test.rb +40 -0
- data/test/telnyx/fqdn_test.rb +40 -0
- data/test/telnyx/ip_connection_test.rb +40 -0
- data/test/telnyx/ip_test.rb +40 -0
- data/test/telnyx/list_object_test.rb +48 -90
- data/test/telnyx/messaging_profile_test.rb +15 -4
- data/test/telnyx/number_order_document_test.rb +35 -0
- data/test/telnyx/outbound_voice_profile_test.rb +67 -0
- data/test/telnyx/phone_number_regulatory_requirement_test.rb +14 -0
- data/test/telnyx/phone_number_test.rb +38 -0
- data/test/telnyx/public_key_test.rb +1 -0
- data/test/telnyx/regulatory_requirement_test.rb +21 -0
- data/test/telnyx/sim_card_test.rb +2 -14
- data/test/telnyx/telnyx_client_test.rb +1 -1
- data/test/telnyx/wireless_detail_records_report_test.rb +57 -0
- data/test/test_helper.rb +1 -1
- metadata +50 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e54e3db4f0d7c7bd342b485ff630439a751068fa6577d31476b2eb5f75899c3
|
4
|
+
data.tar.gz: eab280aea688a37a5adf1acf5d0db3f67229fe1dfca5763eea0ee3e59c703717
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7053eae8654373d08c9ce34cb21ddc2e84934620ad6dc67faccfa1a9c8742e2ae6f00e5c9103e80c999212552a0af1f0a4f00efdf602e28d681e14f9fb712e6
|
7
|
+
data.tar.gz: 1666ac578f02c5fbd0594da8f247d44a26ed206262744e1fd1e4ff39df10ae36ce4f6192ca21e74a2283bbf645d9361a691f998200cc89482bacd2353b001b53
|
data/.travis.yml
CHANGED
@@ -11,7 +11,7 @@ rvm:
|
|
11
11
|
|
12
12
|
matrix:
|
13
13
|
include:
|
14
|
-
- rvm: jruby-
|
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.
|
29
|
+
- TELNYX_MOCK_VERSION=0.8.9
|
30
30
|
|
31
31
|
cache:
|
32
32
|
directories:
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
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
5
|
|
6
6
|
The Telnyx Ruby library provides convenient access to the Telnyx API from
|
7
7
|
applications written in the Ruby language. It includes a pre-defined set of
|
@@ -34,7 +34,7 @@ If you want to build the gem from source:
|
|
34
34
|
|
35
35
|
### Requirements
|
36
36
|
|
37
|
-
* Ruby 2.0
|
37
|
+
* Ruby 2.1.0+
|
38
38
|
|
39
39
|
### Bundler
|
40
40
|
|
@@ -65,6 +65,44 @@ Telnyx::MessagingProfile.list()
|
|
65
65
|
Telnyx::MessagingProfile.retrieve("123")
|
66
66
|
```
|
67
67
|
|
68
|
+
|
69
|
+
### Iterating over a resource
|
70
|
+
|
71
|
+
API resources are paginated and the library comes with a handful of methods to
|
72
|
+
ease dealing with them seemlessly.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# list messaging profiles
|
76
|
+
first_page = Telnyx::MessagingProfile.list()
|
77
|
+
|
78
|
+
# check whether there are more pages to go through
|
79
|
+
if first_page.more?
|
80
|
+
puts("There are still more pages to go.")
|
81
|
+
else
|
82
|
+
puts("This is the last page.")
|
83
|
+
end
|
84
|
+
|
85
|
+
# get current page's size and number
|
86
|
+
first_page.page_size
|
87
|
+
first_page.page_number
|
88
|
+
|
89
|
+
# fetch the next and previous pages
|
90
|
+
second_page = first_page.next_page
|
91
|
+
first_page = second_page.previous_page
|
92
|
+
|
93
|
+
# iterate over the results of a *single page*
|
94
|
+
second_page.each do |messaging_profile|
|
95
|
+
puts(messaging_profile.id)
|
96
|
+
end
|
97
|
+
|
98
|
+
# iterate over *all of the messaging profiles* starting at `first_page`
|
99
|
+
# similar to `each`, but requests subsequent pages as needed
|
100
|
+
first_page.auto_paging_each do |messaging_profile|
|
101
|
+
puts(messaging_profile.id)
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
|
68
106
|
### Configuring a Client
|
69
107
|
|
70
108
|
While a default HTTP client is used by default, it's also possible to have the
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/telnyx-console
CHANGED
data/lib/telnyx.rb
CHANGED
@@ -36,19 +36,34 @@ 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/
|
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_order_document"
|
47
57
|
require "telnyx/number_order"
|
48
58
|
require "telnyx/number_reservation"
|
59
|
+
require "telnyx/outbound_voice_profile"
|
60
|
+
require "telnyx/phone_number_regulatory_requirement"
|
49
61
|
require "telnyx/phone_number"
|
62
|
+
require "telnyx/portout"
|
50
63
|
require "telnyx/public_key"
|
51
|
-
require "telnyx/
|
64
|
+
require "telnyx/regulatory_requirement"
|
65
|
+
require "telnyx/sim_card"
|
66
|
+
require "telnyx/wireless_detail_records_report"
|
52
67
|
|
53
68
|
module Telnyx
|
54
69
|
@app_info = nil
|
@@ -20,8 +20,8 @@ module Telnyx
|
|
20
20
|
|
21
21
|
resource_url_method = :"#{resource}s_url"
|
22
22
|
define_singleton_method(resource_url_method) do |id, nested_id = nil|
|
23
|
-
raise ArgumentError, "id is required" if id.nil?
|
24
|
-
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}"
|
25
25
|
url += "/#{CGI.escape(nested_id)}" unless nested_id.nil?
|
26
26
|
url
|
27
27
|
end
|
data/lib/telnyx/api_resource.rb
CHANGED
@@ -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
|
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,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/fqdn.rb
ADDED
@@ -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
|
data/lib/telnyx/list_object.rb
CHANGED
@@ -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:
|
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:
|
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
|
130
|
-
|
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
|
-
|
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
|
@@ -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
|