Class: Vhx::VhxObject

Inherits:
Object
  • Object
show all
Includes:
HelperMethods
Defined in:
lib/vhx/utilities/vhx_object.rb

Constant Summary collapse

ASSOCIATION_WHITELIST =
['products', 'sites', 'site', 'videos', 'video', 'subscription', 'items', 'customer']

Instance Method Summary collapse

Methods included from HelperMethods

#get_hypermedia, #get_klass

Constructor Details

#initialize(obj_hash) ⇒ VhxObject

Returns a new instance of VhxObject.



6
7
8
9
10
11
12
# File 'lib/vhx/utilities/vhx_object.rb', line 6

def initialize(obj_hash)
  @obj_hash = obj_hash

  validate_class(obj_hash)
  create_readers(obj_hash)
  create_associations(obj_hash)
end

Instance Method Details

#_embeddedObject



38
39
40
# File 'lib/vhx/utilities/vhx_object.rb', line 38

def _embedded
  JSON.parse(@obj_hash['_embedded'].to_json)
end


34
35
36
# File 'lib/vhx/utilities/vhx_object.rb', line 34

def _links
  JSON.parse(@obj_hash['_links'].to_json)
end

#hrefObject



22
23
24
# File 'lib/vhx/utilities/vhx_object.rb', line 22

def href
  @obj_hash['_links']['self']['href']
end


26
27
28
29
30
31
32
# File 'lib/vhx/utilities/vhx_object.rb', line 26

def links
  data = {}
  @obj_hash['_links'].each do |k, v|
    data[k] = v['href']
  end
  return OpenStruct.new(data)
end

#to_hashObject



18
19
20
# File 'lib/vhx/utilities/vhx_object.rb', line 18

def to_hash
  @obj_hash
end

#to_jsonObject



14
15
16
# File 'lib/vhx/utilities/vhx_object.rb', line 14

def to_json
  @obj_hash.to_json
end