class Devtunnel::Entity

Attributes

list[RW]
meta[RW]
object[RW]

Public Class Methods

build_from_hash(hash) click to toggle source
# File lib/devtunnel/entity.rb, line 29
def self.build_from_hash(hash)
  # our hash should always include a class attribute that we can use
  # to map back to a proper Entity type
  #
  if !hash["success"].nil? and hash.keys.length == 1
    return Devtunnel::SuccessResponse.new hash["success"]
  end

  hash["new_record"] = false
  case hash["class"]
    when "account"
      Devtunnel::Account.new hash
    else
      raise NoSuchEntity.new("Unknown return type in API response data: #{hash["class"]}")
  end
end
build_from_list(list) click to toggle source
# File lib/devtunnel/entity.rb, line 17
def self.build_from_list(list)
  list.map do |e|
    if e.is_a? Hash
      self.build_from_hash(e)
    elsif e.is_a? Array
      self.build_from_list(e)
    else
      # TODO: throw some weird entity error
    end
  end
end
new(json) click to toggle source
# File lib/devtunnel/entity.rb, line 8
def initialize(json)
  self.meta = json["meta"] if json["meta"]
  if json["list"]
    self.list = Entity.build_from_list(json["list"])
  else
    self.object = Entity.build_from_hash(json)
  end
end