Module: Cosm::Parsers::JSON::SearchResultDefaults

Includes:
FeedDefaults
Included in:
SearchResult
Defined in:
lib/cosm-rb/parsers/json/search_result_defaults.rb

Instance Method Summary collapse

Methods included from Helpers

#join_tags, #parse_tag_string

Instance Method Details

#from_json(json) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cosm-rb/parsers/json/search_result_defaults.rb', line 7

def from_json(json)
  begin
    hash = MultiJson.load(json)
  rescue MultiJson::DecodeError => e
    raise InvalidJSONError, e.message
  end
  raise InvalidJSONError, "JSON doesn't appear to be a hash" unless hash.is_a?(Hash)

  hash['results'] = hash['results'].collect do |feed|
    transform_1_0_0(feed)
  end
  hash
end