Skip to content

Commit

Permalink
Version 3.0.0 - see changelog for new and breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
philm committed Mar 26, 2011
1 parent 393d907 commit 564d99a
Show file tree
Hide file tree
Showing 80 changed files with 877 additions and 944 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.rdoc
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,27 @@
= Twilio Gem Changelog

== 3.0

* SSL validation (thanks Kyle Humberto)
* Available phone numbers search support (thanks Mark Turner)
* Deprecated Twilio::Connection method has been removed, use Twilio.connect(...)
* LocalPhoneNumber and TollFreeNumber have been removed to reflect API changes
* New phone numbers are now provisioned via the IncomingPhoneNumber class
* Several classes improved to avoid adding a stray "?" when no params were set
* Compatibility with 1.9.2 (and tested on 1.8.7 MRI and REE)
* Now uses Bundler, Rspec 2, and WebMock

== 2.9

* Compatibility with Twilio's 2010-04-01 API publish

== 2.8

* SMS callback URLs
* Ability to delete phone numbers

== 2.7

* SMS functionality

For earlier versions, see https://github.com/webficient/twilio/commits/master
7 changes: 1 addition & 6 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,4 @@
source "http://rubygems.org" source "http://rubygems.org"


# Specify your gem's dependencies in twilio.gemspec # Specify your gem's dependencies in twilio.gemspec
gemspec gemspec

group :test do
gem 'fakeweb'
gem 'shoulda'
end
20 changes: 16 additions & 4 deletions README.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,14 +34,26 @@ and you can nest multiple verbs inside a block:


== Installation == Installation


sudo gem install twilio -s http://gemcutter.org gem install twilio


If you need to tweak the source code, clone this repository and do a rake build and rake install. == Contributing

1. Run 'bundle' from the command line to install dependencies
2. Write test(s) for your patch
3. Submit a pull request

Note: don't require 'rubygems' in any file (http://www.rubyinside.com/why-using-require-rubygems-is-wrong-1478.html)


== Copyright == Copyright


Copyright (c) 2009-2010 Phil Misiowiec, Webficient LLC. See LICENSE for details. Copyright (c) 2009-2011 Phil Misiowiec, Webficient LLC. See LICENSE for details.


== Contributors == Contributors


Kyle Daigle, Yuri Gadow, Jonathan Rudenberg, Jeff Wigal, Alex K Wolfe * Kyle Daigle
* Yuri Gadow
* Kyle Humberto
* Jonathan Rudenberg
* Mark Turner
* Jeff Wigal
* Alex K Wolfe
37 changes: 5 additions & 32 deletions Rakefile
Original file line number Original file line Diff line number Diff line change
@@ -1,36 +1,9 @@
require "rubygems" require 'bundler/setup'
begin
require 'bundler'
Bundler::GemHelper.install_tasks Bundler::GemHelper.install_tasks
rescue LoadError
puts "bundler not installed"
end


require 'rake/rdoctask' require 'rake'
Rake::RDocTask.new do |rdoc| require 'rspec/core/rake_task'
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'twilio'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end


require 'rake/testtask' RSpec::Core::RakeTask.new
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = false
end


begin task :default => :spec
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
end
5 changes: 0 additions & 5 deletions VERSION.yml

This file was deleted.

22 changes: 18 additions & 4 deletions lib/twilio.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,17 +23,31 @@


require 'httparty' require 'httparty'
require 'builder' require 'builder'

require 'twilio/twilio_object' require 'twilio/twilio_object'

require 'twilio/account' require 'twilio/account'
require 'twilio/available_phone_numbers' require 'twilio/available_phone_numbers'
require 'twilio/call' require 'twilio/call'
require 'twilio/conference' require 'twilio/conference'
require 'twilio/connection'
require 'twilio/incoming_phone_number' require 'twilio/incoming_phone_number'
require 'twilio/local_phone_number'
require 'twilio/notification' require 'twilio/notification'
require 'twilio/outgoing_caller_id' require 'twilio/outgoing_caller_id'
require 'twilio/recording' require 'twilio/recording'
require 'twilio/sms' require 'twilio/sms'
require 'twilio/toll_free_phone_number' require 'twilio/verb'
require 'twilio/verb'
module Twilio
include HTTParty
TWILIO_URL = "https://api.twilio.com/2010-04-01/Accounts"
SSL_CA_PATH = "/etc/ssl/certs"

# The connect method caches your Twilio account id and authentication token
# Example:
# Twilio.connect('AC309475e5fede1b49e100272a8640f438', '3a2630a909aadbf60266234756fb15a0')
def self.connect(account_sid, auth_token)
self.base_uri "#{TWILIO_URL}/#{account_sid}"
self.basic_auth account_sid, auth_token
self.default_options[:ssl_ca_path] ||= SSL_CA_PATH unless self.default_options[:ssl_ca_file]
end
end
2 changes: 1 addition & 1 deletion lib/twilio/account.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Twilio
# The Account resource represents your Twilio Account. # The Account resource represents your Twilio Account.
class Account < TwilioObject class Account < TwilioObject
def get def get
Twilio.get('') Twilio.get('')
end end


def update_name(name) def update_name(name)
Expand Down
28 changes: 15 additions & 13 deletions lib/twilio/available_phone_numbers.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ class AvailablePhoneNumbers < TwilioObject
# numbers. # numbers.
def search(opts={}) def search(opts={})
iso_country_code = opts[:iso_country_code] || 'US' iso_country_code = opts[:iso_country_code] || 'US'
resource = opts[:resource] resource = opts.delete(:resource)
Twilio.get("/AvailablePhoneNumbers/#{iso_country_code}/#{resource}",
:query => { params = {
:AreaCode => opts[:area_code], :AreaCode => opts[:area_code],
:InPostalCode => opts[:postal_code], :InPostalCode => opts[:postal_code],
:InRegion => opts[:in_region], :InRegion => opts[:in_region],
:Contains => opts[:contains], :Contains => opts[:contains],
:NearLatLong => opts[:near_lat_long], :NearLatLong => opts[:near_lat_long],
:NearNumber => opts[:near_number], :NearNumber => opts[:near_number],
:InLata => opts[:in_lata], :InLata => opts[:in_lata],
:InRateCenter => opts[:in_rate_center], :InRateCenter => opts[:in_rate_center],
:Distance => opts[:distance] :Distance => opts[:distance]
}.reject {|k,v| v == nil}) }.reject {|k,v| v == nil} unless opts.empty?

Twilio.get("/AvailablePhoneNumbers/#{iso_country_code}/#{resource}", :query => params)
end end


# The search_local method searches for numbers in local areas (i.e. state, zip, etc..) # The search_local method searches for numbers in local areas (i.e. state, zip, etc..)
Expand Down
8 changes: 4 additions & 4 deletions lib/twilio/call.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class Call < TwilioObject
# Example: # Example:
# Twilio.connect('my_twilio_sid', 'my_auth_token') # Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::Call.make(CALLER_ID, user_number, 'http://myapp.com/twilio_response_handler') # Twilio::Call.make(CALLER_ID, user_number, 'http://myapp.com/twilio_response_handler')
def make(from, to, url, optional = {}) def make(from, to, url, opts = {})
Twilio.post("/Calls", :body => {:From => from, :To => to, :Url => url}.merge(optional)) Twilio.post("/Calls", :body => {:From => from, :To => to, :Url => url}.merge(opts))
end end


def list(optional = {}) def list(opts = {})
Twilio.get("/Calls", :query => optional) Twilio.get("/Calls", :query => (opts.empty? ? nil : opts))
end end


def get(call_sid) def get(call_sid)
Expand Down
12 changes: 6 additions & 6 deletions lib/twilio/conference.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ module Twilio
# a Conference Instance Resource is created to represent the conference room # a Conference Instance Resource is created to represent the conference room
# and a Participant Instance Resource is created to represent the caller who joined. # and a Participant Instance Resource is created to represent the caller who joined.
class Conference < TwilioObject class Conference < TwilioObject
def list(optional = {}) def list(opts = {})
Twilio.get("/Conferences", :query => optional) Twilio.get("/Conferences", :query => (opts.empty? ? nil : opts))
end end


def get(conference_sid) def get(conference_sid)
Twilio.get("/Conferences/#{conference_sid}") Twilio.get("/Conferences/#{conference_sid}")
end end


def participants(conference_sid, optional = {}) def participants(conference_sid, opts = {})
Twilio.get("/Conferences/#{conference_sid}/Participants", :query => optional) Twilio.get("/Conferences/#{conference_sid}/Participants", :query => (opts.empty? ? nil : opts))
end end


def participant(conference_sid, call_sid) def participant(conference_sid, call_sid)
Twilio.get("/Conferences/#{conference_sid}/Participants/#{call_sid}") Twilio.get("/Conferences/#{conference_sid}/Participants/#{call_sid}")
end end


def mute_participant(conference_sid, call_sid) def mute_participant(conference_sid, call_sid)
Expand Down
26 changes: 0 additions & 26 deletions lib/twilio/connection.rb

This file was deleted.

18 changes: 16 additions & 2 deletions lib/twilio/incoming_phone_number.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@ module Twilio
# Twilio.connect('my_twilio_sid', 'my_auth_token') # Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::IncomingPhoneNumber.list # Twilio::IncomingPhoneNumber.list
class IncomingPhoneNumber < TwilioObject class IncomingPhoneNumber < TwilioObject
def list(optional = {}) def list(opts = {})
Twilio.get("/IncomingPhoneNumbers", :query => optional) Twilio.get("/IncomingPhoneNumbers", :query => (opts.empty? ? nil : opts))
end end


def get(incoming_sid) def get(incoming_sid)
Twilio.get("/IncomingPhoneNumbers/#{incoming_sid}") Twilio.get("/IncomingPhoneNumbers/#{incoming_sid}")
end end

# Creates a phone number in Twilio. You must first find an existing number using
# the AvailablePhoneNumber class before creating one here.
#
# Required: you must either set PhoneNumber or AreaCode as a required option
# For additional options, see http://www.twilio.com/docs/api/rest/incoming-phone-numbers
def create(opts)
raise "You must set either :PhoneNumber or :AreaCode" if !opts.include?(:AreaCode) && !opts.include?(:PhoneNumber)
Twilio.post("/IncomingPhoneNumbers", :body => opts)
end

def delete(incoming_sid)
Twilio.delete("/IncomingPhoneNumbers/#{incoming_sid}")
end
end end
end end
26 changes: 0 additions & 26 deletions lib/twilio/local_phone_number.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/twilio/notification.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Twilio
# Twilio.connect('my_twilio_sid', 'my_auth_token') # Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::Notification.list # Twilio::Notification.list
class Notification < TwilioObject class Notification < TwilioObject
def list(optional = {}) def list(opts = {})
Twilio.get('/Notifications', :query => optional) Twilio.get('/Notifications', :query => (opts.empty? ? nil : opts))
end end


def get(notification_sid) def get(notification_sid)
Expand Down
9 changes: 5 additions & 4 deletions lib/twilio/outgoing_caller_id.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ module Twilio
# Twilio.connect('my_twilio_sid', 'my_auth_token') # Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::OutgoingCallerId.list # Twilio::OutgoingCallerId.list
class OutgoingCallerId < TwilioObject class OutgoingCallerId < TwilioObject
def create(phone_number, friendly_name = phone_number, call_delay = 0) def create(phone_number, friendly_name = phone_number, call_delay = 0, extension = nil)
Twilio.post("/OutgoingCallerIds", :body => { Twilio.post("/OutgoingCallerIds", :body => {
:PhoneNumber => phone_number, :PhoneNumber => phone_number,
:FriendlyName => friendly_name, :FriendlyName => friendly_name,
:CallDelay => call_delay :CallDelay => call_delay,
:Extension => extension
}) })
end end


def list(optional = {}) def list(opts = {})
Twilio.get("/OutgoingCallerIds", :query => optional) Twilio.get("/OutgoingCallerIds", :query => (opts.empty? ? nil : opts))
end end


def get(callerid_sid) def get(callerid_sid)
Expand Down
4 changes: 2 additions & 2 deletions lib/twilio/recording.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Twilio
# Twilio.connect('my_twilio_sid', 'my_auth_token') # Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::Recording.list # Twilio::Recording.list
class Recording < TwilioObject class Recording < TwilioObject
def list(optional = {}) def list(opts = {})
Twilio.get("/Recordings", :query => optional) Twilio.get("/Recordings", :query => (opts.empty? ? nil : opts))
end end


def get(recording_sid) def get(recording_sid)
Expand Down
4 changes: 2 additions & 2 deletions lib/twilio/sms.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def message(from, to, body, callback_url=nil)
Twilio.post("/SMS/Messages", :body => {:From => from, :To => to, :Body => body}.merge(callback)) Twilio.post("/SMS/Messages", :body => {:From => from, :To => to, :Body => body}.merge(callback))
end end


def list(optional = {}) def list(opts = {})
Twilio.get("/SMS/Messages", :query => optional) Twilio.get("/SMS/Messages", :query => (opts.empty? ? nil : opts))
end end


def get(sms_message_sid) def get(sms_message_sid)
Expand Down
Loading

0 comments on commit 564d99a

Please sign in to comment.