Class: Emailable::APIResource

Inherits:
Object
  • Object
show all
Defined in:
lib/emailable/resources/api_resource.rb

Direct Known Subclasses

Account, BatchStatus, Verification

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ APIResource

Returns a new instance of APIResource.



4
5
6
7
8
# File 'lib/emailable/resources/api_resource.rb', line 4

def initialize(attributes = {})
  attributes.each do |attr, value|
    instance_variable_set("@#{attr}", value)
  end
end

Instance Method Details

#inspectObject



22
23
24
25
# File 'lib/emailable/resources/api_resource.rb', line 22

def inspect
  "#<#{self.class}:0x#{(object_id << 1).to_s(16)}> JSON: " +
    JSON.pretty_generate(to_h)
end

#to_hObject Also known as: to_hash



10
11
12
13
14
# File 'lib/emailable/resources/api_resource.rb', line 10

def to_h
  instance_variables.map do |e|
    [e.to_s.delete('@').to_sym, instance_variable_get(e)]
  end.to_h
end

#to_jsonObject



18
19
20
# File 'lib/emailable/resources/api_resource.rb', line 18

def to_json
  JSON.generate(to_h)
end