class Omie::BaseResource

This class contains all logic shared among available resources.

Public Class Methods

new(args = {}) click to toggle source

Initialize the object based on a Hash of attributes their respective values

# File lib/omie/base_resource.rb, line 12
def initialize(args = {})
  args.each do |key, value|
    key_s = key.to_sym
    has_internal_const = self.class.const_defined?('INTERNAL_MODELS')
    if has_internal_const && self.class::INTERNAL_MODELS.key?(key_s)
      klass = self.class::INTERNAL_MODELS[key_s]
      instance = klass.new(value)
      send("#{key}=", instance)
    elsif respond_to?(key_s)
      send("#{key}=", value)
    end
  end
end
request(uri, call, params) click to toggle source
# File lib/omie/base_resource.rb, line 33
def self.request(uri, call, params)
  Omie::Connection.request(uri, call, params)
end
request_and_initialize(uri, call, params) click to toggle source
# File lib/omie/base_resource.rb, line 37
def self.request_and_initialize(uri, call, params)
  response = request(uri, call, params)

  new(response)
end

Public Instance Methods

update_attributes(args = {}) click to toggle source

Update the object with the informed attributes passed as a Hash

# File lib/omie/base_resource.rb, line 27
def update_attributes(args = {})
  args.each do |key, value|
    send("#{key}=", value) if respond_to?(key)
  end
end