Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 87 lines (63 sloc) 2.041 kb
c8a763e @andrewmbenton new twilio-ruby finally :)
andrewmbenton authored
1 ## Get Started
2
3 To install:
4
5 Via rubygems.org:
6
7 ```
8 $ sudo gem install twilio-ruby
9 ```
10
11 To build and install yourself from the latest source:
12
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).
Something went wrong with that request. Please try again.