twilio-ruby 3.3.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -16,7 +16,7 @@ $ rake gem
16
16
  $ gem install pkg/twilio-ruby-{version}
17
17
  ```
18
18
 
19
- ## Get Started With Client Capability Tokens
19
+ ## Getting Started With Client Capability Tokens
20
20
 
21
21
  If you just need to generate a Capability Token for use with Twilio Client, you
22
22
  can do this:
@@ -45,7 +45,7 @@ capability.allow_client_incoming 'andrew'
45
45
  There is a slightly more detailed document in the
46
46
  [Capability](twilio-ruby/wiki/Capability) section of the wiki.
47
47
 
48
- ## Getting Started with TwiML
48
+ ## Getting Started With TwiML
49
49
 
50
50
  TwiML support is based on the [builder][1] library. You can construct a TwiML
51
51
  response like this:
@@ -78,7 +78,7 @@ This will print the following (except for the whitespace):
78
78
  </Response>
79
79
  ```
80
80
 
81
- ## Getting Started with REST
81
+ ## Getting Started With REST
82
82
 
83
83
  ### Setup Work
84
84
 
@@ -139,7 +139,7 @@ auth_token = '62ea81de3a5b414154eb263595357c69'
139
139
 
140
140
  # buy the first one
141
141
  @number = @numbers[0].phone_number
142
- @account.incoming_phone_numbers.create(:phone_number => @number)
142
+ @client.account.incoming_phone_numbers.create(:phone_number => @number)
143
143
  ```
144
144
 
145
145
  ## More Information
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'rubygems'
2
- require 'rake/gempackagetask'
2
+ require 'rubygems/package_task'
3
3
  require 'rspec/core/rake_task'
4
4
 
5
5
  spec = eval(File.read('twilio-ruby.gemspec'))
6
6
 
7
- Rake::GemPackageTask.new(spec) do |p|
7
+ Gem::PackageTask.new(spec) do |p|
8
8
  p.gem_spec = spec
9
9
  end
10
10
 
data/examples.rb CHANGED
@@ -7,7 +7,13 @@
7
7
 
8
8
  ################ ACCOUNTS ################
9
9
 
10
- # grab an account instance resource (no http request)
10
+ # shortcut to grab your account object (account_sid is inferred from the client's auth credentials)
11
+ @account = @client.account
12
+
13
+ # list your (sub)accounts
14
+ @client.accounts.list
15
+
16
+ # grab an account instance resource if you know the sid (no http request)
11
17
  @account = @client.accounts.get(@account_sid)
12
18
  # http round trip happens here
13
19
  puts @account.friendly_name
@@ -15,18 +21,15 @@ puts @account.friendly_name
15
21
  # update an account's friendly name (only one http request, for the POST)
16
22
  @client.accounts.get(@account_sid).update(:friendly_name => 'A Fabulous Friendly Name')
17
23
 
18
- # shortcut to grab your account object (account_sid is inferred from the client's auth credentials)
19
- @account = @client.account
20
-
21
24
  ################ CALLS ################
22
25
 
23
- # print a list of calls (all parameters optional, single http req)
26
+ # print a list of calls (all parameters optional, single http request)
24
27
  @account.calls.list({:page => 0, :page_size => 1000, :start_time => '2010-09-01'}).each do |call|
25
28
  puts call.sid
26
29
  end
27
30
 
28
- # get a particular call and list its recordings (one http req, for each())
29
- @account.calls.get('CAXXXXXXX').recordings.list.each do {|r| puts r.sid}
31
+ # get a particular call and list its recording urls (one http request for #list)
32
+ @account.calls.get('CAXXXXXXX').recordings.list.each do {|r| puts r.wav}
30
33
 
31
34
  # make a new outgoing call (this is the same type of object we get
32
35
  # from calls.get, except this has attributes since we made an http request)
@@ -61,7 +64,7 @@ puts @account.sms.messages.get('SMXXXXXXXX').body
61
64
 
62
65
  ################ PHONE NUMBERS ################
63
66
 
64
- # get a list of supported country codes (api currently doesn't support this)
67
+ # get a list of supported country codes
65
68
  @account.available_phone_numbers.list
66
69
 
67
70
  # print some available numbers (only one http request)
data/lib/twilio-ruby.rb CHANGED
@@ -23,6 +23,8 @@ require 'twilio-ruby/rest/sms'
23
23
  require 'twilio-ruby/rest/sms/messages'
24
24
  require 'twilio-ruby/rest/sms/short_codes'
25
25
  require 'twilio-ruby/rest/applications'
26
+ require 'twilio-ruby/rest/connect_apps'
27
+ require 'twilio-ruby/rest/authorized_connect_apps'
26
28
  require 'twilio-ruby/rest/outgoing_caller_ids'
27
29
  require 'twilio-ruby/rest/incoming_phone_numbers'
28
30
  require 'twilio-ruby/rest/available_phone_numbers'
@@ -7,7 +7,8 @@ module Twilio
7
7
  super uri, client, params
8
8
  resource :sandbox, :available_phone_numbers, :incoming_phone_numbers,
9
9
  :calls, :outgoing_caller_ids, :conferences, :sms, :recordings,
10
- :transcriptions, :notifications, :applications
10
+ :transcriptions, :notifications, :applications, :connect_apps,
11
+ :authorized_connect_apps
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,6 @@
1
+ module Twilio
2
+ module REST
3
+ class AuthorizedConnectApps < ListResource; end
4
+ class AuthorizedConnectApp < InstanceResource; end
5
+ end
6
+ end
@@ -2,9 +2,9 @@ module Twilio
2
2
  module REST
3
3
  class AvailablePhoneNumbers < ListResource
4
4
  def initialize(uri, client)
5
- @resource_name = 'countries'
6
- @instance_class = Twilio::REST.const_get 'Country'
7
5
  @uri, @client = uri, client
6
+ @instance_class = Twilio::REST::Country
7
+ @list_key, @instance_id_key = 'countries', 'country_code'
8
8
  end
9
9
  end
10
10
 
@@ -2,9 +2,9 @@ module Twilio
2
2
  module REST
3
3
  class Local < ListResource
4
4
  def initialize(uri, client)
5
- @resource_name = 'available_phone_numbers'
6
- @instance_class = Twilio::REST.const_get 'AvailablePhoneNumber'
7
5
  @uri, @client = uri, client
6
+ @instance_class = Twilio::REST::AvailablePhoneNumber
7
+ @list_key, @instance_id_key = 'available_phone_numbers', 'sid'
8
8
  end
9
9
  end
10
10
  end
@@ -2,9 +2,9 @@ module Twilio
2
2
  module REST
3
3
  class TollFree < ListResource
4
4
  def initialize(uri, client)
5
- @resource_name = 'available_phone_numbers'
6
- @instance_class = Twilio::REST.const_get 'AvailablePhoneNumber'
7
5
  @uri, @client = uri, client
6
+ @instance_class = Twilio::REST::AvailablePhoneNumber
7
+ @list_key, @instance_id_key = 'available_phone_numbers', 'sid'
8
8
  end
9
9
  end
10
10
  end
@@ -82,6 +82,14 @@ module Twilio
82
82
  # to avoid insecure connection warnings in environments without the proper
83
83
  # cert validation chain.
84
84
  #
85
+ # === <tt>:timeout => 30</tt>
86
+ #
87
+ # Set the time in seconds to wait before timing out the HTTP request.
88
+ # Defaults to 30 seconds. If you aren't fetching giant pages of call or
89
+ # SMS logs you can safely decrease this to something like 3 seconds or
90
+ # lower. In paricular if you are sending SMS you can set this to 1 second
91
+ # or less and swallow the exception if you don't care about the response.
92
+ #
85
93
  # === <tt>:proxy_addr => 'proxy.host.domain'</tt>
86
94
  #
87
95
  # The domain of a proxy through which you'd like the client to make HTTP
@@ -168,7 +176,7 @@ module Twilio
168
176
  # a private method documented for completeness.
169
177
  def set_up_connection_from(options = {}) # :doc:
170
178
  config = {:host => 'api.twilio.com', :port => 443, :use_ssl => true,
171
- :ssl_verify_peer => true}.merge! options
179
+ :ssl_verify_peer => true, :timeout => 30}.merge! options
172
180
  connection_class = Net::HTTP::Proxy config[:proxy_addr],
173
181
  config[:proxy_port], config[:proxy_user], config[:proxy_pass]
174
182
  @connection = connection_class.new config[:host], config[:port]
@@ -176,6 +184,8 @@ module Twilio
176
184
  unless config[:ssl_verify_peer]
177
185
  @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
178
186
  end
187
+ @connection.open_timeout = options[:timeout]
188
+ @connection.read_timeout = options[:timeout]
179
189
  end
180
190
 
181
191
  ##
@@ -1,9 +1,10 @@
1
1
  module Twilio
2
2
  module REST
3
3
  class Participants < ListResource
4
- private
5
- def instance_sid_key
6
- 'call_sid'
4
+ def initialize(uri, client)
5
+ super
6
+ # hard-code the json key since participants don't have sids
7
+ @instance_id_key = 'call_sid'
7
8
  end
8
9
  end
9
10
 
@@ -0,0 +1,6 @@
1
+ module Twilio
2
+ module REST
3
+ class ConnectApps < ListResource; end
4
+ class ConnectApp < InstanceResource; end
5
+ end
6
+ end
@@ -4,9 +4,10 @@ module Twilio
4
4
  include Utils
5
5
 
6
6
  def initialize(uri, client)
7
- @resource_name = self.class.name.split('::')[-1]
8
- @instance_class = Twilio::REST.const_get @resource_name.chop
9
7
  @uri, @client = uri, client
8
+ resource_name = self.class.name.split('::')[-1]
9
+ @instance_class = Twilio::REST.const_get resource_name.chop
10
+ @list_key, @instance_id_key = detwilify(resource_name), 'sid'
10
11
  end
11
12
 
12
13
  def inspect # :nodoc:
@@ -22,13 +23,13 @@ module Twilio
22
23
  # of resources you can request is 1000.
23
24
  #
24
25
  # The optional +params+ hash allows you to filter the list returned. The
25
- # filters for each list resource type are defined by Twilio
26
+ # filters for each list resource type are defined by Twilio.
26
27
  def list(params = {})
27
28
  raise "Can't get a resource list without a REST Client" unless @client
28
29
  response = @client.get @uri, params
29
- resources = response[detwilify(@resource_name)]
30
+ resources = response[@list_key]
30
31
  resource_list = resources.map do |resource|
31
- @instance_class.new "#{@uri}/#{resource[instance_sid_key]}", @client,
32
+ @instance_class.new "#{@uri}/#{resource[@instance_id_key]}", @client,
32
33
  resource
33
34
  end
34
35
  # set the +total+ property on the array
@@ -68,21 +69,12 @@ module Twilio
68
69
  # the Twilio REST API documentation related to the kind of resource you
69
70
  # are attempting to create for details. Calling this method makes an HTTP
70
71
  # POST request to <tt>@uri</tt> with the given params
71
- def create(params = {})
72
+ def create(params={})
72
73
  raise "Can't create a resource without a REST Client" unless @client
73
74
  response = @client.post @uri, params
74
- @instance_class.new "#{@uri}/#{response[instance_sid_key]}", @client,
75
+ @instance_class.new "#{@uri}/#{response[@instance_id_key]}", @client,
75
76
  response
76
77
  end
77
-
78
- private
79
-
80
- ##
81
- # Return the JSON key containing the sid of each instance. Overridden for
82
- # conference participants and perhaps other resources.
83
- def instance_sid_key
84
- 'sid'
85
- end
86
78
  end
87
79
  end
88
80
  end
@@ -4,8 +4,22 @@ module Twilio
4
4
  def add(phone_number)
5
5
  create :phone_number => phone_number
6
6
  end
7
+ alias :verify :add
8
+
9
+ ##
10
+ # Override ListResource#create to instantiate the proper instance class.
11
+ # This doesn't actually matter since all properties are lazily loaded into
12
+ # whatever object is instantiated. But it might matter in the future.
13
+ def create(params={}) # :nodoc:
14
+ old_instance_class = @instance_class
15
+ @instance_class = Twilio::REST::PhoneNumberVerificationRequest
16
+ verification_request = super
17
+ @instance_class = old_instance_class
18
+ verification_request
19
+ end
7
20
  end
8
21
 
9
22
  class OutgoingCallerId < InstanceResource; end
23
+ class PhoneNumberVerificationRequest < InstanceResource; end
10
24
  end
11
25
  end
@@ -10,18 +10,20 @@ module Twilio
10
10
  @connection = @client.instance_variable_get :@connection
11
11
  end
12
12
 
13
+ ##
14
+ # Return the wav URL for this recording.
13
15
  def wav
14
- scheme = @connection.use_ssl ? 'https' : 'http'
15
- "#{scheme}://#{@connection.address}#{@uri}.wav"
16
+ "https://#{@connection.address}#{@uri}.wav"
16
17
  end
17
18
 
18
19
  def wav!(&block)
19
20
  @connection.request_get @uri, &block
20
21
  end
21
22
 
23
+ ##
24
+ # Return the mp3 URL for this recording.
22
25
  def mp3
23
- scheme = @connection.use_ssl ? 'https' : 'http'
24
- "#{scheme}://#{@connection.address}#{@uri}.mp3"
26
+ "https://#{@connection.address}#{@uri}.mp3"
25
27
  end
26
28
 
27
29
  def mp3!(&block)
@@ -4,7 +4,7 @@ module Twilio
4
4
  def initialize(uri, client)
5
5
  super
6
6
  # hard-code the json key since 'messages' doesn't exist in the response
7
- @resource_name = 'sms_messages'
7
+ @list_key = 'sms_messages'
8
8
  end
9
9
  end
10
10
 
@@ -1,3 +1,3 @@
1
1
  module Twilio
2
- VERSION = '3.3.1'
2
+ VERSION = '3.4.0'
3
3
  end
data/test/twilio_spec.rb CHANGED
@@ -28,6 +28,15 @@ describe Twilio::REST::Client do
28
28
  twilio.instance_variable_get('@connection').use_ssl?.should == true
29
29
  end
30
30
 
31
+ it 'should adjust the open and read timeouts on the underlying Net::HTTP object when asked' do
32
+ timeout = rand(30)
33
+ twilio = Twilio::REST::Client.new('someSid', 'someToken', :timeout => timeout)
34
+ twilio.instance_variable_get('@connection').port.should == 443
35
+ twilio.instance_variable_get('@connection').use_ssl?.should == true
36
+ twilio.instance_variable_get('@connection').open_timeout.should == timeout
37
+ twilio.instance_variable_get('@connection').read_timeout.should == timeout
38
+ end
39
+
31
40
  it 'should set up the proper http ssl connection when a proxy_host is given' do
32
41
  twilio = Twilio::REST::Client.new('someSid', 'someToken', :host => 'api.faketwilio.com', :proxy_addr => 'localhost')
33
42
  twilio.instance_variable_get('@connection').proxy?.should == true
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: 9
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
- - 3
9
- - 1
10
- version: 3.3.1
8
+ - 4
9
+ - 0
10
+ version: 3.4.0
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: 2011-08-26 00:00:00 -07:00
18
+ date: 2011-09-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -152,6 +152,7 @@ files:
152
152
  - lib/twilio-ruby.rb
153
153
  - lib/twilio-ruby/rest/accounts.rb
154
154
  - lib/twilio-ruby/rest/applications.rb
155
+ - lib/twilio-ruby/rest/authorized_connect_apps.rb
155
156
  - lib/twilio-ruby/rest/available_phone_numbers.rb
156
157
  - lib/twilio-ruby/rest/available_phone_numbers/country.rb
157
158
  - lib/twilio-ruby/rest/available_phone_numbers/local.rb
@@ -160,6 +161,7 @@ files:
160
161
  - lib/twilio-ruby/rest/client.rb
161
162
  - lib/twilio-ruby/rest/conferences.rb
162
163
  - lib/twilio-ruby/rest/conferences/participants.rb
164
+ - lib/twilio-ruby/rest/connect_apps.rb
163
165
  - lib/twilio-ruby/rest/errors.rb
164
166
  - lib/twilio-ruby/rest/incoming_phone_numbers.rb
165
167
  - lib/twilio-ruby/rest/instance_resource.rb