twilio-ruby 0.4.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +79 -5
- data/examples.rb +0 -2
- data/lib/twilio-ruby.rb +41 -34
- data/lib/twilio-ruby/rest/client.rb +53 -22
- data/lib/twilio-ruby/rest/errors.rb +6 -0
- data/lib/twilio-ruby/rest/instance_resource.rb +7 -6
- data/lib/twilio-ruby/rest/list_resource.rb +4 -4
- data/lib/twilio-ruby/rest/sms/messages.rb +1 -5
- data/lib/twilio-ruby/rest/sms/short_code.rb +5 -0
- data/lib/twilio-ruby/rest/sms/short_codes.rb +5 -0
- data/lib/twilio-ruby/rest/sms/sms.rb +1 -1
- data/lib/twilio-ruby/rest/utils.rb +0 -7
- data/lib/twilio-ruby/util.rb +7 -0
- data/lib/twilio-ruby/util/request_validator.rb +22 -0
- data/test/twilio_spec.rb +75 -4
- data/twilio-ruby.gemspec +3 -3
- metadata +11 -8
- data/test/test_twilio.rb +0 -6
data/README.md
CHANGED
@@ -1,13 +1,87 @@
|
|
1
1
|
## Get Started
|
2
2
|
|
3
|
-
Review [examples.rb](twilio-ruby/blob/master/examples.rb) to see how to get started using twilio-ruby.
|
4
|
-
|
5
3
|
To install:
|
6
4
|
|
5
|
+
Via rubygems.org:
|
6
|
+
|
7
|
+
```
|
7
8
|
$ sudo gem install twilio-ruby
|
9
|
+
```
|
8
10
|
|
9
11
|
To build and install yourself from the latest source:
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
```
|
14
|
+
$ git clone git@github.com:andrewmbenton/twilio-ruby.git
|
15
|
+
$ cd twilio-ruby; rake gem
|
16
|
+
$ sudo gem install pkg/twilio-ruby-{version}
|
17
|
+
```
|
18
|
+
|
19
|
+
## Some Code To Get You Started
|
20
|
+
|
21
|
+
### Setup Work
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
require 'rubygems'
|
25
|
+
require 'twilio-ruby'
|
26
|
+
|
27
|
+
# put your own credentials here
|
28
|
+
@account_sid = 'AC043dcf9844e04758bc3a36a84c29761'
|
29
|
+
@auth_token = '62ea81de3a5b414154eb263595357c69'
|
30
|
+
|
31
|
+
# set up a client to talk to the Twilio REST API
|
32
|
+
@client = Twilio::REST::Client.new(@account_sid, @auth_token)
|
33
|
+
```
|
34
|
+
|
35
|
+
### Send an SMS
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
# send an sms
|
39
|
+
@client.account.sms.messages.create(
|
40
|
+
:from => '+14159341234',
|
41
|
+
:to => '+16105557069',
|
42
|
+
:body => 'Hey there!'
|
43
|
+
)
|
44
|
+
```
|
45
|
+
|
46
|
+
### Do Some Stuff With Calls
|
47
|
+
|
48
|
+
``` ruby
|
49
|
+
# make a new outgoing call
|
50
|
+
@call = @client.account.calls.create(
|
51
|
+
:from => '+14159341234',
|
52
|
+
:to => '+18004567890',
|
53
|
+
:url => 'http://myapp.com/call-handler'
|
54
|
+
)
|
55
|
+
|
56
|
+
# hangup a ringing call, but don't touch it if it's connected
|
57
|
+
@call.cancel
|
58
|
+
|
59
|
+
# if you have the call sid, you can fetch a call object via:
|
60
|
+
@call = @client.account.calls.get('CA386025c9bf5d6052a1d1ea42b4d16662')
|
61
|
+
|
62
|
+
# redirect an in-progress call
|
63
|
+
@call.redirect_to('http://myapp.com/call-redirect')
|
64
|
+
|
65
|
+
# hangup a call, no matter whether it is ringing or connected
|
66
|
+
@call.hangup
|
67
|
+
```
|
68
|
+
|
69
|
+
### Buy a Phone Number
|
70
|
+
|
71
|
+
``` ruby
|
72
|
+
# print some available numbers
|
73
|
+
@numbers = @client.account.available_phone_numbers.get('US').local.list(
|
74
|
+
:contains => 'AWESOME'
|
75
|
+
)
|
76
|
+
@numbers.each {|num| puts num.phone_number}
|
77
|
+
|
78
|
+
# buy the first one
|
79
|
+
@number = @numbers[0].phone_number
|
80
|
+
@account.incoming_phone_numbers.create(:phone_number => @number)
|
81
|
+
```
|
82
|
+
|
83
|
+
## More Information
|
84
|
+
|
85
|
+
There are more detailed examples in the included [examples.rb](twilio-ruby/blob/master/examples.rb).
|
86
|
+
|
87
|
+
Full [API documentation](twilio-ruby/wiki/Documentation), as well as an [upgrade guide](twilio-ruby/wiki/UpgradeGuide) for users of the old twiliolib gem, is available in the [twilio-ruby github wiki](twilio-ruby/wiki).
|
data/examples.rb
CHANGED
@@ -58,8 +58,6 @@ puts @account.sms.messages.get('SMXXXXXXXX').body
|
|
58
58
|
|
59
59
|
# send an sms
|
60
60
|
@account.sms.messages.create(:from => '+14159341234', :to => '+16105557069', :body => 'Hey there!')
|
61
|
-
# or, an alias
|
62
|
-
@account.sms.messages.send('+14159341234', '+16105557069', 'Hey there!')
|
63
61
|
|
64
62
|
################ PHONE NUMBERS ################
|
65
63
|
|
data/lib/twilio-ruby.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
TWILIO_RUBY_ROOT = File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
1
3
|
require 'net/http'
|
2
4
|
require 'net/https'
|
3
5
|
require 'builder'
|
@@ -7,37 +9,42 @@ require 'openssl'
|
|
7
9
|
require 'base64'
|
8
10
|
|
9
11
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
12
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/util"
|
13
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/util/request_validator"
|
14
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/errors"
|
15
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/utils"
|
16
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/list_resource"
|
17
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/instance_resource"
|
18
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/sandbox/sandbox"
|
19
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/accounts/account"
|
20
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/accounts/accounts"
|
21
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/calls/call"
|
22
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/calls/calls"
|
23
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/sms/sms"
|
24
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/sms/message"
|
25
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/sms/messages"
|
26
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/sms/short_code"
|
27
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/sms/short_codes"
|
28
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/applications/application"
|
29
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/applications/applications"
|
30
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/outgoing_caller_ids/outgoing_caller_id"
|
31
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/outgoing_caller_ids/outgoing_caller_ids"
|
32
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/incoming_phone_numbers/incoming_phone_number"
|
33
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/incoming_phone_numbers/incoming_phone_numbers"
|
34
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/available_phone_numbers/available_phone_number"
|
35
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/available_phone_numbers/available_phone_numbers"
|
36
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/available_phone_numbers/country"
|
37
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/available_phone_numbers/local"
|
38
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/available_phone_numbers/toll_free"
|
39
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/conferences/conference"
|
40
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/conferences/conferences"
|
41
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/conferences/participant"
|
42
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/conferences/participants"
|
43
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/recordings/recording"
|
44
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/recordings/recordings"
|
45
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/transcriptions/transcription"
|
46
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/transcriptions/transcriptions"
|
47
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/notifications/notification"
|
48
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/notifications/notifications"
|
49
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/rest/client"
|
50
|
+
require "#{TWILIO_RUBY_ROOT}/twilio-ruby/twiml/response"
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module Twilio
|
2
2
|
module REST
|
3
3
|
class Client
|
4
|
-
include Utils
|
5
4
|
|
6
|
-
|
5
|
+
include Twilio::Util
|
6
|
+
include Twilio::REST::Utils
|
7
|
+
|
8
|
+
attr_reader :account_sid, :account, :accounts
|
7
9
|
|
8
|
-
def initialize(account_sid, auth_token,
|
9
|
-
|
10
|
+
def initialize(account_sid, auth_token, domain = 'api.twilio.com',
|
11
|
+
proxy_host = nil, proxy_port = nil)
|
10
12
|
@account_sid = account_sid
|
11
13
|
@auth_token = auth_token
|
12
|
-
|
13
|
-
set_up_connection_to domain, proxy
|
14
|
+
set_up_connection_to domain, proxy_host, proxy_port
|
14
15
|
set_up_subresources
|
15
16
|
end
|
16
17
|
|
@@ -19,43 +20,73 @@ module Twilio
|
|
19
20
|
method_class = Net::HTTP.const_get method.to_s.capitalize
|
20
21
|
define_method method do |uri, *args|
|
21
22
|
uri += '.json'
|
22
|
-
params = (args[0]
|
23
|
-
uri += "?#{url_encode(params)}" if params && method == :get
|
24
|
-
|
23
|
+
params = twilify(args[0]); params = {} if params.empty?
|
24
|
+
uri += "?#{url_encode(params)}" if !params.empty? && method == :get
|
25
|
+
headers = {
|
26
|
+
'Accept' => 'application/json',
|
27
|
+
'User-Agent' => 'twilio-ruby/3.0.0'
|
28
|
+
}
|
29
|
+
request = method_class.new uri, headers
|
25
30
|
request.basic_auth @account_sid, @auth_token
|
26
|
-
request.form_data = params if
|
31
|
+
request.form_data = params if [:post, :put].include? method
|
27
32
|
http_response = @connection.request request
|
28
33
|
object = Crack::JSON.parse http_response.body if http_response.body
|
29
|
-
|
34
|
+
if http_response.kind_of? Net::HTTPClientError
|
35
|
+
raise Twilio::REST::RequestError, object['message']
|
36
|
+
elsif http_response.kind_of? Net::HTTPServerError
|
37
|
+
raise Twilio::REST::ServerError, object['message']
|
38
|
+
end
|
30
39
|
object
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
34
|
-
|
35
|
-
|
43
|
+
# Mimic the old (deprecated) interface
|
44
|
+
def request(uri, method = 'POST', params = {})
|
45
|
+
raise ArgumentError, 'Invalid path parameter' if uri.empty?
|
46
|
+
|
47
|
+
uri = "/#{uri}" unless uri.start_with? '/'
|
48
|
+
|
49
|
+
case method
|
50
|
+
when 'GET'
|
51
|
+
uri += "?#{url_encode(params)}" if params
|
52
|
+
req = Net::HTTP::Get.new uri
|
53
|
+
when 'DELETE'
|
54
|
+
req = Net::HTTP::Delete.new uri
|
55
|
+
when 'PUT'
|
56
|
+
req = Net::HTTP::Put.new uri
|
57
|
+
req.form_data = params
|
58
|
+
when 'POST'
|
59
|
+
req = Net::HTTP::Post.new uri
|
60
|
+
req.form_data = params
|
61
|
+
else
|
62
|
+
raise NotImplementedError, "HTTP #{method} not implemented"
|
63
|
+
end
|
64
|
+
|
65
|
+
req.basic_auth @account_sid, @auth_token
|
66
|
+
@connection.request req
|
36
67
|
end
|
37
68
|
|
38
69
|
private
|
39
70
|
|
40
|
-
def set_up_connection_to(domain,
|
41
|
-
|
71
|
+
def set_up_connection_to(domain, proxy_host = nil, proxy_port = nil)
|
72
|
+
connection_class = Net::HTTP::Proxy proxy_host, proxy_port
|
73
|
+
@connection = connection_class.new domain, 443
|
42
74
|
@connection.use_ssl = true
|
43
|
-
# Don't check the server cert. Ideally this is configurable
|
44
|
-
# app wants to verify that it
|
75
|
+
# Don't check the server cert. Ideally this is configurable in case an
|
76
|
+
# app wants to verify that it's actually talking to the real Twilio.
|
77
|
+
# But cert validation is usually a nightmare, so we skip it for now.
|
45
78
|
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
46
79
|
end
|
47
80
|
|
48
81
|
def set_up_subresources
|
49
|
-
accounts_uri =
|
82
|
+
accounts_uri = '/2010-04-01/Accounts'
|
83
|
+
account_uri = "#{accounts_uri}/#{@account_sid}"
|
50
84
|
# Set up a special handle to grab the account.
|
51
|
-
@account = Twilio::REST::Account.new
|
85
|
+
@account = Twilio::REST::Account.new account_uri, self
|
52
86
|
# Set up the accounts subresource.
|
53
87
|
@accounts = Twilio::REST::Accounts.new accounts_uri, self
|
54
88
|
end
|
55
89
|
|
56
|
-
def url_encode(hash)
|
57
|
-
hash.to_a.map {|p| p.map {|e| CGI.escape e.to_s}.join '='}.join '&'
|
58
|
-
end
|
59
90
|
end
|
60
91
|
end
|
61
92
|
end
|
@@ -3,20 +3,20 @@ module Twilio
|
|
3
3
|
class InstanceResource
|
4
4
|
include Utils
|
5
5
|
|
6
|
-
def initialize(uri, client, params={})
|
6
|
+
def initialize(uri, client, params = {})
|
7
7
|
@uri, @client = uri, client
|
8
8
|
set_up_properties_from params
|
9
9
|
end
|
10
10
|
|
11
|
-
def update(params={})
|
12
|
-
raise "Can't update a resource without a
|
11
|
+
def update(params = {})
|
12
|
+
raise "Can't update a resource without a REST Client" unless @client
|
13
13
|
response = @client.post @uri, params
|
14
14
|
set_up_properties_from response
|
15
15
|
self
|
16
16
|
end
|
17
17
|
|
18
18
|
def delete
|
19
|
-
raise "Can't delete a resource without a
|
19
|
+
raise "Can't delete a resource without a REST Client" unless @client
|
20
20
|
@client.delete @uri
|
21
21
|
end
|
22
22
|
|
@@ -44,8 +44,9 @@ module Twilio
|
|
44
44
|
resources.each do |r|
|
45
45
|
resource = twilify r
|
46
46
|
relative_uri = r == :sms ? 'SMS' : resource
|
47
|
-
|
48
|
-
|
47
|
+
uri = "#{@uri}/#{relative_uri}"
|
48
|
+
resource_class = Twilio::REST.const_get resource
|
49
|
+
instance_variable_set("@#{r}", resource_class.new(uri, @client))
|
49
50
|
end
|
50
51
|
self.class.instance_eval {attr_reader *resources}
|
51
52
|
end
|
@@ -10,8 +10,8 @@ module Twilio
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Grab a list of this kind of resource and return it as an array.
|
13
|
-
def list(params={})
|
14
|
-
raise "Can't get a resource list without a
|
13
|
+
def list(params = {})
|
14
|
+
raise "Can't get a resource list without a REST Client" unless @client
|
15
15
|
response = @client.get @uri, params
|
16
16
|
resources = response[detwilify(@resource_name)]
|
17
17
|
resources.map do |resource|
|
@@ -25,8 +25,8 @@ module Twilio
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# Return a newly created resource.
|
28
|
-
def create(params={})
|
29
|
-
raise "Can't create a resource without a
|
28
|
+
def create(params = {})
|
29
|
+
raise "Can't create a resource without a REST Client" unless @client
|
30
30
|
response = @client.post @uri, params
|
31
31
|
@instance_class.new "#{@uri}/#{response['sid']}", @client, response
|
32
32
|
end
|
@@ -20,13 +20,6 @@ module Twilio
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.validate(auth_token, signature, url, params={})
|
24
|
-
data = url + params.sort.to_s
|
25
|
-
digest = OpenSSL::Digest::Digest.new('sha1')
|
26
|
-
expected = Base64.encode64(OpenSSL::HMAC.digest(digest, auth_token, data)).strip
|
27
|
-
return expected == signature
|
28
|
-
end
|
29
|
-
|
30
23
|
end
|
31
24
|
end
|
32
25
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Twilio
|
2
|
+
module Util
|
3
|
+
class RequestValidator
|
4
|
+
|
5
|
+
def initialize(auth_token)
|
6
|
+
@auth_token = auth_token
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate(url, params, signature)
|
10
|
+
expected = build_signature_for url, params
|
11
|
+
expected == signature
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_signature_for(url, params)
|
15
|
+
data = url + params.sort.to_s
|
16
|
+
digest = OpenSSL::Digest::Digest.new('sha1')
|
17
|
+
Base64.encode64(OpenSSL::HMAC.digest(digest, @auth_token, data)).strip
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/test/twilio_spec.rb
CHANGED
@@ -7,11 +7,10 @@ describe Twilio::REST::Client do
|
|
7
7
|
FakeWeb.register_uri(:any, %r/http:\/\/api.twilio.com\//, :body => '{"message": "You tried to reach Twilio"}')
|
8
8
|
end
|
9
9
|
|
10
|
-
it 'should set up a
|
11
|
-
twilio = Twilio::REST::Client.new('someSid', 'someToken'
|
10
|
+
it 'should set up a new client instance with the given sid and token' do
|
11
|
+
twilio = Twilio::REST::Client.new('someSid', 'someToken')
|
12
12
|
twilio.account_sid.should == 'someSid'
|
13
13
|
twilio.instance_variable_get('@auth_token').should == 'someToken'
|
14
|
-
twilio.api_version.should == 'api-version'
|
15
14
|
end
|
16
15
|
|
17
16
|
it 'should set up the proper default http ssl connection' do
|
@@ -22,7 +21,27 @@ describe Twilio::REST::Client do
|
|
22
21
|
end
|
23
22
|
|
24
23
|
it 'should set up the proper http ssl connection when a different domain is given' do
|
25
|
-
twilio = Twilio::REST::Client.new('someSid', 'someToken', '
|
24
|
+
twilio = Twilio::REST::Client.new('someSid', 'someToken', 'api.faketwilio.com')
|
25
|
+
twilio.instance_variable_get('@connection').address.should == 'api.faketwilio.com'
|
26
|
+
twilio.instance_variable_get('@connection').port.should == 443
|
27
|
+
twilio.instance_variable_get('@connection').use_ssl?.should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should set up the proper http ssl connection when a proxy_host is given' do
|
31
|
+
twilio = Twilio::REST::Client.new('someSid', 'someToken', 'api.faketwilio.com', 'localhost')
|
32
|
+
twilio.instance_variable_get('@connection').proxy?.should == true
|
33
|
+
twilio.instance_variable_get('@connection').proxy_address.should == 'localhost'
|
34
|
+
twilio.instance_variable_get('@connection').proxy_port.should == 80
|
35
|
+
twilio.instance_variable_get('@connection').address.should == 'api.faketwilio.com'
|
36
|
+
twilio.instance_variable_get('@connection').port.should == 443
|
37
|
+
twilio.instance_variable_get('@connection').use_ssl?.should == true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set up the proper http ssl connection when a proxy_host and proxy_port are given' do
|
41
|
+
twilio = Twilio::REST::Client.new('someSid', 'someToken', 'api.faketwilio.com', 'localhost', 13128)
|
42
|
+
twilio.instance_variable_get('@connection').proxy?.should == true
|
43
|
+
twilio.instance_variable_get('@connection').proxy_address.should == 'localhost'
|
44
|
+
twilio.instance_variable_get('@connection').proxy_port.should == 13128
|
26
45
|
twilio.instance_variable_get('@connection').address.should == 'api.faketwilio.com'
|
27
46
|
twilio.instance_variable_get('@connection').port.should == 443
|
28
47
|
twilio.instance_variable_get('@connection').use_ssl?.should == true
|
@@ -52,6 +71,20 @@ describe Twilio::REST::Client do
|
|
52
71
|
end
|
53
72
|
end
|
54
73
|
|
74
|
+
describe Twilio::REST::InstanceResource do
|
75
|
+
it 'should set up an internal reference to the uri and client' do
|
76
|
+
resource = Twilio::REST::InstanceResource.new('some/uri', 'someClient')
|
77
|
+
resource.instance_variable_get('@uri').should == 'some/uri'
|
78
|
+
resource.instance_variable_get('@client').should == 'someClient'
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should set up object properties if passed' do
|
82
|
+
params = {'SomeKey' => 'someValue'}
|
83
|
+
resource = Twilio::REST::InstanceResource.new('uri', 'client', params)
|
84
|
+
resource.some_key.should == 'someValue'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
55
88
|
describe Twilio::REST::Account do
|
56
89
|
it 'should set up an incoming phone numbers resources object' do
|
57
90
|
account = Twilio::REST::Account.new('someUri', 'someClient')
|
@@ -137,3 +170,41 @@ describe Twilio::REST::Recording do
|
|
137
170
|
call.transcriptions.instance_variable_get('@uri').should == 'someUri/Transcriptions'
|
138
171
|
end
|
139
172
|
end
|
173
|
+
|
174
|
+
describe Twilio::Util::RequestValidator do
|
175
|
+
it 'should properly validate a Twilio request based on its signature' do
|
176
|
+
token = '1c892n40nd03kdnc0112slzkl3091j20'
|
177
|
+
validator = Twilio::Util::RequestValidator.new token
|
178
|
+
url = 'http://www.postbin.org/1ed898x'
|
179
|
+
params = {
|
180
|
+
'AccountSid' => 'AC9a9f9392lad99kla0sklakjs90j092j3',
|
181
|
+
'ApiVersion' => '2010-04-01',
|
182
|
+
'CallSid' => 'CAd800bb12c0426a7ea4230e492fef2a4f',
|
183
|
+
'CallStatus' => 'ringing',
|
184
|
+
'Called' => '+15306384866',
|
185
|
+
'CalledCity' => 'OAKLAND',
|
186
|
+
'CalledCountry' => 'US',
|
187
|
+
'CalledState' => 'CA',
|
188
|
+
'CalledZip' => '94612',
|
189
|
+
'Caller' => '+15306666666',
|
190
|
+
'CallerCity' => 'SOUTH LAKE TAHOE',
|
191
|
+
'CallerCountry' => 'US',
|
192
|
+
'CallerName' => 'CA Wireless Call',
|
193
|
+
'CallerState' => 'CA',
|
194
|
+
'CallerZip' => '89449',
|
195
|
+
'Direction' => 'inbound',
|
196
|
+
'From' => '+15306666666',
|
197
|
+
'FromCity' => 'SOUTH LAKE TAHOE',
|
198
|
+
'FromCountry' => 'US',
|
199
|
+
'FromState' => 'CA',
|
200
|
+
'FromZip' => '89449',
|
201
|
+
'To' => '+15306384866',
|
202
|
+
'ToCity' => 'OAKLAND',
|
203
|
+
'ToCountry' => 'US',
|
204
|
+
'ToState' => 'CA',
|
205
|
+
'ToZip' => '94612'
|
206
|
+
}
|
207
|
+
signature = 'fF+xx6dTinOaCdZ0aIeNkHr/ZAA='
|
208
|
+
validator.validate(url, params, signature).should == true
|
209
|
+
end
|
210
|
+
end
|
data/twilio-ruby.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "twilio-ruby"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "3.0.0"
|
4
4
|
s.author = "Andrew Benton"
|
5
|
-
s.email = "
|
5
|
+
s.email = "andrew@twilio.com"
|
6
6
|
s.description = "A simple library for communicating with the Twilio REST API"
|
7
7
|
s.summary = "A simple library for communicating with the Twilio REST API"
|
8
|
-
s.homepage = "http://github.com/
|
8
|
+
s.homepage = "http://github.com/twilio/twilio-ruby"
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.files = Dir['lib/**/*.rb'] + Dir['test/**/*.rb'] + ['examples.rb', 'Rakefile', 'LICENSE', 'README.md', 'twilio-ruby.gemspec']
|
11
11
|
s.test_files = Dir['test/**/*.rb']
|
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:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 3
|
7
8
|
- 0
|
8
|
-
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 3.0.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-
|
18
|
+
date: 2011-07-15 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
type: :runtime
|
52
52
|
version_requirements: *id002
|
53
53
|
description: A simple library for communicating with the Twilio REST API
|
54
|
-
email:
|
54
|
+
email: andrew@twilio.com
|
55
55
|
executables: []
|
56
56
|
|
57
57
|
extensions: []
|
@@ -79,9 +79,12 @@ files:
|
|
79
79
|
- lib/twilio-ruby/rest/accounts/account.rb
|
80
80
|
- lib/twilio-ruby/rest/recordings/recording.rb
|
81
81
|
- lib/twilio-ruby/rest/recordings/recordings.rb
|
82
|
+
- lib/twilio-ruby/rest/errors.rb
|
82
83
|
- lib/twilio-ruby/rest/notifications/notification.rb
|
83
84
|
- lib/twilio-ruby/rest/notifications/notifications.rb
|
84
85
|
- lib/twilio-ruby/rest/sms/messages.rb
|
86
|
+
- lib/twilio-ruby/rest/sms/short_code.rb
|
87
|
+
- lib/twilio-ruby/rest/sms/short_codes.rb
|
85
88
|
- lib/twilio-ruby/rest/sms/sms.rb
|
86
89
|
- lib/twilio-ruby/rest/sms/message.rb
|
87
90
|
- lib/twilio-ruby/rest/outgoing_caller_ids/outgoing_caller_id.rb
|
@@ -93,16 +96,17 @@ files:
|
|
93
96
|
- lib/twilio-ruby/rest/available_phone_numbers/toll_free.rb
|
94
97
|
- lib/twilio-ruby/rest/sandbox/sandbox.rb
|
95
98
|
- lib/twilio-ruby/rest/instance_resource.rb
|
99
|
+
- lib/twilio-ruby/util/request_validator.rb
|
100
|
+
- lib/twilio-ruby/util.rb
|
96
101
|
- lib/twilio-ruby/twiml/response.rb
|
97
102
|
- test/twilio_spec.rb
|
98
|
-
- test/test_twilio.rb
|
99
103
|
- examples.rb
|
100
104
|
- Rakefile
|
101
105
|
- LICENSE
|
102
106
|
- README.md
|
103
107
|
- twilio-ruby.gemspec
|
104
108
|
has_rdoc: true
|
105
|
-
homepage: http://github.com/
|
109
|
+
homepage: http://github.com/twilio/twilio-ruby
|
106
110
|
licenses: []
|
107
111
|
|
108
112
|
post_install_message:
|
@@ -137,4 +141,3 @@ specification_version: 3
|
|
137
141
|
summary: A simple library for communicating with the Twilio REST API
|
138
142
|
test_files:
|
139
143
|
- test/twilio_spec.rb
|
140
|
-
- test/test_twilio.rb
|