slayer-twilio 3.0.1

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 (65) hide show
  1. data/.gitignore +8 -0
  2. data/CHANGELOG.rdoc +31 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +63 -0
  6. data/Rakefile +9 -0
  7. data/lib/twilio.rb +53 -0
  8. data/lib/twilio/account.rb +12 -0
  9. data/lib/twilio/available_phone_numbers.rb +56 -0
  10. data/lib/twilio/call.rb +37 -0
  11. data/lib/twilio/conference.rb +35 -0
  12. data/lib/twilio/incoming_phone_number.rb +30 -0
  13. data/lib/twilio/notification.rb +20 -0
  14. data/lib/twilio/outgoing_caller_id.rb +33 -0
  15. data/lib/twilio/recording.rb +24 -0
  16. data/lib/twilio/sms.rb +22 -0
  17. data/lib/twilio/twilio_object.rb +19 -0
  18. data/lib/twilio/verb.rb +387 -0
  19. data/lib/twilio/version.rb +3 -0
  20. data/spec/fixtures/xml/account.xml +23 -0
  21. data/spec/fixtures/xml/account_renamed.xml +11 -0
  22. data/spec/fixtures/xml/available_phone_numbers_local.xml +26 -0
  23. data/spec/fixtures/xml/available_phone_numbers_local_search.xml +15 -0
  24. data/spec/fixtures/xml/available_phone_numbers_toll_free.xml +14 -0
  25. data/spec/fixtures/xml/available_phone_numbers_toll_free_search.xml +10 -0
  26. data/spec/fixtures/xml/call.xml +18 -0
  27. data/spec/fixtures/xml/call_new.xml +14 -0
  28. data/spec/fixtures/xml/call_redirected.xml +15 -0
  29. data/spec/fixtures/xml/calls.xml +36 -0
  30. data/spec/fixtures/xml/conference.xml +10 -0
  31. data/spec/fixtures/xml/conference_participant.xml +12 -0
  32. data/spec/fixtures/xml/conference_participant_muted.xml +12 -0
  33. data/spec/fixtures/xml/conference_participants.xml +24 -0
  34. data/spec/fixtures/xml/conferences.xml +12 -0
  35. data/spec/fixtures/xml/incoming_phone_number.xml +12 -0
  36. data/spec/fixtures/xml/incoming_phone_numbers.xml +24 -0
  37. data/spec/fixtures/xml/notification.xml +19 -0
  38. data/spec/fixtures/xml/notifications.xml +32 -0
  39. data/spec/fixtures/xml/outgoing_caller_id.xml +10 -0
  40. data/spec/fixtures/xml/outgoing_caller_id_new.xml +7 -0
  41. data/spec/fixtures/xml/outgoing_caller_ids.xml +20 -0
  42. data/spec/fixtures/xml/recording.xml +10 -0
  43. data/spec/fixtures/xml/recordings.xml +20 -0
  44. data/spec/fixtures/xml/sms.xml +14 -0
  45. data/spec/fixtures/xml/sms_messages.xml +29 -0
  46. data/spec/fixtures/xml/sms_new.xml +14 -0
  47. data/spec/fixtures/xml/sms_new_with_callback.xml +15 -0
  48. data/spec/fixtures/xml/transcription.xml +13 -0
  49. data/spec/fixtures/xml/transcriptions.xml +26 -0
  50. data/spec/fixtures/yml/verb_responses.yml +86 -0
  51. data/spec/spec_helper.rb +17 -0
  52. data/spec/support/twilio_helpers.rb +52 -0
  53. data/spec/twilio/account_spec.rb +21 -0
  54. data/spec/twilio/available_phone_numbers_spec.rb +53 -0
  55. data/spec/twilio/call_spec.rb +64 -0
  56. data/spec/twilio/conference_spec.rb +58 -0
  57. data/spec/twilio/incoming_phone_number_spec.rb +42 -0
  58. data/spec/twilio/live_connection_spec.rb +21 -0
  59. data/spec/twilio/notification_spec.rb +29 -0
  60. data/spec/twilio/outgoing_caller_id_spec.rb +43 -0
  61. data/spec/twilio/recording_spec.rb +44 -0
  62. data/spec/twilio/sms_spec.rb +36 -0
  63. data/spec/twilio/verb_spec.rb +253 -0
  64. data/twilio.gemspec +30 -0
  65. metadata +258 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ *.gem
6
+ .bundle
7
+ Gemfile.lock
8
+ pkg/*
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = Twilio Gem Changelog
2
+
3
+ == 3.0.1
4
+
5
+ * Bumped down Builder version requirement for Rails compat
6
+
7
+ == 3.0
8
+
9
+ * SSL validation (thanks Kyle Humberto)
10
+ * Available phone numbers search support (thanks Mark Turner)
11
+ * Deprecated Twilio::Connection method has been removed, use Twilio.connect(...)
12
+ * LocalPhoneNumber and TollFreeNumber have been removed to reflect API changes
13
+ * New phone numbers are now provisioned via the IncomingPhoneNumber class
14
+ * Several classes improved to avoid adding a stray "?" when no params were set
15
+ * Compatibility with 1.9.2 (and tested on 1.8.7 MRI and REE)
16
+ * Now uses Bundler, Rspec 2, and WebMock
17
+
18
+ == 2.9
19
+
20
+ * Compatibility with Twilio's 2010-04-01 API publish
21
+
22
+ == 2.8
23
+
24
+ * SMS callback URLs
25
+ * Ability to delete phone numbers
26
+
27
+ == 2.7
28
+
29
+ * SMS functionality
30
+
31
+ For earlier versions, see https://github.com/webficient/twilio/commits/master
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in twilio.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2010 Phil Misiowiec, Webficient LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = Slayer's modifications:
2
+
3
+ * added Reject verb
4
+
5
+ = Twilio Gem
6
+
7
+ The Twilio gem provides two major pieces of functionality: (1) a Ruby wrapper for the Twilio REST API and (2) response handlers based on the Twilio Markup XML (TwiML).
8
+
9
+ See http://www.twilio.com/docs/index for Twilio's API documentation.
10
+
11
+ == Calling the Twilio REST API
12
+
13
+ First set your credentials by calling the connect method:
14
+
15
+ Twilio.connect('my_twilio_sid', 'my_auth_token')
16
+
17
+ Now call any of the Twilio classes:
18
+
19
+ Twilio::Call.make('1234567890', '9876543210', 'http://mysite.com/connected_call')
20
+ Twilio::Recording.list
21
+
22
+ == Responding to Twilio
23
+
24
+ When Twilio calls your application URL, your response must use the Twilio Markup XML (http://www.twilio.com/docs/api_reference/TwiML/). The Twilio gem makes this very easy
25
+ by providing a Twilio Verb class.
26
+
27
+ For example, in a Ruby on Rails application, you could do the following inside a controller class:
28
+
29
+ Twilio::Verb.dial '415-123-4567'
30
+
31
+ and you can nest multiple verbs inside a block:
32
+
33
+ verb = Twilio::Verb.new { |v|
34
+ v.say "The time is #{Time.now}"
35
+ v.hangup
36
+ }
37
+ verb.response
38
+
39
+ == Installation
40
+
41
+ gem install twilio
42
+
43
+ == Contributing
44
+
45
+ 1. Run 'bundle' from the command line to install dependencies
46
+ 2. Write test(s) for your patch
47
+ 3. Submit a pull request
48
+
49
+ Note: don't require 'rubygems' in any file (http://www.rubyinside.com/why-using-require-rubygems-is-wrong-1478.html)
50
+
51
+ == Copyright
52
+
53
+ Copyright (c) 2009-2011 Phil Misiowiec, Webficient LLC. See LICENSE for details.
54
+
55
+ == Contributors
56
+
57
+ * Kyle Daigle
58
+ * Yuri Gadow
59
+ * Kyle Humberto
60
+ * Jonathan Rudenberg
61
+ * Mark Turner
62
+ * Jeff Wigal
63
+ * Alex K Wolfe
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => :spec
data/lib/twilio.rb ADDED
@@ -0,0 +1,53 @@
1
+ #--
2
+ # Copyright (c) 2009 Phil Misiowiec, phil@webficient.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require 'httparty'
25
+ require 'builder'
26
+
27
+ require 'twilio/twilio_object'
28
+
29
+ require 'twilio/account'
30
+ require 'twilio/available_phone_numbers'
31
+ require 'twilio/call'
32
+ require 'twilio/conference'
33
+ require 'twilio/incoming_phone_number'
34
+ require 'twilio/notification'
35
+ require 'twilio/outgoing_caller_id'
36
+ require 'twilio/recording'
37
+ require 'twilio/sms'
38
+ require 'twilio/verb'
39
+
40
+ module Twilio
41
+ include HTTParty
42
+ TWILIO_URL = "https://api.twilio.com/2010-04-01/Accounts"
43
+ SSL_CA_PATH = "/etc/ssl/certs"
44
+
45
+ # The connect method caches your Twilio account id and authentication token
46
+ # Example:
47
+ # Twilio.connect('AC309475e5fede1b49e100272a8640f438', '3a2630a909aadbf60266234756fb15a0')
48
+ def self.connect(account_sid, auth_token)
49
+ self.base_uri "#{TWILIO_URL}/#{account_sid}"
50
+ self.basic_auth account_sid, auth_token
51
+ self.default_options[:ssl_ca_path] ||= SSL_CA_PATH unless self.default_options[:ssl_ca_file]
52
+ end
53
+ end
@@ -0,0 +1,12 @@
1
+ module Twilio
2
+ # The Account resource represents your Twilio Account.
3
+ class Account < TwilioObject
4
+ def get
5
+ Twilio.get('')
6
+ end
7
+
8
+ def update_name(name)
9
+ Twilio.put('', :body => {:FriendlyName => name})
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+ module Twilio
2
+ # An AvailablePhoneNumbers resources represents the available phone numbers
3
+ # that Twilio can provide you based on your search criteria. The valid
4
+ # query terms are outlined in the search methods.
5
+ # Example:
6
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
7
+ # Twilio.AvailablePhoneNumbers.search_local(:area_code => 541)
8
+ class AvailablePhoneNumbers < TwilioObject
9
+
10
+ # The Search method handles the searching of both local and toll-free
11
+ # numbers.
12
+ def search(opts={})
13
+ iso_country_code = opts[:iso_country_code] || 'US'
14
+ resource = opts.delete(:resource)
15
+
16
+ params = {
17
+ :AreaCode => opts[:area_code],
18
+ :InPostalCode => opts[:postal_code],
19
+ :InRegion => opts[:in_region],
20
+ :Contains => opts[:contains],
21
+ :NearLatLong => opts[:near_lat_long],
22
+ :NearNumber => opts[:near_number],
23
+ :InLata => opts[:in_lata],
24
+ :InRateCenter => opts[:in_rate_center],
25
+ :Distance => opts[:distance]
26
+ }.reject {|k,v| v == nil} unless opts.empty?
27
+
28
+ Twilio.get("/AvailablePhoneNumbers/#{iso_country_code}/#{resource}", :query => params)
29
+ end
30
+
31
+ # The search_local method searches for numbers in local areas (i.e. state, zip, etc..)
32
+ # Search Options:
33
+ # :area_code
34
+ # :postal_code
35
+ # :in_region
36
+ # :contains
37
+ # :near_lat_long
38
+ # :near_number
39
+ # :in_lata
40
+ # :in_rate_center
41
+ # :distance
42
+ def search_local(opts ={})
43
+ opts = {:resource => 'Local'}.merge(opts)
44
+ search(opts)
45
+ end
46
+
47
+ # The search_toll_free method searches for available toll-free numbers
48
+ # Search Options
49
+ # :contains
50
+ def search_toll_free(opts ={})
51
+ opts = {:resource => 'TollFree'}.merge(opts)
52
+ search(opts)
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,37 @@
1
+ module Twilio
2
+ # A Call represenents a connection between a telephone and Twilio. This may be
3
+ # inbound, when a person calls your application, or outbound when your application
4
+ # initiates the call, either via the REST API, or during a call via the Dial Verb.
5
+ class Call < TwilioObject
6
+ # Example:
7
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
8
+ # Twilio::Call.make(CALLER_ID, user_number, 'http://myapp.com/twilio_response_handler')
9
+ def make(from, to, url, opts = {})
10
+ Twilio.post("/Calls", :body => {:From => from, :To => to, :Url => url}.merge(opts))
11
+ end
12
+
13
+ def list(opts = {})
14
+ Twilio.get("/Calls", :query => (opts.empty? ? nil : opts))
15
+ end
16
+
17
+ def get(call_sid)
18
+ Twilio.get("/Calls/#{call_sid}")
19
+ end
20
+
21
+ def redirect(call_sid, new_url, url_action = 'POST')
22
+ Twilio.post("/Calls/#{call_sid}", :body => {:CurrentUrl => new_url, :CurrentMethod => url_action})
23
+ end
24
+
25
+ def segments(call_sid, call_segment_sid = nil)
26
+ Twilio.get("/Calls/#{call_sid}/Segments#{ '/' + call_segment_sid if call_segment_sid }")
27
+ end
28
+
29
+ def recordings(call_sid)
30
+ Twilio.get("/Calls/#{call_sid}/Recordings")
31
+ end
32
+
33
+ def notifications(call_sid)
34
+ Twilio.get("/Calls/#{call_sid}/Notifications")
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ module Twilio
2
+ # The Conference REST resource allows you to query and manage the state of conferences.
3
+ # When a caller joins a conference via the Dial verb and Conference noun,
4
+ # a Conference Instance Resource is created to represent the conference room
5
+ # and a Participant Instance Resource is created to represent the caller who joined.
6
+ class Conference < TwilioObject
7
+ def list(opts = {})
8
+ Twilio.get("/Conferences", :query => (opts.empty? ? nil : opts))
9
+ end
10
+
11
+ def get(conference_sid)
12
+ Twilio.get("/Conferences/#{conference_sid}")
13
+ end
14
+
15
+ def participants(conference_sid, opts = {})
16
+ Twilio.get("/Conferences/#{conference_sid}/Participants", :query => (opts.empty? ? nil : opts))
17
+ end
18
+
19
+ def participant(conference_sid, call_sid)
20
+ Twilio.get("/Conferences/#{conference_sid}/Participants/#{call_sid}")
21
+ end
22
+
23
+ def mute_participant(conference_sid, call_sid)
24
+ Twilio.post("/Conferences/#{conference_sid}/Participants/#{call_sid}", :body => {:Muted => true})
25
+ end
26
+
27
+ def unmute_participant(conference_sid, call_sid)
28
+ Twilio.post("/Conferences/#{conference_sid}/Participants/#{call_sid}", :body => {:Muted => false})
29
+ end
30
+
31
+ def kick_participant(conference_sid, call_sid)
32
+ Twilio.delete("/Conferences/#{conference_sid}/Participants/#{call_sid}")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,30 @@
1
+ module Twilio
2
+ # An IncomingPhoneNumber resource represents a phone number given to you by
3
+ # Twilio to receive incoming phone calls.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::IncomingPhoneNumber.list
7
+ class IncomingPhoneNumber < TwilioObject
8
+ def list(opts = {})
9
+ Twilio.get("/IncomingPhoneNumbers", :query => (opts.empty? ? nil : opts))
10
+ end
11
+
12
+ def get(incoming_sid)
13
+ Twilio.get("/IncomingPhoneNumbers/#{incoming_sid}")
14
+ end
15
+
16
+ # Creates a phone number in Twilio. You must first find an existing number using
17
+ # the AvailablePhoneNumber class before creating one here.
18
+ #
19
+ # Required: you must either set PhoneNumber or AreaCode as a required option
20
+ # For additional options, see http://www.twilio.com/docs/api/rest/incoming-phone-numbers
21
+ def create(opts)
22
+ raise "You must set either :PhoneNumber or :AreaCode" if !opts.include?(:AreaCode) && !opts.include?(:PhoneNumber)
23
+ Twilio.post("/IncomingPhoneNumbers", :body => opts)
24
+ end
25
+
26
+ def delete(incoming_sid)
27
+ Twilio.delete("/IncomingPhoneNumbers/#{incoming_sid}")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ module Twilio
2
+ # A Notification represenents a log entry made by Twilio in the course of handling
3
+ # your calls or using the REST API.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::Notification.list
7
+ class Notification < TwilioObject
8
+ def list(opts = {})
9
+ Twilio.get('/Notifications', :query => (opts.empty? ? nil : opts))
10
+ end
11
+
12
+ def get(notification_sid)
13
+ Twilio.get("/Notifications/#{notification_sid}")
14
+ end
15
+
16
+ def delete(notification_sid)
17
+ Twilio.delete("/Notifications/#{notification_sid}")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ module Twilio
2
+ # An OutgoingCallerId resource represents an outgoing Caller ID that you have
3
+ # registered with Twilio for use when making an outgoing call or using the Dial Verb.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::OutgoingCallerId.list
7
+ class OutgoingCallerId < TwilioObject
8
+ def create(phone_number, friendly_name = phone_number, call_delay = 0, extension = nil)
9
+ Twilio.post("/OutgoingCallerIds", :body => {
10
+ :PhoneNumber => phone_number,
11
+ :FriendlyName => friendly_name,
12
+ :CallDelay => call_delay,
13
+ :Extension => extension
14
+ })
15
+ end
16
+
17
+ def list(opts = {})
18
+ Twilio.get("/OutgoingCallerIds", :query => (opts.empty? ? nil : opts))
19
+ end
20
+
21
+ def get(callerid_sid)
22
+ Twilio.get("/OutgoingCallerIds/#{callerid_sid}")
23
+ end
24
+
25
+ def update_name(callerid_sid, name)
26
+ Twilio.put("/OutgoingCallerIds/#{callerid_sid}", :body => {:FriendlyName => name})
27
+ end
28
+
29
+ def delete(callerid_sid)
30
+ Twilio.delete("/OutgoingCallerIds/#{callerid_sid}")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ module Twilio
2
+ # Recordings are generated when you use the Record Verb. Those recordings are
3
+ # hosted on Twilio's REST API for you to access.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::Recording.list
7
+ class Recording < TwilioObject
8
+ def list(opts = {})
9
+ Twilio.get("/Recordings", :query => (opts.empty? ? nil : opts))
10
+ end
11
+
12
+ def get(recording_sid)
13
+ Twilio.get("/Recordings/#{recording_sid}")
14
+ end
15
+
16
+ def delete(recording_sid)
17
+ Twilio.delete("/Recordings/#{recording_sid}")
18
+ end
19
+
20
+ def transcriptions(recording_sid, transcription_sid = nil)
21
+ Twilio.get("/Recordings/#{recording_sid}/Transcriptions#{ '/' + transcription_sid if transcription_sid }")
22
+ end
23
+ end
24
+ end