Class: TorgApi::Base

Inherits:
Object
  • Object
show all
Extended by:
Constants
Includes:
Constants
Defined in:
lib/torg_api/base.rb

Constant Summary collapse

REMOVE_HASH_ATTRS =
[:@id]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Base

Returns a new instance of Base.



23
24
25
26
27
# File 'lib/torg_api/base.rb', line 23

def initialize(args = {})
  self.class.attributes.each do |attribute|
    self.send("#{attribute}=", args[attribute]) if args.key?(attribute)
  end
end

Class Method Details

.attr_accessor(*vars) ⇒ Object



8
9
10
11
12
# File 'lib/torg_api/base.rb', line 8

def attr_accessor(*vars)
  @attributes ||= []
  @attributes.concat vars
  super(*vars)
end

.attributesObject



14
15
16
# File 'lib/torg_api/base.rb', line 14

def attributes
  @attributes
end

.torg_resourceObject



18
19
20
# File 'lib/torg_api/base.rb', line 18

def torg_resource
  @@torg_resource ||= RestClient::Resource.new(Settings.torg_url[:host], Settings.torg_url[:ssl])
end

Instance Method Details

#to_hObject



29
30
31
32
33
34
35
36
# File 'lib/torg_api/base.rb', line 29

def to_h
  hash = {}
  vars = instance_variables
  REMOVE_HASH_ATTRS.each { |a| vars.delete(a) }

  vars.each { |var| hash[var.to_s.delete('@').to_sym] = instance_variable_get(var) }
  hash
end