Module: Xively::Parsers::JSON::DatastreamDefaults

Included in:
Datastream
Defined in:
lib/xively-rb/parsers/json/datastream_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
16
17
18
# File 'lib/xively-rb/parsers/json/datastream_defaults.rb', line 5

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)
  case hash['version']
  when '0.6-alpha'
    transform_0_6_alpha(hash)
  when '1.0.0', nil
    transform_1_0_0(hash)
  end
end