Skip to content

Commit

Permalink
version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemant Bhanoo committed Feb 19, 2011
2 parents 8da4722 + ae6599a commit 1a438bc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,2 +1,4 @@
*~ *~
pkg/* pkg/*
test/*
*.svn
8 changes: 6 additions & 2 deletions History.txt
@@ -1,6 +1,10 @@
=== 1.1.4 / 2011-02-19 === 1.1.5 / 2010-06-02


Various updates based on latest twilio docs * test support for call guid/call status

=== 1.1.4 / 2010-05-09

Backwards-compatible support for environment-specific twilio configuration


=== 1.1.1 / 2010-03-16 === 1.1.1 / 2010-03-16


Expand Down
2 changes: 1 addition & 1 deletion lib/trails.rb
@@ -1,5 +1,5 @@
module Trails module Trails
VERSION = '1.1.4' VERSION = '1.1.6'
end end
begin begin
TwilioRest TwilioRest
Expand Down
37 changes: 23 additions & 14 deletions lib/trails/test_helper.rb
@@ -1,4 +1,5 @@
require 'ostruct' require 'ostruct'
require 'securerandom'


module Trails module Trails
module TestHelper module TestHelper
Expand Down Expand Up @@ -78,12 +79,15 @@ def modify_session_with_twilio_opts( session, as_twilio_opts )
header_modifier = lambda{ |h,o| modify_headers_with_twilio_opts( h, o ) } header_modifier = lambda{ |h,o| modify_headers_with_twilio_opts( h, o ) }
param_modifier = lambda{ |p,o| modify_params_with_twilio_opts( p, o ) } param_modifier = lambda{ |p,o| modify_params_with_twilio_opts( p, o ) }


session_twilio_opts = as_twilio_opts.dup
session_twilio_opts[:call_guid] ||= generate_call_guid

session.metaclass.send( :define_method, :process_with_twilio_as_caller ) do |method, path, params, headers| session.metaclass.send( :define_method, :process_with_twilio_as_caller ) do |method, path, params, headers|
params ||= {} params ||= {}
headers ||= {} headers ||= {}


header_modifier.call( headers, as_twilio_opts ) header_modifier.call( headers, session_twilio_opts )
param_modifier.call( params, as_twilio_opts ) param_modifier.call( params, session_twilio_opts )


process_without_twilio_as_caller( method, path, params, headers ) process_without_twilio_as_caller( method, path, params, headers )
end # define process_with_twilio_as_caller end # define process_with_twilio_as_caller
Expand All @@ -101,24 +105,29 @@ def modify_headers_with_twilio_opts( headers, as_twilio_opts )
end end


def modify_params_with_twilio_opts( params, as_twilio_opts ) def modify_params_with_twilio_opts( params, as_twilio_opts )
options = as_twilio_opts.dup caller = as_twilio_opts[:caller] || '4155551212'

called = as_twilio_opts[:called] || '6155556161'
options[ 'Caller' ] = options.delete(:caller) || '4155551212' from = as_twilio_opts[:from] || '6665554321'
options[ 'Called' ] = options.delete(:called) || '6155556161' to = as_twilio_opts[:to] || '3334445678'
options[ 'From' ] = options.delete(:from) || '6665554321' status = as_twilio_opts[:call_status] || 'in-progress'
options[ 'To' ] = options.delete(:to) || '3334445678' guid = as_twilio_opts[ :call_guid ] || generate_call_guid
options['SmsMessageSid'] = 'DummyMessageSid' if( options[:sms] ) params['Caller'] = caller

params['Called'] = called
valid_options = Hash[ *( options.select{ |k,v| params['From'] = from
Trails::Twilio::Incoming.const_get( 'INCOMING_VARS' ). params['To'] = to
include?( k ) }.flatten ) ] params['CallStatus'] ||= status
params.merge!( valid_options ) params['CallGuid'] ||= guid
params['SmsMessageSid'] = 'DummyMessageSid' if( as_twilio_opts[:sms] )
end end


private private
module IntegrationDSL module IntegrationDSL
end end


def generate_call_guid
'CA_FAKE_' + SecureRandom.hex( 12 )
end

end # module TestHelper end # module TestHelper
end # module Trails end # module Trails


Expand Down
10 changes: 9 additions & 1 deletion lib/trails/twilio/account.rb
Expand Up @@ -178,7 +178,15 @@ def self.logger
return @logger return @logger
end end
def self.config def self.config
@@cfg ||= YAML::load_file( config_file ) @@all_cfg ||= YAML::load_file( config_file ).freeze
# allow per-environment configuration
@@cfg ||= if ( @@all_cfg.has_key?( RAILS_ENV ) )
@@all_cfg[ RAILS_ENV ]
elsif( @@all_cfg.has_key?( 'default' ) )
@@all_cfg['default']
else
@@all_cfg
end
end end


def self.config_file def self.config_file
Expand Down
5 changes: 4 additions & 1 deletion lib/trails/twilio/incoming.rb
Expand Up @@ -15,11 +15,14 @@ def is_sms?
!sms_message_sid.blank? !sms_message_sid.blank?
end end


def complete?
'completed' == self.call_status.downcase
end

protected protected
attr_reader :request attr_reader :request


INCOMING_VARS = [ INCOMING_VARS = [
# Always available:
# Always available: # Always available:
'CallSid', # A unique identifier for this call, generated by Twilio. 'CallSid', # A unique identifier for this call, generated by Twilio.
'AccountSid', # Your Twilio account id. It is 34 characters long, and always starts with the letters AC. 'AccountSid', # Your Twilio account id. It is 34 characters long, and always starts with the letters AC.
Expand Down

0 comments on commit 1a438bc

Please sign in to comment.