Permalink
Browse files

Merge pull request #2 from chingor13/master

Upgrade to 2010-04-01 Twilio API.
  • Loading branch information...
2 parents 16ca89a + 533bbfd commit 70b7fcdd5a4042e4488f0af77a118d820af741b7 @justinweiss committed Mar 7, 2012
View
@@ -1,25 +1,28 @@
PATH
remote: .
specs:
- twilio_resource (0.1.1)
- reactive_resource (~> 0.5.1)
+ twilio_resource (0.2.0)
+ reactive_resource (~> 0.7.0)
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.0.4)
- activesupport (= 3.0.4)
- builder (~> 2.1.2)
- i18n (~> 0.4)
- activeresource (3.0.4)
- activemodel (= 3.0.4)
- activesupport (= 3.0.4)
- activesupport (3.0.4)
- builder (2.1.2)
- i18n (0.5.0)
- rake (0.8.7)
- reactive_resource (0.5.1)
- activeresource (>= 2.3.10)
+ activemodel (3.1.0)
+ activesupport (= 3.1.0)
+ builder (~> 3.0.0)
+ activeresource (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ activesupport (3.1.0)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ builder (3.0.0)
+ i18n (0.6.0)
+ multi_json (1.1.0)
+ rake (0.9.2.2)
+ reactive_resource (0.7.0)
+ activeresource (>= 3.1)
+ activesupport (>= 3.1)
PLATFORMS
ruby
View
@@ -12,6 +12,7 @@ module TwilioResource
autoload :IncomingPhoneNumber, 'twilio_resource/incoming_phone_number'
autoload :LocalIncomingPhoneNumber, 'twilio_resource/local_incoming_phone_number'
autoload :TollFreeIncomingPhoneNumber, 'twilio_resource/toll_free_incoming_phone_number'
+ autoload :OutgoingCallerId, 'twilio_resource/outgoing_caller_id'
class << self
attr_accessor :logger
@@ -3,4 +3,9 @@
# can be found at
# http://www.twilio.com/docs/api/2008-08-01/rest/account
class TwilioResource::Account < TwilioResource::Base
+
+ ACTIVE = "active"
+ SUSPENDED = "suspended"
+ CLOSED = "closed"
+
end
@@ -73,6 +73,6 @@ def save(*params)
self.site = "https://api.twilio.com"
- self.prefix = '/2008-08-01/'
+ self.prefix = '/2010-04-01/'
self.format = :twilio
end
@@ -5,16 +5,27 @@
class TwilioResource::Call < TwilioResource::Base
belongs_to :account
- NOT_DIALED = 0
- IN_PROGRESS = 1
- COMPLETE = 2
+ NOT_DIALED = "queued"
+ IN_PROGRESS = "in-progress"
+ COMPLETE = "completed"
+ RINGING = "ringing"
+ FAILED = "failed"
+ BUSY = "busy"
+ NO_ANSWER = "no-answer"
- # Returns the status of the call. Can be
- # TwilioResource::Call::NOT_DIALED,
- # TwilioResource::Call::IN_PROGRESS, or
- # TwilioResource::Call::COMPLETE
- def status
- attributes["status"].to_i if attributes["status"]
+ # old end-point
+ def called
+ self.to
end
-
+
+ # old end-point
+ def caller
+ self.from
+ end
+
+ # old end-point
+ def call_segment_sid
+ self.parent_call_sid
+ end
+
end
@@ -0,0 +1,3 @@
+class TwilioResource::OutgoingCallerId < TwilioResource::Base
+ belongs_to :account
+end
View
@@ -11,7 +11,7 @@ def setup
def test_find_account
TwilioResource::Base.user = 1
account = TwilioResource::Account.find(1)
- assert_equal "2", account.status
+ assert_equal TwilioResource::Account::ACTIVE, account.status
end
end
View
@@ -14,8 +14,10 @@ def test_find_all
# check attributes were assigned correctly
call = calls.first
- assert_equal('4159633717', call.called)
- assert_equal('4156767925', call.caller)
+ assert_equal('+15304551166', call.called)
+ assert_equal('+15304551166', call.to)
+ assert_equal('+15105555555', call.caller)
+ assert_equal('+15105555555', call.from)
assert(call.call_segment_sid.blank?)
end
@@ -5,16 +5,22 @@ class TwilioResource::LocalIncomingPhoneNumberTest < Test::Unit::TestCase
def setup
super
+ @old_user = TwilioResource::Base.user
TwilioMock.setup_remote_fixtures
end
+
+ def teardown
+ TwilioResource::Base.user = @old_user
+ super
+ end
def test_provision_local_number
phone = TwilioResource::LocalIncomingPhoneNumber.new(:url => "http://example.com/calls",
:area_code => "206",
:method => 'POST',
:friendly_name => "My Local Number",
: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
assert_equal '2064567890', phone.phone_number
@@ -27,11 +33,10 @@ def test_save_with_unavailable_number_throws_exception
:method => 'POST',
:friendly_name => "My Local Number",
: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
phone.save
end
-
end
# test find, update
@@ -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
@@ -14,7 +14,7 @@ def test_provision_toll_free_number
:method => 'POST',
:friendly_name => "My Local Number",
: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
assert_equal '8774567890', phone.phone_number
Oops, something went wrong.

0 comments on commit 70b7fcd

Please sign in to comment.