Class: TwilioResource::Base
- Inherits:
-
ReactiveResource::Base
- Object
- ReactiveResource::Base
- TwilioResource::Base
- Defined in:
- lib/twilio_resource/base.rb
Overview
Encapsulates the changes that need to be made to active_resource’s defaults in order to communicate with Twilio. There are a few main issues with ActiveResource’s defaults:
-
Twilio’s urls don’t take an extension. ActiveResource requires endpoints to have an extension corresponding to the type of data, for example:
resource.xml
orresource.json
. Twilio’s are always xml, but have no extension. -
Twilio uses capitalized names in their URLs. For instance, instead of ‘/account/1/calls/1’, they use ‘/Account/1/Calls/1’.
-
Twilio takes form encoded params, like token=blah&sid=foo, but returns data in XML. These changes are encapsulated in ActiveResource::Formats::TwilioFormat.
All of the Twilio ActiveResource classes inherit from this class.
Direct Known Subclasses
Class Attribute Summary collapse
-
.sid ⇒ Object
(also: user)
Returns the value of attribute sid.
-
.token ⇒ Object
(also: password)
Returns the value of attribute token.
Class Method Summary collapse
-
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
Add logging to these requests.
-
.custom_method_collection_url(method_name, options = {}) ⇒ Object
Add logging to these requests.
-
.element_name ⇒ Object
Twilio uses capitalized path names.
-
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Add logging to these requests.
- .query_string(params) ⇒ Object
Instance Method Summary collapse
-
#save(*params) ⇒ Object
we should wrap the exceptions we can.
Class Attribute Details
.sid ⇒ Object Also known as: user
Returns the value of attribute sid.
23 24 25 |
# File 'lib/twilio_resource/base.rb', line 23 def sid @sid end |
.token ⇒ Object Also known as: password
Returns the value of attribute token.
24 25 26 |
# File 'lib/twilio_resource/base.rb', line 24 def token @token end |
Class Method Details
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
Add logging to these requests
40 41 42 43 44 |
# File 'lib/twilio_resource/base.rb', line 40 def self.collection_path( = {}, = nil) path = super(, ) TwilioResource.logger.info("Request: #{path}") path end |
.custom_method_collection_url(method_name, options = {}) ⇒ Object
Add logging to these requests
47 48 49 50 51 |
# File 'lib/twilio_resource/base.rb', line 47 def self.custom_method_collection_url(method_name, = {}) path = super(method_name, ) TwilioResource.logger.info("Request: #{path}") path end |
.element_name ⇒ Object
Twilio uses capitalized path names
54 55 56 |
# File 'lib/twilio_resource/base.rb', line 54 def self.element_name super.camelize end |
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Add logging to these requests
33 34 35 36 37 |
# File 'lib/twilio_resource/base.rb', line 33 def self.element_path(id, = {}, = nil) path = super(id, , ) TwilioResource.logger.info("Request: #{path}") path end |
.query_string(params) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/twilio_resource/base.rb', line 58 def self.query_string(params) # camelize all the param keys, because that's what Twilio expects fixed_params_list = params.map {|k, v| [k.to_s.camelize, v]}.flatten fixed_params_hash = Hash[*fixed_params_list] # Hash really needs a decent #map super(fixed_params_hash) end |
Instance Method Details
#save(*params) ⇒ Object
we should wrap the exceptions we can
66 67 68 69 70 71 72 |
# File 'lib/twilio_resource/base.rb', line 66 def save(*params) begin super(*params) rescue => e raise TwilioResource::Exception.find_exception(e) end end |