twilio-ruby 3.11.5 → 4.0.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 +13 -5
- data/.gitignore +1 -1
- data/.travis.yml +20 -9
- data/AUTHORS.md +32 -25
- data/CHANGES.md +203 -0
- data/Gemfile +8 -1
- data/{LICENSE → LICENSE.md} +4 -2
- data/Makefile +1 -2
- data/README.md +70 -39
- data/Rakefile +8 -10
- data/docs/faq.rst +3 -3
- data/docs/getting-started.rst +17 -12
- data/docs/index.rst +15 -0
- data/docs/usage/accounts.rst +6 -6
- data/docs/usage/addresses.rst +101 -0
- data/docs/usage/applications.rst +10 -10
- data/docs/usage/basics.rst +17 -4
- data/docs/usage/caller-ids.rst +4 -2
- data/docs/usage/conferences.rst +11 -11
- data/docs/usage/errors.rst +7 -7
- data/docs/usage/messages.rst +48 -20
- data/docs/usage/notifications.rst +6 -4
- data/docs/usage/phone-calls.rst +33 -14
- data/docs/usage/phone-numbers.rst +45 -31
- data/docs/usage/queues.rst +8 -8
- data/docs/usage/recordings.rst +12 -10
- data/docs/usage/sip.rst +15 -14
- data/docs/usage/taskrouter-tokens.rst +98 -0
- data/docs/usage/taskrouter.rst +226 -0
- data/docs/usage/token-generation.rst +19 -4
- data/docs/usage/transcriptions.rst +3 -2
- data/docs/usage/twiml.rst +7 -7
- data/docs/usage/validation.rst +39 -3
- data/examples/examples.rb +44 -20
- data/examples/print-call-log.rb +1 -1
- data/lib/rack/twilio_webhook_authentication.rb +47 -0
- data/lib/twilio-ruby/rest/accounts.rb +2 -1
- data/lib/twilio-ruby/rest/addresses/dependent_phone_numbers.rb +6 -0
- data/lib/twilio-ruby/rest/addresses.rb +12 -0
- data/lib/twilio-ruby/rest/base_client.rb +127 -0
- data/lib/twilio-ruby/rest/call_feedback.rb +28 -0
- data/lib/twilio-ruby/rest/call_feedback_summary.rb +13 -0
- data/lib/twilio-ruby/rest/calls.rb +10 -5
- data/lib/twilio-ruby/rest/client.rb +44 -109
- data/lib/twilio-ruby/rest/conferences/participants.rb +2 -2
- data/lib/twilio-ruby/rest/incoming_phone_numbers.rb +1 -1
- data/lib/twilio-ruby/rest/instance_resource.rb +2 -16
- data/lib/twilio-ruby/rest/list_resource.rb +20 -30
- data/lib/twilio-ruby/rest/lookups/phone_numbers.rb +17 -0
- data/lib/twilio-ruby/rest/lookups_client.rb +99 -0
- data/lib/twilio-ruby/rest/messages.rb +5 -0
- data/lib/twilio-ruby/rest/next_gen_list_resource.rb +36 -0
- data/lib/twilio-ruby/rest/outgoing_caller_ids.rb +1 -1
- data/lib/twilio-ruby/rest/queues/members.rb +1 -1
- data/lib/twilio-ruby/rest/sip.rb +1 -3
- data/lib/twilio-ruby/rest/sms/messages.rb +23 -0
- data/lib/twilio-ruby/rest/task_router/activities.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/events.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/reservations.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/statistics.rb +26 -0
- data/lib/twilio-ruby/rest/task_router/task_queues.rb +17 -0
- data/lib/twilio-ruby/rest/task_router/task_queues_statistics.rb +15 -0
- data/lib/twilio-ruby/rest/task_router/tasks.rb +15 -0
- data/lib/twilio-ruby/rest/task_router/workers.rb +13 -0
- data/lib/twilio-ruby/rest/task_router/workers_statistics.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/workflow_statistics.rb +7 -0
- data/lib/twilio-ruby/rest/task_router/workflows.rb +11 -0
- data/lib/twilio-ruby/rest/task_router/workspace_statistics.rb +7 -0
- data/lib/twilio-ruby/rest/task_router/workspaces.rb +17 -0
- data/lib/twilio-ruby/rest/task_router_client.rb +176 -0
- data/lib/twilio-ruby/rest/tokens.rb +7 -0
- data/lib/twilio-ruby/rest/usage/records.rb +2 -2
- data/lib/twilio-ruby/rest/utils.rb +35 -11
- data/lib/twilio-ruby/task_router/capability.rb +87 -0
- data/lib/twilio-ruby/task_router.rb +0 -0
- data/lib/twilio-ruby/twiml/response.rb +1 -0
- data/lib/twilio-ruby/util/capability.rb +10 -7
- data/lib/twilio-ruby/util/client_config.rb +29 -0
- data/lib/twilio-ruby/util/configuration.rb +7 -0
- data/lib/twilio-ruby/util/request_validator.rb +18 -3
- data/lib/twilio-ruby/version.rb +1 -1
- data/lib/twilio-ruby.rb +48 -0
- data/spec/rack/twilio_webhook_authentication_spec.rb +110 -0
- data/spec/rest/account_spec.rb +51 -20
- data/spec/rest/address_spec.rb +11 -0
- data/spec/rest/call_feedback_spec.rb +12 -0
- data/spec/rest/call_feedback_summary_spec.rb +9 -0
- data/spec/rest/call_spec.rb +8 -4
- data/spec/rest/client_spec.rb +209 -51
- data/spec/rest/conference_spec.rb +4 -2
- data/spec/rest/instance_resource_spec.rb +4 -4
- data/spec/rest/lookups/phone_number_spec.rb +8 -0
- data/spec/rest/message_spec.rb +2 -2
- data/spec/rest/numbers_spec.rb +25 -13
- data/spec/rest/queue_spec.rb +4 -2
- data/spec/rest/recording_spec.rb +4 -2
- data/spec/rest/sms/message_spec.rb +37 -0
- data/spec/rest/sms/messages_spec.rb +31 -0
- data/spec/rest/task_router/reservation_spec.rb +9 -0
- data/spec/rest/task_router/task_queue_spec.rb +9 -0
- data/spec/rest/token_spec.rb +7 -0
- data/spec/rest/utils_spec.rb +45 -0
- data/spec/spec_helper.rb +12 -3
- data/spec/support/fakeweb.rb +2 -0
- data/spec/task_router_spec.rb +114 -0
- data/spec/twilio_spec.rb +15 -0
- data/spec/util/capability_spec.rb +167 -118
- data/spec/util/client_config_spec.rb +21 -0
- data/spec/util/configuration_spec.rb +15 -0
- data/spec/util/request_validator_spec.rb +31 -3
- data/spec/util/url_encode_spec.rb +2 -2
- data/twilio-ruby.gemspec +28 -27
- metadata +93 -71
- data/CHANGES +0 -47
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'twilio-ruby/rest/base_client'
|
|
1
2
|
module Twilio
|
|
2
3
|
module REST
|
|
3
4
|
##
|
|
@@ -28,6 +29,12 @@ module Twilio
|
|
|
28
29
|
#
|
|
29
30
|
# @client.account.calls
|
|
30
31
|
#
|
|
32
|
+
# For convenience, the resources of the default account are also available
|
|
33
|
+
# on the client object. So the following call is equivalent to the example
|
|
34
|
+
# above
|
|
35
|
+
#
|
|
36
|
+
# @client.calls
|
|
37
|
+
#
|
|
31
38
|
# represents an account's call list.
|
|
32
39
|
#
|
|
33
40
|
# ==== @client.accounts
|
|
@@ -41,75 +48,51 @@ module Twilio
|
|
|
41
48
|
# methods like ListResource#list to return a (possibly filtered) list of
|
|
42
49
|
# accounts and ListResource#create to create a new account. Use
|
|
43
50
|
# ListResource#get to grab a particular account once you know its sid.
|
|
44
|
-
class Client
|
|
45
|
-
include Twilio::Util
|
|
46
|
-
include Twilio::REST::Utils
|
|
47
|
-
|
|
51
|
+
class Client < BaseClient
|
|
48
52
|
API_VERSION = '2010-04-01'
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
engine = !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
|
|
52
|
-
|
|
53
|
-
HTTP_HEADERS = {
|
|
54
|
-
'Accept' => 'application/json',
|
|
55
|
-
'Accept-Charset' => 'utf-8',
|
|
56
|
-
'User-Agent' => "twilio-ruby/#{Twilio::VERSION} (#{engine}/#{RUBY_PLATFORM} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})",
|
|
57
|
-
}
|
|
54
|
+
attr_reader :account, :accounts
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
:host => 'api.twilio.com',
|
|
61
|
-
:port => 443,
|
|
62
|
-
:use_ssl => true,
|
|
63
|
-
:ssl_verify_peer => true,
|
|
64
|
-
:ssl_ca_file => File.dirname(__FILE__) + '/../../../conf/cacert.pem',
|
|
65
|
-
:timeout => 30,
|
|
66
|
-
:proxy_addr => nil,
|
|
67
|
-
:proxy_port => nil,
|
|
68
|
-
:proxy_user => nil,
|
|
69
|
-
:proxy_pass => nil,
|
|
70
|
-
:retry_limit => 1,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
attr_reader :account_sid, :account, :accounts, :last_request,
|
|
74
|
-
:last_response
|
|
56
|
+
host 'api.twilio.com'
|
|
75
57
|
|
|
76
58
|
##
|
|
77
59
|
# Instantiate a new HTTP client to talk to Twilio. The parameters
|
|
78
|
-
# +account_sid+ and +auth_token+ are required
|
|
60
|
+
# +account_sid+ and +auth_token+ are required, unless you have configured
|
|
61
|
+
# them already using the block configure syntax, and used to generate the
|
|
79
62
|
# HTTP basic auth header in each request. The +options+ parameter is a
|
|
80
63
|
# hash of connection configuration options. the following keys are
|
|
81
64
|
# supported:
|
|
82
65
|
#
|
|
83
|
-
# === <tt
|
|
66
|
+
# === <tt>host: 'api.twilio.com'</tt>
|
|
84
67
|
#
|
|
85
68
|
# The domain to which you'd like the client to make HTTP requests. Useful
|
|
86
69
|
# for testing. Defaults to 'api.twilio.com'.
|
|
87
70
|
#
|
|
88
|
-
# === <tt
|
|
71
|
+
# === <tt>port: 443</tt>
|
|
89
72
|
#
|
|
90
73
|
# The port on which to connect to the above domain. Defaults to 443 and
|
|
91
74
|
# should be left that way except in testing environments.
|
|
92
75
|
#
|
|
93
|
-
# === <tt
|
|
76
|
+
# === <tt>use_ssl: true</tt>
|
|
94
77
|
#
|
|
95
78
|
# Declare whether ssl should be used for connections to the above domain.
|
|
96
79
|
# Defaults to true and should be left alone except when testing.
|
|
97
80
|
#
|
|
98
|
-
# === <tt
|
|
81
|
+
# === <tt>ssl_verify_peer: true</tt>
|
|
99
82
|
#
|
|
100
83
|
# Declare whether to verify the host's ssl cert when setting up the
|
|
101
84
|
# connection to the above domain. Defaults to true, but can be turned off
|
|
102
85
|
# to avoid ssl certificate verification failures in environments without
|
|
103
86
|
# the necessary ca certificates.
|
|
104
87
|
#
|
|
105
|
-
# === <tt
|
|
88
|
+
# === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
|
|
106
89
|
#
|
|
107
90
|
# Specify the path to the certificate authority bundle you'd like to use
|
|
108
91
|
# to verify Twilio's SSL certificate on each request. If not specified, a
|
|
109
92
|
# certificate bundle extraced from Firefox is packaged with the gem and
|
|
110
93
|
# used by default.
|
|
111
94
|
#
|
|
112
|
-
# === <tt
|
|
95
|
+
# === <tt>timeout: 30</tt>
|
|
113
96
|
#
|
|
114
97
|
# Set the time in seconds to wait before timing out the HTTP request.
|
|
115
98
|
# Defaults to 30 seconds. If you aren't fetching giant pages of call or
|
|
@@ -117,32 +100,29 @@ module Twilio
|
|
|
117
100
|
# lower. In paricular if you are sending SMS you can set this to 1 second
|
|
118
101
|
# or less and swallow the exception if you don't care about the response.
|
|
119
102
|
#
|
|
120
|
-
# === <tt
|
|
103
|
+
# === <tt>proxy_addr: 'proxy.host.domain'</tt>
|
|
121
104
|
#
|
|
122
105
|
# The domain of a proxy through which you'd like the client to make HTTP
|
|
123
106
|
# requests. Defaults to nil.
|
|
124
107
|
#
|
|
125
|
-
# === <tt
|
|
108
|
+
# === <tt>proxy_port: 3128</tt>
|
|
126
109
|
#
|
|
127
110
|
# The port on which to connect to the above proxy. Defaults to nil.
|
|
128
111
|
#
|
|
129
|
-
# === <tt
|
|
112
|
+
# === <tt>proxy_user: 'username'</tt>
|
|
130
113
|
#
|
|
131
114
|
# The user name to use for authentication with the proxy. Defaults to nil.
|
|
132
115
|
#
|
|
133
|
-
# === <tt
|
|
116
|
+
# === <tt>proxy_pass: 'password'</tt>
|
|
134
117
|
#
|
|
135
118
|
# The password to use for authentication with the proxy. Defaults to nil.
|
|
136
119
|
#
|
|
137
|
-
# === <tt
|
|
120
|
+
# === <tt>retry_limit: 1</tt>
|
|
138
121
|
#
|
|
139
122
|
# The number of times to retry a request that has failed before throwing
|
|
140
123
|
# an exception. Defaults to one.
|
|
141
|
-
def initialize(
|
|
142
|
-
|
|
143
|
-
@config = DEFAULTS.merge! options
|
|
144
|
-
set_up_connection
|
|
145
|
-
set_up_subresources
|
|
124
|
+
def initialize(*args)
|
|
125
|
+
super(*args)
|
|
146
126
|
end
|
|
147
127
|
|
|
148
128
|
def inspect # :nodoc:
|
|
@@ -150,52 +130,27 @@ module Twilio
|
|
|
150
130
|
end
|
|
151
131
|
|
|
152
132
|
##
|
|
153
|
-
#
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
unless args[1] # build the full path unless already given
|
|
162
|
-
path = "#{path}.json"
|
|
163
|
-
path << "?#{url_encode(params)}" if method == :get && !params.empty?
|
|
164
|
-
end
|
|
165
|
-
request = method_class.new path, HTTP_HEADERS
|
|
166
|
-
request.basic_auth @account_sid, @auth_token
|
|
167
|
-
request.form_data = params if [:post, :put].include? method
|
|
168
|
-
connect_and_send request
|
|
133
|
+
# Delegate account methods from the client. This saves having to call
|
|
134
|
+
# <tt>client.account</tt> every time for resources on the default
|
|
135
|
+
# account.
|
|
136
|
+
def method_missing(method_name, *args, &block)
|
|
137
|
+
if account.respond_to?(method_name)
|
|
138
|
+
account.send(method_name, *args, &block)
|
|
139
|
+
else
|
|
140
|
+
super
|
|
169
141
|
end
|
|
170
142
|
end
|
|
171
143
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
# Set up and cache a Net::HTTP object to use when making requests. This is
|
|
176
|
-
# a private method documented for completeness.
|
|
177
|
-
def set_up_connection # :doc:
|
|
178
|
-
connection_class = Net::HTTP::Proxy @config[:proxy_addr],
|
|
179
|
-
@config[:proxy_port], @config[:proxy_user], @config[:proxy_pass]
|
|
180
|
-
@connection = connection_class.new @config[:host], @config[:port]
|
|
181
|
-
set_up_ssl
|
|
182
|
-
@connection.open_timeout = @config[:timeout]
|
|
183
|
-
@connection.read_timeout = @config[:timeout]
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
##
|
|
187
|
-
# Set up the ssl properties of the <tt>@connection</tt> Net::HTTP object.
|
|
188
|
-
# This is a private method documented for completeness.
|
|
189
|
-
def set_up_ssl # :doc:
|
|
190
|
-
@connection.use_ssl = @config[:use_ssl]
|
|
191
|
-
if @config[:ssl_verify_peer]
|
|
192
|
-
@connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
193
|
-
@connection.ca_file = @config[:ssl_ca_file]
|
|
144
|
+
def respond_to?(method_name, include_private=false)
|
|
145
|
+
if account.respond_to?(method_name, include_private)
|
|
146
|
+
true
|
|
194
147
|
else
|
|
195
|
-
|
|
148
|
+
super
|
|
196
149
|
end
|
|
197
150
|
end
|
|
198
151
|
|
|
152
|
+
protected
|
|
153
|
+
|
|
199
154
|
##
|
|
200
155
|
# Set up +account+ and +accounts+ attributes.
|
|
201
156
|
def set_up_subresources # :doc:
|
|
@@ -204,31 +159,11 @@ module Twilio
|
|
|
204
159
|
end
|
|
205
160
|
|
|
206
161
|
##
|
|
207
|
-
#
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
def connect_and_send(request) # :doc:
|
|
213
|
-
@last_request = request
|
|
214
|
-
retries_left = @config[:retry_limit]
|
|
215
|
-
begin
|
|
216
|
-
response = @connection.request request
|
|
217
|
-
@last_response = response
|
|
218
|
-
if response.kind_of? Net::HTTPServerError
|
|
219
|
-
raise Twilio::REST::ServerError
|
|
220
|
-
end
|
|
221
|
-
rescue Exception
|
|
222
|
-
raise if request.class == Net::HTTP::Post
|
|
223
|
-
if retries_left > 0 then retries_left -= 1; retry else raise end
|
|
224
|
-
end
|
|
225
|
-
if response.body and !response.body.empty?
|
|
226
|
-
object = MultiJson.load response.body
|
|
227
|
-
end
|
|
228
|
-
if response.kind_of? Net::HTTPClientError
|
|
229
|
-
raise Twilio::REST::RequestError.new object['message'], object['code']
|
|
230
|
-
end
|
|
231
|
-
object
|
|
162
|
+
# Builds up full request path
|
|
163
|
+
def build_full_path(path, params, method)
|
|
164
|
+
path = "#{path}.json"
|
|
165
|
+
path << "?#{url_encode(params)}" if method == :get && !params.empty?
|
|
166
|
+
path
|
|
232
167
|
end
|
|
233
168
|
end
|
|
234
169
|
end
|
|
@@ -32,7 +32,7 @@ module Twilio
|
|
|
32
32
|
# to handle the update. For example, to update the +VoiceUrl+ of a Twilio
|
|
33
33
|
# Application you could write:
|
|
34
34
|
#
|
|
35
|
-
# @app.update :
|
|
35
|
+
# @app.update voice_url: 'http://my.other.app.com/handle_voice'
|
|
36
36
|
#
|
|
37
37
|
# After returning, the object will contain the most recent state of the
|
|
38
38
|
# instance resource, including the newly updated properties.
|
|
@@ -77,25 +77,11 @@ module Twilio
|
|
|
77
77
|
hash.each do |p,v|
|
|
78
78
|
property = detwilify p
|
|
79
79
|
unless ['client', 'updated'].include? property
|
|
80
|
-
eigenclass.send :define_method, property.to_sym, &lambda {v}
|
|
80
|
+
eigenclass.send :define_method, property.to_sym, &lambda { v }
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
@updated = !hash.keys.empty?
|
|
84
84
|
end
|
|
85
|
-
|
|
86
|
-
def resource(*resources)
|
|
87
|
-
custom_resource_names = {:sms => 'SMS', :sip => 'SIP'}
|
|
88
|
-
resources.each do |r|
|
|
89
|
-
resource = twilify r
|
|
90
|
-
relative_path = custom_resource_names.fetch(r, resource)
|
|
91
|
-
path = "#{@path}/#{relative_path}"
|
|
92
|
-
enclosing_module = @submodule == nil ? (Twilio::REST) : (Twilio::REST.const_get(@submodule))
|
|
93
|
-
resource_class = enclosing_module.const_get resource
|
|
94
|
-
instance_variable_set("@#{r}", resource_class.new(path, @client))
|
|
95
|
-
end
|
|
96
|
-
self.class.instance_eval {attr_reader *resources}
|
|
97
|
-
end
|
|
98
|
-
|
|
99
85
|
end
|
|
100
86
|
end
|
|
101
87
|
end
|
|
@@ -3,9 +3,14 @@ module Twilio
|
|
|
3
3
|
class ListResource
|
|
4
4
|
include Utils
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
def initialize(path, client)
|
|
8
|
-
custom_names = {
|
|
7
|
+
custom_names = {
|
|
8
|
+
'Activities' => 'Activity',
|
|
9
|
+
'Media' => 'MediaInstance',
|
|
10
|
+
'IpAddresses' => 'IpAddress',
|
|
11
|
+
'Feedback' => 'FeedbackInstance',
|
|
12
|
+
'Addresses' => 'Address'
|
|
13
|
+
}
|
|
9
14
|
@path, @client = path, client
|
|
10
15
|
resource_name = self.class.name.split('::')[-1]
|
|
11
16
|
instance_name = custom_names.fetch(resource_name, resource_name.chop)
|
|
@@ -13,7 +18,11 @@ module Twilio
|
|
|
13
18
|
# The next line grabs the enclosing module. Necessary for resources
|
|
14
19
|
# contained in their own submodule like /SMS/Messages
|
|
15
20
|
parent_module = self.class.to_s.split('::')[-2]
|
|
16
|
-
full_module_path = parent_module == "REST"
|
|
21
|
+
full_module_path = if parent_module == "REST"
|
|
22
|
+
Twilio::REST
|
|
23
|
+
else
|
|
24
|
+
Twilio::REST.const_get parent_module
|
|
25
|
+
end
|
|
17
26
|
|
|
18
27
|
@instance_class = full_module_path.const_get instance_name
|
|
19
28
|
@list_key, @instance_id_key = detwilify(resource_name), 'sid'
|
|
@@ -42,11 +51,17 @@ module Twilio
|
|
|
42
51
|
@instance_class.new "#{path}/#{resource[@instance_id_key]}", @client,
|
|
43
52
|
resource
|
|
44
53
|
end
|
|
45
|
-
# set the +
|
|
54
|
+
# set the +previous_page+ and +next_page+ properties on the array
|
|
46
55
|
client, list_class = @client, self.class
|
|
47
56
|
resource_list.instance_eval do
|
|
48
57
|
eigenclass = class << self; self; end
|
|
49
|
-
eigenclass.send :define_method, :
|
|
58
|
+
eigenclass.send :define_method, :previous_page, &lambda {
|
|
59
|
+
if response['previous_page_uri']
|
|
60
|
+
list_class.new(response['previous_page_uri'], client).list({}, true)
|
|
61
|
+
else
|
|
62
|
+
[]
|
|
63
|
+
end
|
|
64
|
+
}
|
|
50
65
|
eigenclass.send :define_method, :next_page, &lambda {
|
|
51
66
|
if response['next_page_uri']
|
|
52
67
|
list_class.new(response['next_page_uri'], client).list({}, true)
|
|
@@ -58,18 +73,6 @@ module Twilio
|
|
|
58
73
|
resource_list
|
|
59
74
|
end
|
|
60
75
|
|
|
61
|
-
##
|
|
62
|
-
# Ask Twilio for the total number of items in the list.
|
|
63
|
-
# Calling this method makes an HTTP GET request to <tt>@path</tt> with a
|
|
64
|
-
# page size parameter of 1 to minimize data over the wire while still
|
|
65
|
-
# obtaining the total. Don't use this if you are planning to
|
|
66
|
-
# call #list anyway, since the array returned from #list will have a
|
|
67
|
-
# +total+ attribute as well.
|
|
68
|
-
def total
|
|
69
|
-
raise "Can't get a resource total without a REST Client" unless @client
|
|
70
|
-
@client.get(@path, :page_size => 1)['total']
|
|
71
|
-
end
|
|
72
|
-
|
|
73
76
|
##
|
|
74
77
|
# Return an empty instance resource object with the proper path. Note that
|
|
75
78
|
# this will never raise a Twilio::REST::RequestError on 404 since no HTTP
|
|
@@ -92,19 +95,6 @@ module Twilio
|
|
|
92
95
|
@instance_class.new "#{@path}/#{response[@instance_id_key]}", @client,
|
|
93
96
|
response
|
|
94
97
|
end
|
|
95
|
-
|
|
96
|
-
def resource(*resources)
|
|
97
|
-
custom_resource_names = {:sms => 'SMS', :sip => 'SIP'}
|
|
98
|
-
resources.each do |r|
|
|
99
|
-
resource = twilify r
|
|
100
|
-
relative_path = custom_resource_names.fetch(r, resource)
|
|
101
|
-
path = "#{@path}/#{relative_path}"
|
|
102
|
-
enclosing_module = @submodule == nil ? (Twilio::REST) : (Twilio::REST.const_get(@submodule))
|
|
103
|
-
resource_class = enclosing_module.const_get resource
|
|
104
|
-
instance_variable_set("@#{r}", resource_class.new(path, @client))
|
|
105
|
-
end
|
|
106
|
-
self.class.instance_eval {attr_reader *resources}
|
|
107
|
-
end
|
|
108
98
|
end
|
|
109
99
|
end
|
|
110
100
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Twilio
|
|
2
|
+
module REST
|
|
3
|
+
module Lookups
|
|
4
|
+
class PhoneNumbers < Twilio::REST::NextGenListResource;
|
|
5
|
+
include Twilio::Util
|
|
6
|
+
include Twilio::REST::Utils
|
|
7
|
+
|
|
8
|
+
def get(number, query={})
|
|
9
|
+
full_path = "#{@path}/#{number}"
|
|
10
|
+
full_path << "?#{url_encode(twilify(query))}" if !query.empty?
|
|
11
|
+
@instance_class.new full_path, @client
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
class PhoneNumber < InstanceResource; end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
require 'twilio-ruby/rest/base_client'
|
|
2
|
+
module Twilio
|
|
3
|
+
module REST
|
|
4
|
+
class LookupsClient < BaseClient
|
|
5
|
+
API_VERSION = 'v1'
|
|
6
|
+
|
|
7
|
+
attr_reader :phone_numbers
|
|
8
|
+
|
|
9
|
+
host 'lookups.twilio.com'
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Instantiate a new HTTP Lookups client to talk to Twilio. The parameters
|
|
13
|
+
# +account_sid+, +auth_token+ and +workspace_sid are required, unless you
|
|
14
|
+
# have configured them already using the block configure syntax, and used
|
|
15
|
+
# to generate the HTTP basic auth header in each request. The +options+
|
|
16
|
+
# parameter is a hash of connection configuration options. the following
|
|
17
|
+
# keys are supported:
|
|
18
|
+
#
|
|
19
|
+
# === <tt>host: 'lookups.twilio.com'</tt>
|
|
20
|
+
#
|
|
21
|
+
# The domain to which you'd like the client to make HTTP requests. Useful
|
|
22
|
+
# for testing. Defaults to 'lookups.twilio.com'.
|
|
23
|
+
#
|
|
24
|
+
# === <tt>port: 443</tt>
|
|
25
|
+
#
|
|
26
|
+
# The port on which to connect to the above domain. Defaults to 443 and
|
|
27
|
+
# should be left that way except in testing environments.
|
|
28
|
+
#
|
|
29
|
+
# === <tt>use_ssl: true</tt>
|
|
30
|
+
#
|
|
31
|
+
# Declare whether ssl should be used for connections to the above domain.
|
|
32
|
+
# Defaults to true and should be left alone except when testing.
|
|
33
|
+
#
|
|
34
|
+
# === <tt>ssl_verify_peer: true</tt>
|
|
35
|
+
#
|
|
36
|
+
# Declare whether to verify the host's ssl cert when setting up the
|
|
37
|
+
# connection to the above domain. Defaults to true, but can be turned off
|
|
38
|
+
# to avoid ssl certificate verification failures in environments without
|
|
39
|
+
# the necessary ca certificates.
|
|
40
|
+
#
|
|
41
|
+
# === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
|
|
42
|
+
#
|
|
43
|
+
# Specify the path to the certificate authority bundle you'd like to use
|
|
44
|
+
# to verify Twilio's SSL certificate on each request. If not specified, a
|
|
45
|
+
# certificate bundle extraced from Firefox is packaged with the gem and
|
|
46
|
+
# used by default.
|
|
47
|
+
#
|
|
48
|
+
# === <tt>timeout: 30</tt>
|
|
49
|
+
#
|
|
50
|
+
# Set the time in seconds to wait before timing out the HTTP request.
|
|
51
|
+
# Defaults to 30 seconds. If you aren't fetching giant pages of call or
|
|
52
|
+
# SMS logs you can safely decrease this to something like 3 seconds or
|
|
53
|
+
# lower. In paricular if you are sending SMS you can set this to 1 second
|
|
54
|
+
# or less and swallow the exception if you don't care about the response.
|
|
55
|
+
#
|
|
56
|
+
# === <tt>proxy_addr: 'proxy.host.domain'</tt>
|
|
57
|
+
#
|
|
58
|
+
# The domain of a proxy through which you'd like the client to make HTTP
|
|
59
|
+
# requests. Defaults to nil.
|
|
60
|
+
#
|
|
61
|
+
# === <tt>proxy_port: 3128</tt>
|
|
62
|
+
#
|
|
63
|
+
# The port on which to connect to the above proxy. Defaults to nil.
|
|
64
|
+
#
|
|
65
|
+
# === <tt>proxy_user: 'username'</tt>
|
|
66
|
+
#
|
|
67
|
+
# The user name to use for authentication with the proxy. Defaults to nil.
|
|
68
|
+
#
|
|
69
|
+
# === <tt>proxy_pass: 'password'</tt>
|
|
70
|
+
#
|
|
71
|
+
# The password to use for authentication with the proxy. Defaults to nil.
|
|
72
|
+
#
|
|
73
|
+
# === <tt>retry_limit: 1</tt>
|
|
74
|
+
#
|
|
75
|
+
# The number of times to retry a request that has failed before throwing
|
|
76
|
+
# an exception. Defaults to one.
|
|
77
|
+
def inspect # :nodoc:
|
|
78
|
+
"<Twilio::REST::LookupsClient @account_sid=#{@account_sid}>"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
protected
|
|
82
|
+
|
|
83
|
+
##
|
|
84
|
+
# Set up +phone_numbers+ attribute.
|
|
85
|
+
def set_up_subresources # :doc:
|
|
86
|
+
@phone_numbers = Twilio::REST::Lookups::PhoneNumbers.new "/#{API_VERSION}/PhoneNumbers", self
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
##
|
|
90
|
+
# Builds up full request path
|
|
91
|
+
def build_full_path(path, params, method)
|
|
92
|
+
path = path.dup
|
|
93
|
+
path << "?#{url_encode(params)}" if method == :get && !params.empty?
|
|
94
|
+
path
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Twilio
|
|
2
|
+
module REST
|
|
3
|
+
class NextGenListResource < Twilio::REST::ListResource
|
|
4
|
+
def list(params={}, full_path=false)
|
|
5
|
+
raise "Can't get a resource list without a REST Client" unless @client
|
|
6
|
+
response = @client.get @path, params, full_path
|
|
7
|
+
list_key = response['meta']['key']
|
|
8
|
+
raise "Couldn't find a list key in response meta" unless list_key
|
|
9
|
+
resources = response[list_key]
|
|
10
|
+
resource_list = resources.map do |resource|
|
|
11
|
+
@instance_class.new "#{@path}/#{resource[@instance_id_key]}", @client,
|
|
12
|
+
resource
|
|
13
|
+
end
|
|
14
|
+
client, list_class = @client, self.class
|
|
15
|
+
resource_list.instance_eval do
|
|
16
|
+
eigenclass = class << self; self; end
|
|
17
|
+
eigenclass.send :define_method, :next_page, &lambda {
|
|
18
|
+
if response['meta']['next_page_url']
|
|
19
|
+
list_class.new(response['meta']['next_page_url'], client).list({})
|
|
20
|
+
else
|
|
21
|
+
[]
|
|
22
|
+
end
|
|
23
|
+
}
|
|
24
|
+
eigenclass.send :define_method, :previous_page, &lambda {
|
|
25
|
+
if response['meta']['previous_page_url']
|
|
26
|
+
list_class.new(response['meta']['previous_page_url'], client).list({})
|
|
27
|
+
else
|
|
28
|
+
[]
|
|
29
|
+
end
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
resource_list
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/twilio-ruby/rest/sip.rb
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
module Twilio
|
|
2
2
|
module REST
|
|
3
3
|
module SMS
|
|
4
|
+
|
|
5
|
+
module Deprecation
|
|
6
|
+
def deprecate(method_name)
|
|
7
|
+
old_method = "_deprecated_#{method_name}"
|
|
8
|
+
alias_method old_method, method_name
|
|
9
|
+
define_method method_name do |*args, &block|
|
|
10
|
+
warn "[DEPRECATED] SMS Resource is deprecated. Please use Messages (https://www.twilio.com/docs/api/rest/message)"
|
|
11
|
+
send old_method, *args, &block
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
4
16
|
class Messages < ListResource
|
|
17
|
+
extend Deprecation
|
|
18
|
+
|
|
19
|
+
deprecate :list
|
|
20
|
+
deprecate :get
|
|
21
|
+
deprecate :create
|
|
22
|
+
|
|
5
23
|
def initialize(path, client)
|
|
6
24
|
super
|
|
7
25
|
@list_key = 'sms_messages'
|
|
@@ -9,6 +27,11 @@ module Twilio
|
|
|
9
27
|
end
|
|
10
28
|
|
|
11
29
|
class Message < InstanceResource
|
|
30
|
+
extend Deprecation
|
|
31
|
+
|
|
32
|
+
deprecate :update
|
|
33
|
+
deprecate :refresh
|
|
34
|
+
deprecate :delete
|
|
12
35
|
end
|
|
13
36
|
end
|
|
14
37
|
end
|