Skip to content
This repository
Newer
Older
100644 160 lines (119 sloc) 3.946 kb
9b7948a5 »
2011-07-22 readme cleanup
1 ## Install
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
2
3 Via rubygems.org:
4
5 ```
a76836fa »
2011-07-21 removed straggling reference to andrewmbenton/twilio-ruby from README
6 $ gem install twilio-ruby
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
7 ```
8
a76836fa »
2011-07-21 removed straggling reference to andrewmbenton/twilio-ruby from README
9 To build and install the development branch yourself from the latest source:
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
10
11 ```
a76836fa »
2011-07-21 removed straggling reference to andrewmbenton/twilio-ruby from README
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}
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
17 ```
18
4d745000 »
2011-09-16 slight readme changes
19 ## Getting Started With REST
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
20
21 ### Setup Work
22
23 ``` ruby
cd1f4d85 »
2011-07-30 readme update
24 require 'rubygems' # not necessary with ruby 1.9 but included for completeness
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
25 require 'twilio-ruby'
26
27 # put your own credentials here
73323b99 »
2012-01-07 make it more clear that sid & auth token must be modified.
28 account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
29 auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
30
31 # set up a client to talk to the Twilio REST API
cd1f4d85 »
2011-07-30 readme update
32 @client = Twilio::REST::Client.new account_sid, auth_token
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
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',
957832c7 »
2012-08-08 s/myapp.com/example.com/g
53 :url => 'http://example.com/call-handler'
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
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
957832c7 »
2012-08-08 s/myapp.com/example.com/g
63 @call.redirect_to('http://example.com/call-redirect')
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
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
6c29252f »
2011-09-05 readme cleanup
80 @client.account.incoming_phone_numbers.create(:phone_number => @number)
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
81 ```
82
8db543dd »
2011-10-14 move rest api details to top
83 ## Getting Started With Client Capability Tokens
84
85 If you just need to generate a Capability Token for use with Twilio Client, you
86 can do this:
87
88 ``` ruby
89 require 'rubygems' # not necessary with ruby 1.9 but included for completeness
90 require 'twilio-ruby'
91
92 # put your own account credentials here:
93 account_sid = 'AC043dcf9844e13758bc3a36a84c29761'
94 auth_token = '62ea81de3a5b413254eb263595357c69'
95
96 # set up
97 capability = Twilio::Util::Capability.new account_sid, auth_token
98
99 # allow outgoing calls to an application
100 capability.allow_client_outgoing 'AP89a0180a1a4ddf1da954efca349b7a20'
101
102 # allow incoming calls to 'andrew'
103 capability.allow_client_incoming 'andrew'
104
105 # generate the token string
106 @token = capability.generate
107 ```
108
109 There is a slightly more detailed document in the [Capability][capability]
110 section of the wiki.
111
112 ## Getting Started With TwiML
113
114 TwiML support is based on the [builder][builder] library. You can construct a
115 TwiML response like this:
116
117 ``` ruby
118 require 'rubygems' # not necessary with ruby 1.9 but included for completeness
119 require 'twilio-ruby'
120
121 # build up a response
122 response = Twilio::TwiML::Response.new do |r|
123 r.Say 'hello there', :voice => 'woman'
124 r.Dial :callerId => '+14159992222' do |d|
125 d.Client 'jenny'
126 end
127 end
128
129 # print the result
130 puts response.text
131 ```
132
133 This will print the following (except for the whitespace):
134
135 ```
136 <?xml version="1.0" encoding="UTF-8"?>
137 <Response>
138 <Say voice="woman">hello there</Say>
139 <Dial callerId="+14159992222">
140 <Client>jenny</Client>
141 </Dial>
142 </Response>
143 ```
144
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
145 ## More Information
146
99b9192c »
2012-03-24 link to the examples directory
147 There are more detailed examples in the included [examples][examples]
148 directory.
c8a763e3 »
2011-07-15 new twilio-ruby finally :)
149
6f12b202 »
2011-09-28 making README.md universally accessible and killing README.rdoc
150 Full [API documentation][documentation], as well as an [upgrade guide][upgrade]
151 for users of the old twiliolib gem, is available in the
152 [twilio-ruby github wiki][wiki].
d87c0a76 »
2011-07-30 updating builder link reference
153
6f12b202 »
2011-09-28 making README.md universally accessible and killing README.rdoc
154 [capability]:https://github.com/twilio/twilio-ruby/wiki/Capability
155 [builder]:http://builder.rubyforge.org/
99b9192c »
2012-03-24 link to the examples directory
156 [examples]:https://github.com/twilio/twilio-ruby/blob/master/examples
6f12b202 »
2011-09-28 making README.md universally accessible and killing README.rdoc
157 [documentation]:https://github.com/twilio/twilio-ruby/wiki/Documentation
158 [upgrade]:https://github.com/twilio/twilio-ruby/wiki/UpgradeGuide
8db543dd »
2011-10-14 move rest api details to top
159 [wiki]:https://github.com/twilio/twilio-ruby/wiki
Something went wrong with that request. Please try again.