class Alman::ApiObject
Attributes
json[R]
Public Class Methods
construct(json)
click to toggle source
# File lib/alman/apibits/api_object.rb, line 6 def self.construct(json) if json.is_a?(Array) return json.map{ |a| ApiObject.construct(a) } elsif json.is_a?(Hash) return ApiObject.new(json) else return json end end
new(json=nil)
click to toggle source
# File lib/alman/apibits/api_object.rb, line 16 def initialize(json=nil) refresh_from(json) end
Public Instance Methods
inspect()
click to toggle source
# File lib/alman/apibits/api_object.rb, line 28 def inspect @json.inspect end
method_missing(name, *args, &blk)
click to toggle source
Calls superclass method
# File lib/alman/apibits/api_object.rb, line 36 def method_missing(name, *args, &blk) if name.to_s.end_with?('=') attr = name.to_s[0...-1].to_sym @json[attr] = args[0] else if @json.respond_to?(name) @json.send(name, *args, &blk) elsif @json.has_key?(name.to_sym) return @json[name.to_sym] else super end end end
refresh_from(json={})
click to toggle source
# File lib/alman/apibits/api_object.rb, line 20 def refresh_from(json={}) @json = Util.sorta_deep_clone(json) @json.each do |k, v| @json[k] = ApiObject.construct(v) end self end
to_json(*args)
click to toggle source
# File lib/alman/apibits/api_object.rb, line 32 def to_json(*args) JSON.generate(@json) end