Class: TwilioResource::Base
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::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
Have to override this to make empty extensions work (without the dot).
-
.custom_method_collection_url(method_name, options = {}) ⇒ Object
Have to override this to make empty extensions work (without the dot).
-
.element_name ⇒ Object
Twilio uses capitalized path names.
-
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Have to override this to make empty extensions work (without the dot).
- .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.
21 22 23 |
# File 'lib/twilio_resource/base.rb', line 21 def sid @sid end |
.token ⇒ Object Also known as: password
Returns the value of attribute token.
22 23 24 |
# File 'lib/twilio_resource/base.rb', line 22 def token @token end |
Class Method Details
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
Have to override this to make empty extensions work (without the dot)
40 41 42 43 44 45 46 |
# File 'lib/twilio_resource/base.rb', line 40 def self.collection_path( = {}, = nil) , = () if .nil? extension = format.extension.blank? ? "" : ".#{format.extension}" path = "#{prefix()}#{collection_name}#{extension}#{query_string()}" TwilioResource.logger.info("Request: #{path}") path end |
.custom_method_collection_url(method_name, options = {}) ⇒ Object
Have to override this to make empty extensions work (without the dot)
49 50 51 52 53 54 55 |
# File 'lib/twilio_resource/base.rb', line 49 def self.custom_method_collection_url(method_name, = {}) , = () extension = format.extension.blank? ? "" : ".#{format.extension}" path = "#{prefix()}#{collection_name}/#{method_name}#{extension}#{query_string()}" TwilioResource.logger.info("Request: #{path}") path end |
.element_name ⇒ Object
Twilio uses capitalized path names
58 59 60 |
# File 'lib/twilio_resource/base.rb', line 58 def self.element_name super.camelize end |
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Have to override this to make empty extensions work (without the dot)
31 32 33 34 35 36 37 |
# File 'lib/twilio_resource/base.rb', line 31 def self.element_path(id, = {}, = nil) , = () if .nil? extension = format.extension.blank? ? "" : ".#{format.extension}" path = "#{prefix()}#{collection_name}/#{id}#{extension}#{query_string()}" TwilioResource.logger.info("Request: #{path}") path end |
.query_string(params) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/twilio_resource/base.rb', line 62 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
70 71 72 73 74 75 76 77 |
# File 'lib/twilio_resource/base.rb', line 70 def save(*params) begin super(*params) rescue => e raise TwilioResource::Exception.find_exception(e) end end |