twilio-rb 0.3.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -0
- data/lib/twilio/resource.rb +16 -6
- data/lib/twilio/twiml.rb +3 -3
- data/lib/twilio.rb +4 -3
- metadata +28 -14
data/README.md
CHANGED
@@ -64,6 +64,14 @@ The parameter keys should be given as underscored symbols. They will be converte
|
|
64
64
|
|
65
65
|
Please see the Twilio REST API documentation for an up to date list of supported parameters.
|
66
66
|
|
67
|
+
## Finding an existing telephone call
|
68
|
+
|
69
|
+
To retrieve an earlier created call, there is the `Twilio::Call.find` method, which accepts a call SID, e.g.
|
70
|
+
|
71
|
+
<pre>call = Twilio::Call.find 'CAa346467ca321c71dbd5e12f627deb854'</pre>
|
72
|
+
|
73
|
+
This returns an instance of `Twilio::Call` if a call with the given SID was found, otherwise nil is returned
|
74
|
+
|
67
75
|
### Modifying a live telephone call
|
68
76
|
|
69
77
|
Once a call has been been created it can be modified with the following methods:
|
@@ -90,6 +98,14 @@ The parameter keys should be given as underscored symbols. They will be converte
|
|
90
98
|
|
91
99
|
Please see the Twilio REST API documentation for an up to date list of supported parameters.
|
92
100
|
|
101
|
+
## Finding an existing telephone SMS message
|
102
|
+
|
103
|
+
To retrieve an earlier created SMS message, there is the `Twilio::SMS.find` method, which accepts a SMS message SID, e.g.
|
104
|
+
|
105
|
+
<pre>call = Twilio::SMS.find 'SM90c6fc909d8504d45ecdb3a3d5b3556e'</pre>
|
106
|
+
|
107
|
+
This returns an instance of `Twilio::SMS` if a SMS message with the given SID was found, otherwise nil is returned
|
108
|
+
|
93
109
|
## Building TwiML documents
|
94
110
|
|
95
111
|
A TwiML document is an XML document. The best way to build XML in Ruby is with Builder, and so it follows that we should use builder for TwiML. `Twilio::TwiML.build` behaves like builder except element names are capitalised for you and attributes are camelized for you as well. This is so you may continue to write beautiful code.
|
data/lib/twilio/resource.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'active_support/core_ext/string
|
1
|
+
require 'active_support/core_ext/string' # Chill! we only use the bits of AS we need!
|
2
2
|
|
3
3
|
module Twilio
|
4
4
|
module Resource
|
@@ -73,10 +73,20 @@ module Twilio
|
|
73
73
|
end
|
74
74
|
|
75
75
|
class << base
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
if instance_of? Class # Don't want this mixed into singleton objects e.g. Twilio::Account
|
77
|
+
def find(id)
|
78
|
+
# All Twilio resources follow a convention, except SMS :(
|
79
|
+
klass_name = name.demodulize
|
80
|
+
resource = klass_name == 'SMS' ? "#{klass_name}/Messages" : klass_name.pluralize
|
81
|
+
res = get "/Accounts/#{Twilio::ACCOUNT_SID}/#{resource}/#{id}.json"
|
82
|
+
new Hash[res.parsed_response.map { |k,v| [k.camelize, v] }] if (200..299).include? res.code
|
83
|
+
end
|
84
|
+
|
85
|
+
def create(attrs={})
|
86
|
+
new(attrs).tap { |c| c.save }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
80
90
|
# decorate http methods with authentication
|
81
91
|
%w<post get put delete>.each do |meth|
|
82
92
|
define_method(meth) do |*args| # splatted args necessary hack since <= 1.8.7 does not support optional block args
|
@@ -87,4 +97,4 @@ module Twilio
|
|
87
97
|
end
|
88
98
|
end
|
89
99
|
end
|
90
|
-
end
|
100
|
+
end
|
data/lib/twilio/twiml.rb
CHANGED
@@ -5,8 +5,8 @@ module Twilio
|
|
5
5
|
xm.instance_eval do
|
6
6
|
def method_missing(meth, *args, &blk)
|
7
7
|
# camelize options
|
8
|
-
if args.last.kind_of? Hash
|
9
|
-
args[-1] = Hash[args.last.map { |k,v| [k.to_s.camelize(:lower), v]}]
|
8
|
+
if args.last.kind_of? ::Hash
|
9
|
+
args[-1] = ::Hash[args.last.map { |k,v| [k.to_s.camelize(:lower), v]}]
|
10
10
|
end
|
11
11
|
# let builder do the heavy lifting
|
12
12
|
super(meth.to_s.capitalize, *args, &blk)
|
@@ -17,4 +17,4 @@ module Twilio
|
|
17
17
|
end
|
18
18
|
extend self
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
data/lib/twilio.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
%w<rubygems active_support
|
1
|
+
%w<rubygems active_support cgi yajl yajl/json_gem httparty builder>.each { |lib| require lib }
|
2
2
|
require File.join(File.dirname(__FILE__), 'twilio', 'resource.rb')
|
3
3
|
|
4
4
|
module Twilio
|
@@ -6,7 +6,7 @@ module Twilio
|
|
6
6
|
APIError = Class.new StandardError
|
7
7
|
ConfigurationError = Class.new StandardError
|
8
8
|
InvalidStateError = Class.new StandardError
|
9
|
-
|
9
|
+
|
10
10
|
class << self
|
11
11
|
def const_missing(const_name)
|
12
12
|
raise Twilio::ConfigurationError.new "Cannot complete request. Please set #{const_name.to_s.downcase} with Twilio::Config.setup first!"
|
@@ -14,4 +14,5 @@ module Twilio
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
Dir[File.join(File.dirname(__FILE__), 'twilio', '*.rb')].each { |lib| require lib }
|
17
|
+
Dir[File.join(File.dirname(__FILE__), 'twilio', '*.rb')].each { |lib| require lib }
|
18
|
+
|
metadata
CHANGED
@@ -4,9 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
|
9
|
-
version: 0.3.1
|
7
|
+
- 4
|
8
|
+
version: "0.4"
|
10
9
|
platform: ruby
|
11
10
|
authors:
|
12
11
|
- Stevie Graham
|
@@ -14,7 +13,7 @@ autorequire:
|
|
14
13
|
bindir: bin
|
15
14
|
cert_chain: []
|
16
15
|
|
17
|
-
date: 2010-
|
16
|
+
date: 2010-12-13 00:00:00 +00:00
|
18
17
|
default_executable:
|
19
18
|
dependencies:
|
20
19
|
- !ruby/object:Gem::Dependency
|
@@ -63,7 +62,7 @@ dependencies:
|
|
63
62
|
type: :runtime
|
64
63
|
version_requirements: *id003
|
65
64
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
65
|
+
name: builder
|
67
66
|
prerelease: false
|
68
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
68
|
none: false
|
@@ -71,14 +70,14 @@ dependencies:
|
|
71
70
|
- - ">="
|
72
71
|
- !ruby/object:Gem::Version
|
73
72
|
segments:
|
73
|
+
- 2
|
74
74
|
- 1
|
75
|
-
-
|
76
|
-
|
77
|
-
version: 1.3.5
|
75
|
+
- 2
|
76
|
+
version: 2.1.2
|
78
77
|
type: :runtime
|
79
78
|
version_requirements: *id004
|
80
79
|
- !ruby/object:Gem::Dependency
|
81
|
-
name:
|
80
|
+
name: webmock
|
82
81
|
prerelease: false
|
83
82
|
requirement: &id005 !ruby/object:Gem::Requirement
|
84
83
|
none: false
|
@@ -86,12 +85,27 @@ dependencies:
|
|
86
85
|
- - ">="
|
87
86
|
- !ruby/object:Gem::Version
|
88
87
|
segments:
|
89
|
-
- 2
|
90
88
|
- 1
|
91
|
-
-
|
92
|
-
|
93
|
-
|
89
|
+
- 6
|
90
|
+
- 1
|
91
|
+
version: 1.6.1
|
92
|
+
type: :development
|
94
93
|
version_requirements: *id005
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
prerelease: false
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 2
|
104
|
+
- 2
|
105
|
+
- 0
|
106
|
+
version: 2.2.0
|
107
|
+
type: :development
|
108
|
+
version_requirements: *id006
|
95
109
|
description: A nice Ruby wrapper for the Twilio REST API
|
96
110
|
email: sjtgraham@mac.com
|
97
111
|
executables: []
|
@@ -109,7 +123,7 @@ files:
|
|
109
123
|
- lib/twilio/sms.rb
|
110
124
|
- lib/twilio/twiml.rb
|
111
125
|
- lib/twilio.rb
|
112
|
-
has_rdoc:
|
126
|
+
has_rdoc: false
|
113
127
|
homepage: http://github.com/stevegraham/twilio-rb
|
114
128
|
licenses: []
|
115
129
|
|