Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 151 lines (111 sloc) 3.683 kb
9b7948a Andrew Benton readme cleanup
andrewmbenton authored
1 ## Install
c8a763e Andrew Benton new twilio-ruby finally :)
andrewmbenton authored
2
3 Via rubygems.org:
4
5 ```
a76836f Andrew Benton removed straggling reference to andrewmbenton/twilio-ruby from README
andrewmbenton authored
6 $ gem install twilio-ruby
c8a763e Andrew Benton new twilio-ruby finally :)
andrewmbenton authored
7 ```
8
a76836f Andrew Benton removed straggling reference to andrewmbenton/twilio-ruby from README
andrewmbenton authored
9 To build and install the development branch yourself from the latest source:
c8a763e Andrew Benton new twilio-ruby finally :)
andrewmbenton authored
10
11 ```
a76836f Andrew Benton removed straggling reference to andrewmbenton/twilio-ruby from README
andrewmbenton authored
12 $ git clone git@github.com:twilio/twilio-ruby.git
13 $ cd twilio-ruby
14 $ git checkout develop
15 $ rake gem
16 $ gem install pkg/twilio-ruby-{version}
c8a763e Andrew Benton new twilio-ruby finally :)
andrewmbenton authored
17 ```
18
cd1f4d8 Andrew Benton readme update
andrewmbenton authored
19 ## Get Started With Client Capability Tokens
20
21 If you just need to generate a Capability Token for use with Twilio Client, you
22 can do this:
23
24 ``` ruby
25 require 'rubygems' # not necessary with ruby 1.9 but included for completeness
26 require 'twilio-ruby'
27
28 # put your own account credentials here:
29 account_sid = 'AC043dcf9844e13758bc3a36a84c29761'
30 auth_token = '62ea81de3a5b413254eb263595357c69'
31
32 # set up
33 capability = Twilio::Util::Capability.new account_sid, auth_token
34
35 # allow outgoing calls to an application
36 capability.allow_client_outgoing 'AP89a0180a1a4ddf1da954efca349b7a20'
37
38 # allow incoming calls to 'andrew'
39 capability.allow_client_incoming 'andrew'
40
41 # generate the token string
42 @token = capability.generate
43 ```
44
45 There is a slightly more detailed document in the
46 [Capability](twilio-ruby/wiki/Capability) section of the wiki.
47
48 ## Getting Started with TwiML
49
50 TwiML support is based on the [builder][1] library. You can construct a TwiML
51 response like this:
52
53 ``` ruby
54 require 'rubygems' # not necessary with ruby 1.9 but included for completeness
55 require 'twilio-ruby'
56
57 # build up a response
58 response = Twilio::TwiML::Response.new do |r|
59 r.Say 'hello there', :voice => 'woman'
60 r.Dial :callerId => '+14159992222' do |d|
61 d.Client 'jenny'
62 end
63 end
64
65 # print the result
66 puts response.text
67 ```
68
69 This will print the following (except for the whitespace):
70
71 ```
72 <?xml version="1.0" encoding="UTF-8"?>
73 <Response>
74 <Say voice="woman">hello there</Say>
75 <Dial callerId="+14159992222">
76 <Client>jenny</Client>
77 </Dial>
78 </Response>
79 ```
80
81 ## Getting Started with REST
c8a763e Andrew Benton new twilio-ruby finally :)
andrewmbenton authored
82
83 ### Setup Work
84
85 ``` ruby
cd1f4d8 Andrew Benton readme update
andrewmbenton authored
86 require 'rubygems' # not necessary with ruby 1.9 but included for completeness
c8a763e Andrew Benton new twilio-ruby finally :)
andrewmbenton authored
87 require 'twilio-ruby'
88
89 # put your own credentials here
cd1f4d8 Andrew Benton readme update
andrewmbenton authored
90 account_sid = 'AC043dcf9844e04758bc3a36a84c29761'
91 auth_token = '62ea81de3a5b414154eb263595357c69'
c8a763e Andrew Benton new twilio-ruby finally :)
andrewmbenton authored
92
93 # set up a client to talk to the Twilio REST API
cd1f4d8 Andrew Benton readme update
andrewmbenton authored
94 @client = Twilio::REST::Client.new account_sid, auth_token
c8a763e Andrew Benton new twilio-ruby finally :)
andrewmbenton authored
95 ```
96
97 ### Send an SMS
98
99 ``` ruby
100 # send an sms
101 @client.account.sms.messages.create(
102 :from => '+14159341234',
103 :to => '+16105557069',
104 :body => 'Hey there!'
105 )
106 ```
107
108 ### Do Some Stuff With Calls
109
110 ``` ruby
111 # make a new outgoing call
112 @call = @client.account.calls.create(
113 :from => '+14159341234',
114 :to => '+18004567890',
115 :url => 'http://myapp.com/call-handler'
116 )
117
118 # hangup a ringing call, but don't touch it if it's connected
119 @call.cancel
120
121 # if you have the call sid, you can fetch a call object via:
122 @call = @client.account.calls.get('CA386025c9bf5d6052a1d1ea42b4d16662')
123
124 # redirect an in-progress call
125 @call.redirect_to('http://myapp.com/call-redirect')
126
127 # hangup a call, no matter whether it is ringing or connected
128 @call.hangup
129 ```
130
131 ### Buy a Phone Number
132
133 ``` ruby
134 # print some available numbers
135 @numbers = @client.account.available_phone_numbers.get('US').local.list(
136 :contains => 'AWESOME'
137 )
138 @numbers.each {|num| puts num.phone_number}
139
140 # buy the first one
141 @number = @numbers[0].phone_number
142 @account.incoming_phone_numbers.create(:phone_number => @number)
143 ```
144
145 ## More Information
146
147 There are more detailed examples in the included [examples.rb](twilio-ruby/blob/master/examples.rb).
148
d87c0a7 Andrew Benton updating builder link reference
andrewmbenton authored
149 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).
150
151 [1]:http://builder.rubyforge.org/
Something went wrong with that request. Please try again.