Module: Wrest::Components::Translators

Defined in:
lib/wrest/components/translators.rb,
lib/wrest/components/translators/xml.rb,
lib/wrest/components/translators/json.rb,
lib/wrest/components/translators/content_types.rb

Overview

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: Json, Xml

Constant Summary collapse

CONTENT_TYPES =

Maps content types to deserialisers

{
  'application/xml' => Wrest::Components::Translators::Xml,
  'text/xml' => Wrest::Components::Translators::Xml,
  'application/json' => Wrest::Components::Translators::Json,
  'text/javascript' => Wrest::Components::Translators::Json
}

Class Method Summary collapse

Class Method Details

.lookup(content_type) ⇒ Object

Loads the appropriate desirialisation strategy based on the content type



16
17
18
19
# File 'lib/wrest/components/translators.rb', line 16

def self.lookup(content_type)
  translator = CONTENT_TYPES[content_type]
  translator || (raise Wrest::Exceptions::UnsupportedContentTypeException.new("Unsupported content type #{content_type}"))
end