Module: Xively::Parsers::JSON::KeyDefaults

Included in:
Key
Defined in:
lib/xively-rb/parsers/json/key_defaults.rb

Instance Method Summary collapse

Instance Method Details

#from_json(json) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/xively-rb/parsers/json/key_defaults.rb', line 5

def from_json(json)
  begin
    hash = MultiJson.load(json)["key"]
  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["id"] = hash.delete("id")
  hash["key"] = hash.delete("api_key")
  hash
end