Skip to content

Commit

Permalink
Merge pull request #2 from chingor13/master
Browse files Browse the repository at this point in the history
Upgrade to 2010-04-01 Twilio API.
  • Loading branch information
justinweiss committed Mar 7, 2012
2 parents 16ca89a + 533bbfd commit 70b7fcd
Show file tree
Hide file tree
Showing 13 changed files with 457 additions and 206 deletions.
33 changes: 18 additions & 15 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
@@ -1,25 +1,28 @@
PATH PATH
remote: . remote: .
specs: specs:
twilio_resource (0.1.1) twilio_resource (0.2.0)
reactive_resource (~> 0.5.1) reactive_resource (~> 0.7.0)


GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
activemodel (3.0.4) activemodel (3.1.0)
activesupport (= 3.0.4) activesupport (= 3.1.0)
builder (~> 2.1.2) builder (~> 3.0.0)
i18n (~> 0.4) activeresource (3.1.0)
activeresource (3.0.4) activemodel (= 3.1.0)
activemodel (= 3.0.4) activesupport (= 3.1.0)
activesupport (= 3.0.4) activesupport (3.1.0)
activesupport (3.0.4) i18n (~> 0.6)
builder (2.1.2) multi_json (~> 1.0)
i18n (0.5.0) builder (3.0.0)
rake (0.8.7) i18n (0.6.0)
reactive_resource (0.5.1) multi_json (1.1.0)
activeresource (>= 2.3.10) rake (0.9.2.2)
reactive_resource (0.7.0)
activeresource (>= 3.1)
activesupport (>= 3.1)


PLATFORMS PLATFORMS
ruby ruby
Expand Down
1 change: 1 addition & 0 deletions lib/twilio_resource.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module TwilioResource
autoload :IncomingPhoneNumber, 'twilio_resource/incoming_phone_number' autoload :IncomingPhoneNumber, 'twilio_resource/incoming_phone_number'
autoload :LocalIncomingPhoneNumber, 'twilio_resource/local_incoming_phone_number' autoload :LocalIncomingPhoneNumber, 'twilio_resource/local_incoming_phone_number'
autoload :TollFreeIncomingPhoneNumber, 'twilio_resource/toll_free_incoming_phone_number' autoload :TollFreeIncomingPhoneNumber, 'twilio_resource/toll_free_incoming_phone_number'
autoload :OutgoingCallerId, 'twilio_resource/outgoing_caller_id'


class << self class << self
attr_accessor :logger attr_accessor :logger
Expand Down
5 changes: 5 additions & 0 deletions lib/twilio_resource/account.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
# can be found at # can be found at
# http://www.twilio.com/docs/api/2008-08-01/rest/account # http://www.twilio.com/docs/api/2008-08-01/rest/account
class TwilioResource::Account < TwilioResource::Base class TwilioResource::Account < TwilioResource::Base

ACTIVE = "active"
SUSPENDED = "suspended"
CLOSED = "closed"

end end
2 changes: 1 addition & 1 deletion lib/twilio_resource/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ def save(*params)




self.site = "https://api.twilio.com" self.site = "https://api.twilio.com"
self.prefix = '/2008-08-01/' self.prefix = '/2010-04-01/'
self.format = :twilio self.format = :twilio
end end
31 changes: 21 additions & 10 deletions lib/twilio_resource/call.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@
class TwilioResource::Call < TwilioResource::Base class TwilioResource::Call < TwilioResource::Base
belongs_to :account belongs_to :account


NOT_DIALED = 0 NOT_DIALED = "queued"
IN_PROGRESS = 1 IN_PROGRESS = "in-progress"
COMPLETE = 2 COMPLETE = "completed"
RINGING = "ringing"
FAILED = "failed"
BUSY = "busy"
NO_ANSWER = "no-answer"


# Returns the status of the call. Can be # old end-point
# TwilioResource::Call::NOT_DIALED, def called
# TwilioResource::Call::IN_PROGRESS, or self.to
# TwilioResource::Call::COMPLETE
def status
attributes["status"].to_i if attributes["status"]
end end


# old end-point
def caller
self.from
end

# old end-point
def call_segment_sid
self.parent_call_sid
end

end end
3 changes: 3 additions & 0 deletions lib/twilio_resource/outgoing_caller_id.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
class TwilioResource::OutgoingCallerId < TwilioResource::Base
belongs_to :account
end
2 changes: 1 addition & 1 deletion test/account_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setup
def test_find_account def test_find_account
TwilioResource::Base.user = 1 TwilioResource::Base.user = 1
account = TwilioResource::Account.find(1) account = TwilioResource::Account.find(1)
assert_equal "2", account.status assert_equal TwilioResource::Account::ACTIVE, account.status
end end


end end
6 changes: 4 additions & 2 deletions test/call_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def test_find_all


# check attributes were assigned correctly # check attributes were assigned correctly
call = calls.first call = calls.first
assert_equal('4159633717', call.called) assert_equal('+15304551166', call.called)
assert_equal('4156767925', call.caller) assert_equal('+15304551166', call.to)
assert_equal('+15105555555', call.caller)
assert_equal('+15105555555', call.from)
assert(call.call_segment_sid.blank?) assert(call.call_segment_sid.blank?)
end end


Expand Down
11 changes: 8 additions & 3 deletions test/local_incoming_phone_number_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ class TwilioResource::LocalIncomingPhoneNumberTest < Test::Unit::TestCase


def setup def setup
super super
@old_user = TwilioResource::Base.user
TwilioMock.setup_remote_fixtures TwilioMock.setup_remote_fixtures
end end

def teardown
TwilioResource::Base.user = @old_user
super
end


def test_provision_local_number def test_provision_local_number
phone = TwilioResource::LocalIncomingPhoneNumber.new(:url => "http://example.com/calls", phone = TwilioResource::LocalIncomingPhoneNumber.new(:url => "http://example.com/calls",
:area_code => "206", :area_code => "206",
:method => 'POST', :method => 'POST',
:friendly_name => "My Local Number", :friendly_name => "My Local Number",
:account_id => 1) :account_id => 1)
assert_equal "AreaCode=206&FriendlyName=My+Local+Number&Method=POST&Url=http%3A%2F%2Fexample.com%2Fcalls", phone.encode assert_equal "AccountId=1&AreaCode=206&FriendlyName=My+Local+Number&Method=POST&Url=http%3A%2F%2Fexample.com%2Fcalls", phone.encode
phone.save phone.save


assert_equal '2064567890', phone.phone_number assert_equal '2064567890', phone.phone_number
Expand All @@ -27,11 +33,10 @@ def test_save_with_unavailable_number_throws_exception
:method => 'POST', :method => 'POST',
:friendly_name => "My Local Number", :friendly_name => "My Local Number",
:account_id => TwilioResource::Base.user) :account_id => TwilioResource::Base.user)
assert_equal "AreaCode=815&FriendlyName=My+Local+Number&Method=POST&Url=http%3A%2F%2Fexample.com%2Fcalls", phone.encode assert_equal "AccountId=2&AreaCode=815&FriendlyName=My+Local+Number&Method=POST&Url=http%3A%2F%2Fexample.com%2Fcalls", phone.encode
assert_raises TwilioResource::NoPhoneNumbersFoundException do assert_raises TwilioResource::NoPhoneNumbersFoundException do
phone.save phone.save
end end

end end


# test find, update # test find, update
Expand Down
29 changes: 29 additions & 0 deletions test/outgoing_caller_id_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'test_helper'
require 'twilio_mock'

class TwilioResource::OutgoingCallerIdTest < Test::Unit::TestCase

def setup
super
TwilioMock.setup_remote_fixtures
end

def test_find_all
caller_ids = TwilioResource::OutgoingCallerId.find(:all, :params => {:account_id => 1})
assert_equal 1, caller_ids.length

# check attributes were assigned correctly
caller_id = caller_ids.first
assert_equal('+15105555555', caller_id.phone_number)
end

def test_find_by_phone_number
caller_ids = TwilioResource::OutgoingCallerId.find(:all, :params => {:account_id => 1, :friendly_name => "Foo"})
assert_equal 1, caller_ids.length

# check attributes were assigned correctly
caller_id = caller_ids.first
assert_equal('+15105555555', caller_id.phone_number)
end

end
2 changes: 1 addition & 1 deletion test/toll_free_incoming_phone_number_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_provision_toll_free_number
:method => 'POST', :method => 'POST',
:friendly_name => "My Local Number", :friendly_name => "My Local Number",
:account_id => TwilioResource::Base.user) :account_id => TwilioResource::Base.user)
assert_equal "FriendlyName=My+Local+Number&Method=POST&Url=http%3A%2F%2Fexample.com%2Fcalls", phone.encode assert_equal "AccountId=1&FriendlyName=My+Local+Number&Method=POST&Url=http%3A%2F%2Fexample.com%2Fcalls", phone.encode
phone.save phone.save


assert_equal '8774567890', phone.phone_number assert_equal '8774567890', phone.phone_number
Expand Down
Loading

0 comments on commit 70b7fcd

Please sign in to comment.