Class: Billogram::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/billogram/resource.rb

Direct Known Subclasses

Invoice

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource.



28
29
30
# File 'lib/billogram/resource.rb', line 28

def initialize(attributes = {})
  @attributes = Hashie::Mash.new(attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/billogram/resource.rb', line 42

def method_missing(method, *args)
  method_name = method.to_s

  if method_name =~ /(=|\?)$/
    case $1
    when '='
      attributes[$`] = args.first
    when '?'
      attributes[$`]
    end
  else
    if attributes.respond_to?(method)
      attributes[method]
    else
      super
    end
  end
end

Class Attribute Details

.endpointObject



6
7
8
# File 'lib/billogram/resource.rb', line 6

def endpoint
  @endpoint || downcased_class_name
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



26
27
28
# File 'lib/billogram/resource.rb', line 26

def attributes
  @attributes
end

Class Method Details

.get(id = '') ⇒ Object



10
11
12
# File 'lib/billogram/resource.rb', line 10

def get(id = '')
  get_and_return_new("/#{endpoint}/#{id}")
end

Instance Method Details

#deleteObject



36
37
38
# File 'lib/billogram/resource.rb', line 36

def delete
  Billogram.client.delete("/#{endpoint}/#{id}")
end

#update(attributes = {}) ⇒ Object



32
33
34
# File 'lib/billogram/resource.rb', line 32

def update(attributes = {})
  Billogram.client.put("/#{endpoint}/#{id}", attributes)
end