twilio-ruby 3.5.0 → 3.5.1

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.
@@ -50,6 +50,20 @@ module Twilio
50
50
  'User-Agent' => "twilio-ruby/#{Twilio::VERSION}",
51
51
  }
52
52
 
53
+ DEFAULTS = {
54
+ :host => 'api.twilio.com',
55
+ :port => 443,
56
+ :use_ssl => true,
57
+ :ssl_verify_peer => true,
58
+ :ssl_ca_file => File.dirname(__FILE__) + '/../../../conf/cacert.pem',
59
+ :timeout => 30,
60
+ :proxy_addr => nil,
61
+ :proxy_port => nil,
62
+ :proxy_user => nil,
63
+ :proxy_pass => nil,
64
+ :retry_limit => 1,
65
+ }
66
+
53
67
  attr_reader :account_sid, :account, :accounts, :last_request,
54
68
  :last_response
55
69
 
@@ -113,9 +127,15 @@ module Twilio
113
127
  # === <tt>:proxy_pass => 'password'</tt>
114
128
  #
115
129
  # The password to use for authentication with the proxy. Defaults to nil.
130
+ #
131
+ # === <tt>:retry_limit => 1</tt>
132
+ #
133
+ # The number of times to retry a request that has failed before throwing
134
+ # an exception. Defaults to one.
116
135
  def initialize(account_sid, auth_token, options={})
117
136
  @account_sid, @auth_token = account_sid.strip, auth_token.strip
118
- set_up_connection_from options
137
+ @config = DEFAULTS.merge! options
138
+ set_up_connection
119
139
  set_up_subresources
120
140
  end
121
141
 
@@ -171,6 +191,7 @@ module Twilio
171
191
  raise NotImplementedError, "HTTP #{method} not implemented"
172
192
  end
173
193
 
194
+ req['User-Agent'] = 'twilio-ruby/deprecated'
174
195
  req.basic_auth @account_sid, @auth_token
175
196
  @last_request = req
176
197
  @last_response = @connection.request req
@@ -181,30 +202,23 @@ module Twilio
181
202
  ##
182
203
  # Set up and cache a Net::HTTP object to use when making requests. This is
183
204
  # a private method documented for completeness.
184
- def set_up_connection_from(options={}) # :doc:
185
- config = {:host => 'api.twilio.com', :port => 443, :use_ssl => true,
186
- :ssl_verify_peer => true, :timeout => 30}.merge! options
187
- connection_class = Net::HTTP::Proxy config[:proxy_addr],
188
- config[:proxy_port], config[:proxy_user], config[:proxy_pass]
189
- @connection = connection_class.new config[:host], config[:port]
190
- set_up_ssl_from config
191
- @connection.open_timeout = options[:timeout]
192
- @connection.read_timeout = options[:timeout]
205
+ def set_up_connection # :doc:
206
+ connection_class = Net::HTTP::Proxy @config[:proxy_addr],
207
+ @config[:proxy_port], @config[:proxy_user], @config[:proxy_pass]
208
+ @connection = connection_class.new @config[:host], @config[:port]
209
+ set_up_ssl
210
+ @connection.open_timeout = @config[:timeout]
211
+ @connection.read_timeout = @config[:timeout]
193
212
  end
194
213
 
195
214
  ##
196
215
  # Set up the ssl properties of the <tt>@connection</tt> Net::HTTP object.
197
216
  # This is a private method documented for completeness.
198
- def set_up_ssl_from(config) # :doc:
199
- @connection.use_ssl = config[:use_ssl]
200
- if config[:ssl_verify_peer]
217
+ def set_up_ssl # :doc:
218
+ @connection.use_ssl = @config[:use_ssl]
219
+ if @config[:ssl_verify_peer]
201
220
  @connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
202
- if config[:ssl_ca_file]
203
- @connection.ca_file = config[:ssl_ca_file]
204
- else
205
- conf_dir = File.dirname(__FILE__) + '/../../../conf'
206
- @connection.ca_file = conf_dir + '/cacert.pem'
207
- end
221
+ @connection.ca_file = @config[:ssl_ca_file]
208
222
  else
209
223
  @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
210
224
  end
@@ -227,13 +241,24 @@ module Twilio
227
241
  # inspection later.
228
242
  def connect_and_send(request) # :doc:
229
243
  @last_request = request
230
- response = @connection.request request
231
- @last_response = response
232
- object = MultiJson.decode response.body if response.body
244
+ retries_remaining = @config[:retry_limit]
245
+ begin
246
+ response = @connection.request request
247
+ @last_response = response
248
+ object = MultiJson.decode response.body if response.body
249
+ if response.kind_of? Net::HTTPServerError
250
+ raise Twilio::REST::ServerError, object['message']
251
+ end
252
+ rescue Exception
253
+ if retries_remaining > 0
254
+ retries_remaining -= 1
255
+ retry
256
+ else
257
+ raise
258
+ end
259
+ end
233
260
  if response.kind_of? Net::HTTPClientError
234
261
  raise Twilio::REST::RequestError, object['message']
235
- elsif response.kind_of? Net::HTTPServerError
236
- raise Twilio::REST::ServerError, object['message']
237
262
  end
238
263
  object
239
264
  end
@@ -1,3 +1,3 @@
1
1
  module Twilio
2
- VERSION = '3.5.0'
2
+ VERSION = '3.5.1'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 5
9
- - 0
10
- version: 3.5.0
9
+ - 1
10
+ version: 3.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Benton
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-06 00:00:00 -08:00
18
+ date: 2012-01-21 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency