Class: ActiveCic::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cic/active_cic.rb

Direct Known Subclasses

Cic::Category, Cic::Group, Cic::Report

Constant Summary collapse

BASE_URL =
"api.nl.cic.mx/0/nl"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Base

Returns a new instance of Base.



17
18
19
20
# File 'lib/cic/active_cic.rb', line 17

def initialize(hash)
  self.attributes = Hashie::Mash.new(hash) 
  @raw_attributes = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



22
23
24
25
26
# File 'lib/cic/active_cic.rb', line 22

def method_missing(name, *args)
  self.attributes.send(name, args)
rescue NoMethodError
  super
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



8
9
10
# File 'lib/cic/active_cic.rb', line 8

def attributes
  @attributes
end

#raw_attributesObject (readonly)

Returns the value of attribute raw_attributes.



9
10
11
# File 'lib/cic/active_cic.rb', line 9

def raw_attributes
  @raw_attributes
end

Class Method Details

.allObject



28
29
30
31
32
33
34
35
36
# File 'lib/cic/active_cic.rb', line 28

def self.all
  class_name = self.pluralize_child_class_name
  response = self.get("/#{class_name}.json") 
  if response.success?
    response.parsed_response[class_name].map { |hash| self.new(hash) } 
  else
    raise_exception(response.code, response.body)
  end
end