/
intermediate.rb
50 lines (38 loc) · 915 Bytes
/
intermediate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# RJR Request Message
#
# Copyright (C) 2012-2014 Mohammed Morsi <mo@morsi.org>
# Licensed under the Apache License, Version 2.0
require 'json'
require 'rjr/util/json_parser'
module RJR
module Messages
# Intermediate representation of a JSON-RPC data containing
# extracted/parsed data which has not been analysed.
class Intermediate
# JSON from which data is extracted from
attr_accessor :json
# Data extracted from message
attr_accessor :data
def initialize(args = {})
@json = args[:json] || nil
@data = args[:data] || {}
end
def keys
data.keys
end
def [](key)
data[key.to_s]
end
def has?(key)
data.key?(key)
end
def self.parse(json)
parsed = nil
#allow parsing errs to propagate up
parsed = JSONParser.parse(json)
self.new :json => json,
:data => parsed
end
end # class Intermediate
end # module Messages
end # module RJR