Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 89 lines (65 sloc) 2.133 kb
c8a763e @andrewmbenton new twilio-ruby finally :)
andrewmbenton authored
1 ## Get Started
2
3 To install:
4
5 Via rubygems.org:
6
7 ```
a76836f @andrewmbenton removed straggling reference to andrewmbenton/twilio-ruby from README
andrewmbenton authored
8 $ gem install twilio-ruby
c8a763e @andrewmbenton new twilio-ruby finally :)
andrewmbenton authored
9 ```
10
a76836f @andrewmbenton removed straggling reference to andrewmbenton/twilio-ruby from README
andrewmbenton authored
11 To build and install the development branch yourself from the latest source:
c8a763e @andrewmbenton new twilio-ruby finally :)
andrewmbenton authored
12
13 ```
a76836f @andrewmbenton removed straggling reference to andrewmbenton/twilio-ruby from README
andrewmbenton authored
14 $ git clone git@github.com:twilio/twilio-ruby.git
15 $ cd twilio-ruby
16 $ git checkout develop
17 $ rake gem
18 $ gem install pkg/twilio-ruby-{version}
c8a763e @andrewmbenton new twilio-ruby finally :)
andrewmbenton authored
19 ```
20
21 ## Some Code To Get You Started
22
23 ### Setup Work
24
25 ``` ruby
a76836f @andrewmbenton removed straggling reference to andrewmbenton/twilio-ruby from README
andrewmbenton authored
26 require 'rubygems' # not necessary with ruby 1.9.2 but included for completeness
c8a763e @andrewmbenton new twilio-ruby finally :)
andrewmbenton authored
27 require 'twilio-ruby'
28
29 # put your own credentials here
30 @account_sid = 'AC043dcf9844e04758bc3a36a84c29761'
31 @auth_token = '62ea81de3a5b414154eb263595357c69'
32
33 # set up a client to talk to the Twilio REST API
34 @client = Twilio::REST::Client.new(@account_sid, @auth_token)
35 ```
36
37 ### Send an SMS
38
39 ``` ruby
40 # send an sms
41 @client.account.sms.messages.create(
42 :from => '+14159341234',
43 :to => '+16105557069',
44 :body => 'Hey there!'
45 )
46 ```
47
48 ### Do Some Stuff With Calls
49
50 ``` ruby
51 # make a new outgoing call
52 @call = @client.account.calls.create(
53 :from => '+14159341234',
54 :to => '+18004567890',
55 :url => 'http://myapp.com/call-handler'
56 )
57
58 # hangup a ringing call, but don't touch it if it's connected
59 @call.cancel
60
61 # if you have the call sid, you can fetch a call object via:
62 @call = @client.account.calls.get('CA386025c9bf5d6052a1d1ea42b4d16662')
63
64 # redirect an in-progress call
65 @call.redirect_to('http://myapp.com/call-redirect')
66
67 # hangup a call, no matter whether it is ringing or connected
68 @call.hangup
69 ```
70
71 ### Buy a Phone Number
72
73 ``` ruby
74 # print some available numbers
75 @numbers = @client.account.available_phone_numbers.get('US').local.list(
76 :contains => 'AWESOME'
77 )
78 @numbers.each {|num| puts num.phone_number}
79
80 # buy the first one
81 @number = @numbers[0].phone_number
82 @account.incoming_phone_numbers.create(:phone_number => @number)
83 ```
84
85 ## More Information
86
87 There are more detailed examples in the included [examples.rb](twilio-ruby/blob/master/examples.rb).
88
89 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).
Something went wrong with that request. Please try again.