trails 1.1.2 → 1.1.3
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.
- data/Manifest.txt +0 -1
- data/README.txt +1 -1
- data/lib/trails.rb +1 -1
- data/lib/trails/test_helper.rb +2 -0
- data/lib/trails/twilio/account.rb +57 -10
- data/lib/trails/twilio/call_handling.rb +2 -2
- data/lib/trails/twilio/incoming.rb +3 -3
- metadata +3 -4
- data/.autotest +0 -23
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
data/lib/trails.rb
CHANGED
data/lib/trails/test_helper.rb
CHANGED
@@ -104,9 +104,11 @@ module Trails
|
|
104
104
|
caller = as_twilio_opts[:caller] || '4155551212'
|
105
105
|
called = as_twilio_opts[:called] || '6155556161'
|
106
106
|
from = as_twilio_opts[:from] || '6665554321'
|
107
|
+
to = as_twilio_opts[:to] || '3334445678'
|
107
108
|
params['Caller'] = caller
|
108
109
|
params['Called'] = called
|
109
110
|
params['From'] = from
|
111
|
+
params['To'] = to
|
110
112
|
params['SmsMessageSid'] = 'DummyMessageSid' if( as_twilio_opts[:sms] )
|
111
113
|
end
|
112
114
|
|
@@ -52,8 +52,7 @@ module Trails
|
|
52
52
|
'Method' => opts['Method'] || opts[:method] || 'GET',
|
53
53
|
'Timeout' => opts['Timeout'] || opts[:timeout] || 15
|
54
54
|
}
|
55
|
-
|
56
|
-
make_request( File.join( base_uri, 'Calls' ), 'POST', params )
|
55
|
+
request( 'Calls', 'POST', params )
|
57
56
|
end
|
58
57
|
|
59
58
|
MAX_SMS_LENGTH = 160
|
@@ -72,22 +71,22 @@ module Trails
|
|
72
71
|
'Body' => body,
|
73
72
|
'Method' => opts[:method] || 'POST'
|
74
73
|
}
|
75
|
-
|
76
|
-
make_request(url, 'POST', params )
|
74
|
+
request( 'SMS/Messages', 'POST', params )
|
77
75
|
end
|
78
76
|
|
77
|
+
# Sample Response:
|
78
|
+
# [{"SmsFallbackUrl"=>nil, "SmsUrl"=>nil, "PhoneNumber"=>"4253954994", "AccountSid"=>"AC6c25b3d8b4f0a2a4e49e4936398a2180", "Capabilities"=>{"SMS"=>"false", "Voice"=>"false"}, "Method"=>"POST", "Sid"=>"PNc939a026d5a332d22c23ca94a161ce29", "DateUpdated"=>"Sat, 20 Mar 2010 17:52:33 -0700", "DateCreated"=>"Sat, 20 Mar 2010 17:52:33 -0700", "Url"=>nil, "FriendlyName"=>"(425) 395-4994", "VoiceFallbackUrl"=>nil, "SmsFallbackMethod"=>"POST", "VoiceCallerIdLookup"=>"false", "SmsMethod"=>"POST", "VoiceFallbackMethod"=>"POST"}]
|
79
79
|
def incoming_numbers( reset = false )
|
80
80
|
if( @incoming_numbers.nil? || reset )
|
81
81
|
response =
|
82
|
-
|
82
|
+
request( 'IncomingPhoneNumbers', 'GET' )
|
83
83
|
|
84
84
|
if( 200 == response.code.to_i )
|
85
|
-
@raw_incoming_numbers =
|
85
|
+
@raw_incoming_numbers = Hash.from_xml( response.body )
|
86
86
|
else
|
87
87
|
raise "got response code #{response.code} and body #{response.body}"
|
88
88
|
end
|
89
|
-
@incoming_numbers = @raw_incoming_numbers.
|
90
|
-
collect{|j| j.inner_html}
|
89
|
+
@incoming_numbers = [@raw_incoming_numbers['TwilioResponse']['IncomingPhoneNumbers']['IncomingPhoneNumber']].flatten # returns an array even when it's a single entry
|
91
90
|
end
|
92
91
|
return @incoming_numbers
|
93
92
|
end
|
@@ -95,8 +94,7 @@ module Trails
|
|
95
94
|
def outgoing_numbers( reset = false )
|
96
95
|
if( @outgoing_numbers.nil? || reset )
|
97
96
|
response =
|
98
|
-
|
99
|
-
'GET' )
|
97
|
+
request( 'OutgoingCallerIds', 'GET' )
|
100
98
|
@outgoing_numbers_raw = Hpricot( response.body ) if( 200 == response.code.to_i )
|
101
99
|
@outgoing_numbers = @outgoing_numbers_raw.search( '//phonenumber').
|
102
100
|
collect{|j| j.inner_html}
|
@@ -104,6 +102,55 @@ module Trails
|
|
104
102
|
return @outgoing_numbers
|
105
103
|
end
|
106
104
|
|
105
|
+
# options: [:area_code, :friendly_name, :url, :sms_url]
|
106
|
+
# sameple return:
|
107
|
+
# {"SmsFallbackUrl"=>nil,
|
108
|
+
# "SmsUrl"=>nil,
|
109
|
+
# "PhoneNumber"=>"4253954994",
|
110
|
+
# "AccountSid"=>"AC6c25b3d8b4f0a2a4e49e4936398a2180",
|
111
|
+
# "Capabilities"=>{"SMS"=>"false",
|
112
|
+
# "Voice"=>"false"},
|
113
|
+
# "Method"=>"POST",
|
114
|
+
# "Sid"=>"PNc939a026d5a332d22c23ca94a161ce29",
|
115
|
+
# "DateUpdated"=>"Sat,
|
116
|
+
# 20 Mar 2010 17:52:33 -0700",
|
117
|
+
# "DateCreated"=>"Sat,
|
118
|
+
# 20 Mar 2010 17:52:33 -0700",
|
119
|
+
# "Url"=>nil,
|
120
|
+
# "FriendlyName"=>"(425) 395-4994",
|
121
|
+
# "VoiceFallbackUrl"=>nil,
|
122
|
+
# "SmsFallbackMethod"=>"POST",
|
123
|
+
# "VoiceCallerIdLookup"=>"false",
|
124
|
+
# "SmsMethod"=>"POST",
|
125
|
+
# "VoiceFallbackMethod"=>"POST"}
|
126
|
+
def provision_number( options = {} )
|
127
|
+
params = {}
|
128
|
+
[:area_code, :friendly_name, :url, :sms_url].each do |key|
|
129
|
+
params[key.to_s.camelize] = options[key] if options.has_key?( key )
|
130
|
+
end
|
131
|
+
|
132
|
+
response = request( 'IncomingPhoneNumbers/Local', 'POST', params )
|
133
|
+
if( 201 == response.code.to_i )
|
134
|
+
raw_number_response = Hash.from_xml( response.body )
|
135
|
+
else
|
136
|
+
raise "while trying to acquire a new number, got response #{response.code} and body: #{response.body}"
|
137
|
+
end
|
138
|
+
raw_number_response["TwilioResponse"]["IncomingPhoneNumber"]
|
139
|
+
end
|
140
|
+
|
141
|
+
def release_number( sid )
|
142
|
+
request( File.join( 'IncomingPhoneNumbers', sid ), 'DELETE' )
|
143
|
+
end
|
144
|
+
|
145
|
+
# just specify the resource (e.g. 'Calls' ) and it will
|
146
|
+
# append it to the base uri ("/#{api_version}/Accounts/#{sid}/")
|
147
|
+
# and then call twilio.
|
148
|
+
def request( resource, method = 'GET', params = {})
|
149
|
+
url = File.join( base_uri, resource )
|
150
|
+
make_request( url, method, params )
|
151
|
+
end
|
152
|
+
|
153
|
+
|
107
154
|
protected
|
108
155
|
|
109
156
|
|
@@ -5,7 +5,7 @@ module Trails
|
|
5
5
|
raise "can\'t include #{self} in #{klass} - not a Controller?" unless
|
6
6
|
klass.respond_to?( :before_filter )
|
7
7
|
Mime::Type.register_alias( "text/html", :twiml ) unless Mime.const_defined?( 'TWIML' )
|
8
|
-
klass.send( :
|
8
|
+
klass.send( :prepend_before_filter, :setup_incoming_call )
|
9
9
|
klass.send( :attr_reader, :incoming_call )
|
10
10
|
klass.send( :alias_method_chain, :protect_against_forgery?, :twilio )
|
11
11
|
klass.send( :append_view_path, File.expand_path( File.join( File.dirname( __FILE__ ),
|
@@ -29,7 +29,7 @@ module Trails
|
|
29
29
|
|
30
30
|
def setup_incoming_call
|
31
31
|
return unless is_twilio_call?
|
32
|
-
logger.debug
|
32
|
+
logger.debug{ "at the beginning, request.params = #{request.parameters}" }
|
33
33
|
request.format = :twiml
|
34
34
|
response.content_type = 'text/xml'
|
35
35
|
|
@@ -8,7 +8,7 @@ module Trails
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def twilio_data
|
11
|
-
|
11
|
+
request.params.slice( *INCOMING_VARS ).dup
|
12
12
|
end
|
13
13
|
|
14
14
|
def is_sms?
|
@@ -47,14 +47,14 @@ module Trails
|
|
47
47
|
'To', #
|
48
48
|
'Body', # 160 chars
|
49
49
|
|
50
|
-
]
|
50
|
+
].freeze
|
51
51
|
public
|
52
52
|
INCOMING_VARS.uniq.each do |pname|
|
53
53
|
mname = pname.gsub( /[A-Z]/ ) { |s| "_#{s.downcase}" }.gsub( /^_/, '' )
|
54
54
|
# some extra debugging code here:
|
55
55
|
# ActionController::Base.logger.debug{ "defining method: #{mname} for param #{pname}" }
|
56
56
|
define_method( mname ) do
|
57
|
-
return request.params[ pname ]
|
57
|
+
return request.params[ pname ] || request.env["HTTP_X_TWILIO_#{pname.upcase}"]
|
58
58
|
end # define_method
|
59
59
|
end # each
|
60
60
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hemant Bhanoo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-04-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.0.
|
23
|
+
version: 2.0.4
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: gemcutter
|
@@ -56,7 +56,6 @@ extra_rdoc_files:
|
|
56
56
|
- Manifest.txt
|
57
57
|
- README.txt
|
58
58
|
files:
|
59
|
-
- .autotest
|
60
59
|
- History.txt
|
61
60
|
- Manifest.txt
|
62
61
|
- README.txt
|
data/.autotest
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
|
3
|
-
require 'autotest/restart'
|
4
|
-
|
5
|
-
# Autotest.add_hook :initialize do |at|
|
6
|
-
# at.extra_files << "../some/external/dependency.rb"
|
7
|
-
#
|
8
|
-
# at.libs << ":../some/external"
|
9
|
-
#
|
10
|
-
# at.add_exception 'vendor'
|
11
|
-
#
|
12
|
-
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
-
# at.files_matching(/test_.*rb$/)
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# %w(TestA TestB).each do |klass|
|
17
|
-
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
|
21
|
-
# Autotest.add_hook :run_command do |at|
|
22
|
-
# system "rake build"
|
23
|
-
# end
|