Class: Hummer::Client::Model::Base
- Inherits:
-
Object
- Object
- Hummer::Client::Model::Base
- Defined in:
- lib/hummer/client/model/base.rb
Class Method Summary collapse
- .all(resource = nil) ⇒ Object
- .attributes(*args) ⇒ Object
- .configure(options) ⇒ Object
- .find(id, resource = nil) ⇒ Object
- .resource(res) ⇒ Object
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
40 41 42 43 44 |
# 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 |
Class Method Details
.all(resource = nil) ⇒ Object
32 33 34 35 36 37 38 39 |
# 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.}" exit(1) end |
.attributes(*args) ⇒ Object
18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/hummer/client/model/base.rb', line 6 def self.configure() @@server = RestClient::Resource.new([:server], :headers => { "X-User-ID" => [:user], "X-User-Token" => [:token], "Accept" => "application/json" } ) end |
.find(id, resource = nil) ⇒ Object
26 27 28 29 30 31 |
# 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.}" exit(1) end |
.resource(res) ⇒ Object
15 16 17 |
# File 'lib/hummer/client/model/base.rb', line 15 def self.resource res @resource = res end |