twilio-ruby 0.0.3

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.
Files changed (37) hide show
  1. data/Rakefile +8 -0
  2. data/examples.rb +93 -0
  3. data/lib/twilio-ruby.rb +36 -0
  4. data/lib/twilio-ruby/accounts/account.rb +10 -0
  5. data/lib/twilio-ruby/accounts/accounts.rb +3 -0
  6. data/lib/twilio-ruby/available_phone_numbers/available_phone_number.rb +3 -0
  7. data/lib/twilio-ruby/available_phone_numbers/available_phone_numbers.rb +9 -0
  8. data/lib/twilio-ruby/available_phone_numbers/country.rb +8 -0
  9. data/lib/twilio-ruby/available_phone_numbers/local.rb +9 -0
  10. data/lib/twilio-ruby/available_phone_numbers/toll_free.rb +9 -0
  11. data/lib/twilio-ruby/calls/call.rb +20 -0
  12. data/lib/twilio-ruby/calls/calls.rb +7 -0
  13. data/lib/twilio-ruby/client.rb +61 -0
  14. data/lib/twilio-ruby/conferences/conference.rb +8 -0
  15. data/lib/twilio-ruby/conferences/conferences.rb +3 -0
  16. data/lib/twilio-ruby/conferences/participant.rb +15 -0
  17. data/lib/twilio-ruby/conferences/participants.rb +3 -0
  18. data/lib/twilio-ruby/incoming_phone_numbers/incoming_phone_number.rb +3 -0
  19. data/lib/twilio-ruby/incoming_phone_numbers/incoming_phone_numbers.rb +7 -0
  20. data/lib/twilio-ruby/instance_resource.rb +53 -0
  21. data/lib/twilio-ruby/list_resource.rb +33 -0
  22. data/lib/twilio-ruby/notifications/notification.rb +3 -0
  23. data/lib/twilio-ruby/notifications/notifications.rb +3 -0
  24. data/lib/twilio-ruby/outgoing_caller_ids/outgoing_caller_id.rb +3 -0
  25. data/lib/twilio-ruby/outgoing_caller_ids/outgoing_caller_ids.rb +7 -0
  26. data/lib/twilio-ruby/recordings/recording.rb +10 -0
  27. data/lib/twilio-ruby/recordings/recordings.rb +3 -0
  28. data/lib/twilio-ruby/sandbox/sandbox.rb +3 -0
  29. data/lib/twilio-ruby/sms_messages/sms_message.rb +3 -0
  30. data/lib/twilio-ruby/sms_messages/sms_messages.rb +7 -0
  31. data/lib/twilio-ruby/transcriptions/transcription.rb +3 -0
  32. data/lib/twilio-ruby/transcriptions/transcriptions.rb +3 -0
  33. data/lib/twilio-ruby/utils.rb +23 -0
  34. data/lib/twilio-ruby/verb.rb +5 -0
  35. data/test/test_twilio.rb +6 -0
  36. data/test/twilio_spec.rb +139 -0
  37. metadata +134 -0
@@ -0,0 +1,8 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ Spec::Rake::SpecTask.new do |spec|
5
+ spec.spec_files = FileList['test/*_spec.rb']
6
+ spec.spec_opts << "--color"
7
+ spec.libs += ["lib", "test"]
8
+ end
@@ -0,0 +1,93 @@
1
+ # examples version 3
2
+
3
+ @account_sid = 'AC043dcf9844e04758bc3a36a84c29761'
4
+ @auth_token = '62ea81de3a5b414154eb263595357c69'
5
+ # set up a client, without any http requests
6
+ @client = Twilio::Client.new(@account_sid, @auth_token)
7
+
8
+ ################ ACCOUNTS ################
9
+
10
+ # grab an account instance resource (no http request)
11
+ @account = @client.accounts.get(@account_sid)
12
+ # http round trip happens here
13
+ puts @account.friendly_name
14
+
15
+ # update an account's friendly name (only one http request, for the POST)
16
+ @client.accounts.get(@account_sid).update(:friendly_name => 'A Fabulous Friendly Name')
17
+
18
+ # shortcut to grab your account object (account_sid is inferred from the client's auth credentials)
19
+ @account = @client.account
20
+
21
+ ################ CALLS ################
22
+
23
+ # print a list of calls (all parameters optional, single http req)
24
+ @account.calls.list({:page => 0, :page_size => 1000, :start_time => '2010-09-01'}).each do |call|
25
+ puts call.sid
26
+ end
27
+
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}
30
+
31
+ # make a new outgoing call (this is the same type of object we get
32
+ # from calls.get, except this has attributes since we made an http request)
33
+ @call = @account.calls.create({:from => '+14159341234', :to => '+18004567890', :url => 'http://myapp.com/call-handler'})
34
+
35
+ # cancel the call if not already in progress (single http request)
36
+ @account.calls.get(@call.sid).update({:status => 'canceled'})
37
+ # or equivalently (single http request)
38
+ @call.update({:status => 'canceled'})
39
+ # or simply
40
+ @call.cancel
41
+
42
+ # redirect and then terminate a call (each one http request)
43
+ @account.calls.get('CA386025c9bf5d6052a1d1ea42b4d16662').update({:url => 'http://myapp.com/call-redirect'})
44
+ @account.calls.get('CA386025c9bf5d6052a1d1ea42b4d16662').update({:status => 'completed'}) # formerly @call.hangup
45
+ # or, use the aliases...
46
+ @call.redirect_to('http://myapp.com/call-redirect')
47
+ @call.hangup
48
+
49
+ ################ SMS MESSAGES ################
50
+
51
+ # print a list of sms messages (one http request)
52
+ @account.sms_messages.list({:date_sent => '2010-09-01'}).each do |sms|
53
+ puts sms.body
54
+ end
55
+
56
+ # print a particular sms message (one http request)
57
+ puts @account.sms_messages.get('SMXXXXXXXX').body
58
+
59
+ # send an sms
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
+
64
+ ################ PHONE NUMBERS ################
65
+
66
+ # get a list of supported country codes (api currently doesn't support this)
67
+ @account.available_phone_numbers.list
68
+
69
+ # print some available numbers (only one http request)
70
+ @numbers = @account.available_phone_numbers.get('US').local.list({:contains => 'AWESOME'})
71
+ @numbers.each {|num| puts num.phone_number}
72
+
73
+ # buy the first one (one http request)
74
+ @account.incoming_phone_numbers.create(:phone_number => @numbers[0].phone_number)
75
+
76
+ # update an existing phone number's voice url (one http request)
77
+ @account.incoming_phone_numbers.get('PNdba508c5616a7f5e141789f44f022cc3').update({:voice_url => 'http://myapp.com/voice'})
78
+
79
+ ################ CONFERENCES ################
80
+
81
+ # get a particular conference's participants object and stash it (should be zero http requests)
82
+ @participants = @account.conferences.get('CFbbe46ff1274e283f7e3ac1df0072ab39').participants
83
+
84
+ # list participants (http request here)
85
+ @participants.list.each do {|p| puts p.sid}
86
+
87
+ # update a conference participant
88
+ @participants.get('CA386025c9bf5d6052a1d1ea42b4d16662').update({:muted => 'true'})
89
+ # or an easier way
90
+ @participants.get('CA386025c9bf5d6052a1d1ea42b4d16662').mute
91
+
92
+ # and, since we're lazy loading, this would only incur one http request
93
+ @account.conferences.get('CFbbe46ff1274e283f7e3ac1df0072ab39').participants.get('CA386025c9bf5d6052a1d1ea42b4d16662').update({:muted => 'true'})
@@ -0,0 +1,36 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'builder'
4
+ require 'crack'
5
+ require 'cgi'
6
+
7
+ require 'twilio-ruby/utils'
8
+ require 'twilio-ruby/list_resource'
9
+ require 'twilio-ruby/instance_resource'
10
+ require 'twilio-ruby/sandbox/sandbox'
11
+ require 'twilio-ruby/accounts/account'
12
+ require 'twilio-ruby/accounts/accounts'
13
+ require 'twilio-ruby/calls/call'
14
+ require 'twilio-ruby/calls/calls'
15
+ require 'twilio-ruby/sms_messages/sms_message'
16
+ require 'twilio-ruby/sms_messages/sms_messages'
17
+ require 'twilio-ruby/outgoing_caller_ids/outgoing_caller_id'
18
+ require 'twilio-ruby/outgoing_caller_ids/outgoing_caller_ids'
19
+ require 'twilio-ruby/incoming_phone_numbers/incoming_phone_number'
20
+ require 'twilio-ruby/incoming_phone_numbers/incoming_phone_numbers'
21
+ require 'twilio-ruby/available_phone_numbers/available_phone_number'
22
+ require 'twilio-ruby/available_phone_numbers/available_phone_numbers'
23
+ require 'twilio-ruby/available_phone_numbers/country'
24
+ require 'twilio-ruby/available_phone_numbers/local'
25
+ require 'twilio-ruby/available_phone_numbers/toll_free'
26
+ require 'twilio-ruby/conferences/conference'
27
+ require 'twilio-ruby/conferences/conferences'
28
+ require 'twilio-ruby/conferences/participant'
29
+ require 'twilio-ruby/conferences/participants'
30
+ require 'twilio-ruby/recordings/recording'
31
+ require 'twilio-ruby/recordings/recordings'
32
+ require 'twilio-ruby/transcriptions/transcription'
33
+ require 'twilio-ruby/transcriptions/transcriptions'
34
+ require 'twilio-ruby/notifications/notification'
35
+ require 'twilio-ruby/notifications/notifications'
36
+ require 'twilio-ruby/client'
@@ -0,0 +1,10 @@
1
+ module Twilio
2
+ class Account < InstanceResource
3
+ def initialize(uri, client, params={})
4
+ super uri, client, params
5
+ resource :sandbox, :available_phone_numbers, :incoming_phone_numbers,
6
+ :calls, :outgoing_caller_ids, :conferences, :sms_messages, :recordings,
7
+ :transcriptions, :notifications
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Accounts < ListResource; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class AvailablePhoneNumber < InstanceResource; end
3
+ end
@@ -0,0 +1,9 @@
1
+ module Twilio
2
+ class AvailablePhoneNumbers < ListResource
3
+ def initialize(uri, client)
4
+ @resource_name = 'countries'
5
+ @instance_class = Twilio.const_get 'Country'
6
+ @uri, @client = uri, client
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Twilio
2
+ class Country < InstanceResource
3
+ def initialize(uri, client, params={})
4
+ super uri, client, params
5
+ resource :local, :toll_free
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Twilio
2
+ class Local < ListResource
3
+ def initialize(uri, client)
4
+ @resource_name = 'available_phone_numbers'
5
+ @instance_class = Twilio.const_get 'AvailablePhoneNumber'
6
+ @uri, @client = uri, client
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Twilio
2
+ class TollFree < ListResource
3
+ def initialize(uri, client)
4
+ @resource_name = 'available_phone_numbers'
5
+ @instance_class = Twilio.const_get 'AvailablePhoneNumber'
6
+ @uri, @client = uri, client
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module Twilio
2
+ class Call < InstanceResource
3
+ def initialize(uri, client, params={})
4
+ super uri, client, params
5
+ resource :recordings, :transcriptions
6
+ end
7
+
8
+ def redirect_to(url)
9
+ update :url => url
10
+ end
11
+
12
+ def cancel
13
+ update :status => 'canceled'
14
+ end
15
+
16
+ def hangup
17
+ update :status => 'completed'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Twilio
2
+ class Calls < ListResource
3
+ def make(from, to, url)
4
+ create :from => from, :to => to, :url => url
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ module Twilio
2
+ class Client
3
+ include Utils
4
+
5
+ attr_reader :api_version, :domain, :account_sid, :account, :accounts
6
+
7
+ def initialize(account_sid, auth_token, api_version='2010-04-01',
8
+ domain='api.twilio.com', proxy=nil)
9
+ @account_sid = account_sid
10
+ @auth_token = auth_token
11
+ @api_version = api_version
12
+ set_up_connection_to domain, proxy
13
+ set_up_subresources
14
+ end
15
+
16
+ # Define some helper methods for sending HTTP requests
17
+ [:get, :put, :post, :delete].each do |method|
18
+ method_class = Net::HTTP.const_get method.to_s.capitalize
19
+ define_method method do |uri, *args|
20
+ uri += '.json'
21
+ params = (args[0] && args[0] != {}) ? twilify(args[0]) : nil
22
+ uri += "?#{url_encode(params)}" if params && method == :get
23
+ request = method_class.new uri
24
+ request.basic_auth @account_sid, @auth_token
25
+ request.form_data = params if params && [:post, :put].include?(method)
26
+ puts "DEBUG: Request Path ==> "+request.path
27
+ puts "DEBUG: Request Body ==> "+request.body if request.body
28
+ http_response = @connection.request request
29
+ object = Crack::JSON.parse http_response.body if http_response.body
30
+ raise object['message'] unless http_response.kind_of? Net::HTTPSuccess
31
+ object
32
+ end
33
+ end
34
+
35
+ def request(uri, method, params={})
36
+ send method.downcase.to_sym, uri, params
37
+ end
38
+
39
+ private
40
+
41
+ def set_up_connection_to(domain, proxy)
42
+ @connection = Net::HTTP.new domain, 443
43
+ @connection.use_ssl = true
44
+ # Don't check the server cert. Ideally this is configurable, in case an
45
+ # app wants to verify that it is actually talking to the real Twilio.
46
+ @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
47
+ end
48
+
49
+ def set_up_subresources
50
+ accounts_uri = "/#{@api_version}/Accounts"
51
+ # Set up a special handle to grab the account.
52
+ @account = Twilio::Account.new "#{accounts_uri}/#{@account_sid}", self
53
+ # Set up the accounts subresource.
54
+ @accounts = Twilio::Accounts.new accounts_uri, self
55
+ end
56
+
57
+ def url_encode(hash)
58
+ hash.to_a.map {|pair| pair.map {|e| CGI.escape e.to_s}.join '='}.join '&'
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,8 @@
1
+ module Twilio
2
+ class Conference < InstanceResource
3
+ def initialize(uri, client, params={})
4
+ super uri, client, params
5
+ resource :participants
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Conferences < ListResource; end
3
+ end
@@ -0,0 +1,15 @@
1
+ module Twilio
2
+ class Participant < InstanceResource
3
+
4
+ def mute
5
+ update :muted => 'true'
6
+ end
7
+
8
+ def unmute
9
+ update :muted => 'false'
10
+ end
11
+
12
+ alias :kick :delete
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Participants < ListResource; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class IncomingPhoneNumber < InstanceResource; end
3
+ end
@@ -0,0 +1,7 @@
1
+ module Twilio
2
+ class IncomingPhoneNumbers < ListResource
3
+ def buy(phone_number)
4
+ create :phone_number => phone_number
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,53 @@
1
+ module Twilio
2
+ class InstanceResource
3
+ include Utils
4
+
5
+ def initialize(uri, client, params={})
6
+ @uri, @client = uri, client
7
+ set_up_properties_from params
8
+ end
9
+
10
+ def update(params={})
11
+ raise "Can't update a resource without a Twilio::Client" unless @client
12
+ response = @client.post @uri, params
13
+ set_up_properties_from response
14
+ self
15
+ end
16
+
17
+ def delete
18
+ raise "Can't delete a resource without a Twilio::Client" unless @client
19
+ @client.delete @uri
20
+ end
21
+
22
+ def method_missing(method, *args)
23
+ super if @updated
24
+ response = @client.get @uri
25
+ set_up_properties_from response
26
+ self.send method, *args
27
+ end
28
+
29
+ protected
30
+
31
+ def set_up_properties_from(hash)
32
+ eigenclass = class << self; self; end
33
+ hash.each do |p,v|
34
+ property = detwilify p
35
+ unless ['uri', 'client', 'updated'].include? property
36
+ eigenclass.send :define_method, property.to_sym, &lambda {v}
37
+ end
38
+ end
39
+ @updated = !hash.keys.empty?
40
+ end
41
+
42
+ def resource(*resources)
43
+ resources.each do |r|
44
+ resource = twilify r
45
+ relative_uri = r == :sms_messages ? 'SMS/Messages' : resource
46
+ instance_variable_set("@#{r}",
47
+ Twilio.const_get(resource).new("#{@uri}/#{relative_uri}", @client))
48
+ end
49
+ self.class.instance_eval {attr_reader *resources}
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ module Twilio
2
+ class ListResource
3
+ include Utils
4
+
5
+ def initialize(uri, client)
6
+ @resource_name = self.class.name.split('::')[-1]
7
+ @instance_class = Twilio.const_get @resource_name.chop
8
+ @uri, @client = uri, client
9
+ end
10
+
11
+ # Grab a list of this kind of resource and return it as an array.
12
+ def list(params={})
13
+ raise "Can't get a resource list without a Twilio::Client" unless @client
14
+ response = @client.get @uri, params
15
+ resources = response[detwilify(@resource_name)]
16
+ resources.map do |resource|
17
+ @instance_class.new "#{@uri}/#{resource['sid']}", @client, resource
18
+ end
19
+ end
20
+
21
+ # Return an empty instance resource object with the proper URI.
22
+ def get(sid)
23
+ @instance_class.new "#{@uri}/#{sid}", @client
24
+ end
25
+
26
+ # Return a newly created resource.
27
+ def create(params={})
28
+ raise "Can't create a resource without a Twilio::Client" unless @client
29
+ response = @client.post @uri, params
30
+ @instance_class.new "#{@uri}/#{response['sid']}", @client, response
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Notification < InstanceResource; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Notifications < ListResource; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class OutgoingCallerId < InstanceResource; end
3
+ end
@@ -0,0 +1,7 @@
1
+ module Twilio
2
+ class OutgoingCallerIds < ListResource
3
+ def add(phone_number)
4
+ create :phone_number => phone_number
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Twilio
2
+ class Recording < InstanceResource
3
+
4
+ def initialize(uri, client, params={})
5
+ super uri, client, params
6
+ resource :transcriptions
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Recordings < ListResource; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Sandbox < InstanceResource; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class SmsMessage < InstanceResource; end
3
+ end
@@ -0,0 +1,7 @@
1
+ module Twilio
2
+ class SmsMessages < ListResource
3
+ def send(from, to, body)
4
+ create :from => from, :to => to, :body => body
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Transcription < InstanceResource; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Twilio
2
+ class Transcriptions < ListResource; end
3
+ end
@@ -0,0 +1,23 @@
1
+ module Twilio
2
+ module Utils
3
+
4
+ def twilify(something)
5
+ if something.is_a? Hash
6
+ Hash[*something.to_a.map {|a| [twilify(a[0]).to_sym, a[1]]}.flatten]
7
+ else
8
+ something.to_s.split('_').map do |s|
9
+ [s[0,1].capitalize, s[1..-1]].join
10
+ end.join
11
+ end
12
+ end
13
+
14
+ def detwilify(something)
15
+ if something.is_a? Hash
16
+ Hash[*something.to_a.map {|pair| [detwilify(pair[0]).to_sym, pair[1]]}.flatten]
17
+ else
18
+ something.to_s.gsub(/[A-Z][a-z]*/) {|s| "_#{s.downcase}"}.gsub(/^_/, '')
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Twilio
2
+ class Verb
3
+
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require File.dirname(__FILE__) + '/../lib/twilio'
2
+
3
+ twilio = Twilio::Client.new('AC2ae18c3d1a42ddb2eea67f8bef081728', 'd15433e698105a045e9d3cd84ed0c909')
4
+ puts twilio.get('/')
5
+
6
+
@@ -0,0 +1,139 @@
1
+ require 'rubygems'
2
+ require 'twilio-ruby'
3
+ require 'fakeweb'
4
+
5
+ describe Twilio::Client do
6
+ before :all do
7
+ FakeWeb.register_uri(:any, %r/http:\/\/api.twilio.com\//, :body => '{"message": "You tried to reach Twilio"}')
8
+ end
9
+
10
+ it 'should set up a Twilio::Client' do
11
+ twilio = Twilio::Client.new('someSid', 'someToken', 'api-version')
12
+ twilio.account_sid.should == 'someSid'
13
+ twilio.instance_variable_get('@auth_token').should == 'someToken'
14
+ twilio.api_version.should == 'api-version'
15
+ end
16
+
17
+ it 'should set up the proper default http ssl connection' do
18
+ twilio = Twilio::Client.new('someSid', 'someToken')
19
+ twilio.instance_variable_get('@connection').address.should == 'api.twilio.com'
20
+ twilio.instance_variable_get('@connection').port.should == 443
21
+ twilio.instance_variable_get('@connection').use_ssl?.should == true
22
+ end
23
+
24
+ it 'should set up the proper http ssl connection when a different domain is given' do
25
+ twilio = Twilio::Client.new('someSid', 'someToken', '2008-08-01', 'api.faketwilio.com')
26
+ twilio.instance_variable_get('@connection').address.should == 'api.faketwilio.com'
27
+ twilio.instance_variable_get('@connection').port.should == 443
28
+ twilio.instance_variable_get('@connection').use_ssl?.should == true
29
+ end
30
+
31
+ it 'should set up an accounts resources object' do
32
+ twilio = Twilio::Client.new('someSid', 'someToken')
33
+ twilio.respond_to?(:accounts).should == true
34
+ twilio.accounts.instance_variable_get('@uri').should == '/2010-04-01/Accounts'
35
+ end
36
+
37
+ it 'should set up an account object with the given sid' do
38
+ twilio = Twilio::Client.new('someSid', 'someToken')
39
+ twilio.respond_to?(:account).should == true
40
+ twilio.account.instance_variable_get('@uri').should == '/2010-04-01/Accounts/someSid'
41
+ end
42
+
43
+ it 'should convert all parameter names to Twilio-style names' do
44
+ twilio = Twilio::Client.new('someSid', 'someToken')
45
+ untwilified = {:sms_url => 'someUrl', 'voiceFallbackUrl' => 'anotherUrl',
46
+ 'Status_callback' => 'yetAnotherUrl'}
47
+ twilified = {:SmsUrl => 'someUrl', :VoiceFallbackUrl => 'anotherUrl',
48
+ :StatusCallback => 'yetAnotherUrl'}
49
+ twilio.instance_eval do
50
+ twilify(untwilified).should == twilified
51
+ end
52
+ end
53
+ end
54
+
55
+ describe Twilio::Account do
56
+ it 'should set up an incoming phone numbers resources object' do
57
+ account = Twilio::Account.new('someUri', 'someClient')
58
+ account.respond_to?(:incoming_phone_numbers).should == true
59
+ account.incoming_phone_numbers.instance_variable_get('@uri').should == 'someUri/IncomingPhoneNumbers'
60
+ end
61
+
62
+ it 'should set up an available phone numbers resources object' do
63
+ account = Twilio::Account.new('someUri', 'someClient')
64
+ account.respond_to?(:available_phone_numbers).should == true
65
+ account.available_phone_numbers.instance_variable_get('@uri').should == 'someUri/AvailablePhoneNumbers'
66
+ end
67
+
68
+ it 'should set up an outgoing caller ids resources object' do
69
+ account = Twilio::Account.new('someUri', 'someClient')
70
+ account.respond_to?(:outgoing_caller_ids).should == true
71
+ account.outgoing_caller_ids.instance_variable_get('@uri').should == 'someUri/OutgoingCallerIds'
72
+ end
73
+
74
+ it 'should set up a calls resources object' do
75
+ account = Twilio::Account.new('someUri', 'someClient')
76
+ account.respond_to?(:calls).should == true
77
+ account.calls.instance_variable_get('@uri').should == 'someUri/Calls'
78
+ end
79
+
80
+ it 'should set up a conferences resources object' do
81
+ account = Twilio::Account.new('someUri', 'someClient')
82
+ account.respond_to?(:conferences).should == true
83
+ account.conferences.instance_variable_get('@uri').should == 'someUri/Conferences'
84
+ end
85
+
86
+ it 'should set up a sms messages resources object' do
87
+ account = Twilio::Account.new('someUri', 'someClient')
88
+ account.respond_to?(:sms_messages).should == true
89
+ account.sms_messages.instance_variable_get('@uri').should == 'someUri/SMS/Messages'
90
+ end
91
+
92
+ it 'should set up a recordings resources object' do
93
+ account = Twilio::Account.new('someUri', 'someClient')
94
+ account.respond_to?(:recordings).should == true
95
+ account.recordings.instance_variable_get('@uri').should == 'someUri/Recordings'
96
+ end
97
+
98
+ it 'should set up a transcriptions resources object' do
99
+ account = Twilio::Account.new('someUri', 'someClient')
100
+ account.respond_to?(:transcriptions).should == true
101
+ account.transcriptions.instance_variable_get('@uri').should == 'someUri/Transcriptions'
102
+ end
103
+
104
+ it 'should set up a notifications resources object' do
105
+ account = Twilio::Account.new('someUri', 'someClient')
106
+ account.respond_to?(:notifications).should == true
107
+ account.notifications.instance_variable_get('@uri').should == 'someUri/Notifications'
108
+ end
109
+ end
110
+
111
+ describe Twilio::Call do
112
+ it 'should set up a recordings resources object' do
113
+ call = Twilio::Call.new('someUri', 'someClient')
114
+ call.respond_to?(:recordings).should == true
115
+ call.recordings.instance_variable_get('@uri').should == 'someUri/Recordings'
116
+ end
117
+
118
+ it 'should set up a recordings resources object' do
119
+ call = Twilio::Call.new('someUri', 'someClient')
120
+ call.respond_to?(:transcriptions).should == true
121
+ call.transcriptions.instance_variable_get('@uri').should == 'someUri/Transcriptions'
122
+ end
123
+ end
124
+
125
+ describe Twilio::Conference do
126
+ it 'should set up a participants resources object' do
127
+ call = Twilio::Conference.new('someUri', 'someClient')
128
+ call.respond_to?(:participants).should == true
129
+ call.participants.instance_variable_get('@uri').should == 'someUri/Participants'
130
+ end
131
+ end
132
+
133
+ describe Twilio::Recording do
134
+ it 'should set up a transcriptions resources object' do
135
+ call = Twilio::Recording.new('someUri', 'someClient')
136
+ call.respond_to?(:transcriptions).should == true
137
+ call.transcriptions.instance_variable_get('@uri').should == 'someUri/Transcriptions'
138
+ end
139
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twilio-ruby
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Benton
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-31 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: builder
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 1
33
+ - 2
34
+ version: 2.1.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: crack
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 11
46
+ segments:
47
+ - 0
48
+ - 1
49
+ - 8
50
+ version: 0.1.8
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: A simple library for communicating with the Twilio REST API
54
+ email: andrewmbenton@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - lib/twilio-ruby.rb
63
+ - lib/twilio-ruby/sms_messages/sms_message.rb
64
+ - lib/twilio-ruby/sms_messages/sms_messages.rb
65
+ - lib/twilio-ruby/client.rb
66
+ - lib/twilio-ruby/verb.rb
67
+ - lib/twilio-ruby/list_resource.rb
68
+ - lib/twilio-ruby/incoming_phone_numbers/incoming_phone_number.rb
69
+ - lib/twilio-ruby/incoming_phone_numbers/incoming_phone_numbers.rb
70
+ - lib/twilio-ruby/conferences/participant.rb
71
+ - lib/twilio-ruby/conferences/conference.rb
72
+ - lib/twilio-ruby/conferences/conferences.rb
73
+ - lib/twilio-ruby/conferences/participants.rb
74
+ - lib/twilio-ruby/transcriptions/transcriptions.rb
75
+ - lib/twilio-ruby/transcriptions/transcription.rb
76
+ - lib/twilio-ruby/calls/call.rb
77
+ - lib/twilio-ruby/calls/calls.rb
78
+ - lib/twilio-ruby/utils.rb
79
+ - lib/twilio-ruby/accounts/accounts.rb
80
+ - lib/twilio-ruby/accounts/account.rb
81
+ - lib/twilio-ruby/recordings/recording.rb
82
+ - lib/twilio-ruby/recordings/recordings.rb
83
+ - lib/twilio-ruby/notifications/notification.rb
84
+ - lib/twilio-ruby/notifications/notifications.rb
85
+ - lib/twilio-ruby/outgoing_caller_ids/outgoing_caller_id.rb
86
+ - lib/twilio-ruby/outgoing_caller_ids/outgoing_caller_ids.rb
87
+ - lib/twilio-ruby/available_phone_numbers/country.rb
88
+ - lib/twilio-ruby/available_phone_numbers/local.rb
89
+ - lib/twilio-ruby/available_phone_numbers/available_phone_number.rb
90
+ - lib/twilio-ruby/available_phone_numbers/available_phone_numbers.rb
91
+ - lib/twilio-ruby/available_phone_numbers/toll_free.rb
92
+ - lib/twilio-ruby/sandbox/sandbox.rb
93
+ - lib/twilio-ruby/instance_resource.rb
94
+ - test/twilio_spec.rb
95
+ - test/test_twilio.rb
96
+ - examples.rb
97
+ - Rakefile
98
+ has_rdoc: true
99
+ homepage: http://github.com/andrewmbenton/twilio-ruby
100
+ licenses: []
101
+
102
+ post_install_message:
103
+ rdoc_options: []
104
+
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirements: []
126
+
127
+ rubyforge_project:
128
+ rubygems_version: 1.4.2
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: A simple library for communicating with the Twilio REST API
132
+ test_files:
133
+ - test/twilio_spec.rb
134
+ - test/test_twilio.rb