Module: Wrest::Translators
- Defined in:
- lib/wrest/translators.rb,
lib/wrest/translators/xml.rb,
lib/wrest/translators/json.rb,
lib/wrest/translators/typed_hash.rb,
lib/wrest/translators/content_types.rb
Overview
Contains strategies/lambdas which know how to deserialise different content types.
Defined Under Namespace
Classes: TypedHash
Constant Summary collapse
- Xml =
Knows how to deserialise xml. Depends on the xmlsimple gem.
lambda{|response| XmlSimple.xml_in( response.body, 'keeproot' => true ) }
- Json =
Knows how to deserialise json. Depends on the json gem.
lambda{|response| JSON.parse(response.body) }
- CONTENT_TYPES =
Maps content types to deserialisers
{ 'application/xml' => Wrest::Translators::Xml, 'text/xml' => Wrest::Translators::Xml, 'application/json' => Wrest::Translators::Json, 'text/javascript' => Wrest::Translators::Json }
Class Method Summary collapse
-
.load(content_type) ⇒ Object
Loads the appropriate desirialisation strategy based on the content type.
Class Method Details
.load(content_type) ⇒ Object
Loads the appropriate desirialisation strategy based on the content type
16 17 18 19 |
# File 'lib/wrest/translators.rb', line 16 def self.load(content_type) translator = CONTENT_TYPES[content_type] translator || (raise UnsupportedContentTypeException.new("Unsupported content type #{content_type}")) end |