class Hummer::Client::Model::Base

Public Class Methods

all(resource = nil) click to toggle source
# File lib/hummer/client/model/base.rb, line 32
def self.all(resource = nil)
  JSON(@@server[resource || @resource].get).collect do |params|
    new(params)
  end
rescue => e
  puts "API error: #{e.message}"
  exit(1)
end
attributes(*args) click to toggle source
# File lib/hummer/client/model/base.rb, line 18
def self.attributes *args
  @attributes = []
  args.each do |arg|
    @attributes << arg
    self.class_eval("def #{arg};@#{arg};end")
    self.class_eval("def #{arg}=(val);@#{arg}=val;end")
  end
end
configure(options) click to toggle source
# File lib/hummer/client/model/base.rb, line 6
def self.configure(options)
  @@server = RestClient::Resource.new(options[:server],
    :headers => {
      "X-User-ID" => options[:user],
      "X-User-Token" => options[:token],
      "Accept" => "application/json"
    }
  )
end
find(id, resource = nil) click to toggle source
# File lib/hummer/client/model/base.rb, line 26
def self.find(id, resource = nil)
  new(JSON(@@server[resource || @resource][id].get))
rescue => e
  puts "API error: #{e.message}"
  exit(1)
end
new(params = {}) click to toggle source
# File lib/hummer/client/model/base.rb, line 40
def initialize(params = {})
  params.each do |key, value|
    send("#{key}=", value) if respond_to? "#{key}="
  end
end
resource(res) click to toggle source
# File lib/hummer/client/model/base.rb, line 15
def self.resource res
  @resource = res
end