Class: KeyPayAPI::Resource

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

Direct Known Subclasses

ResourceCollection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data) ⇒ Resource

Returns a new instance of Resource.



5
6
7
8
9
10
11
12
13
14
# File 'lib/keypay_api/resource.rb', line 5

def initialize(client, data)
  data = {} unless data.is_a?(Hash)

  @client = client

  data = data.with_indifferent_access

  @data   = OpenStruct.new(data.with_indifferent_access)

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/keypay_api/resource.rb', line 16

def method_missing(method_sym, *arguments, &block)
  if @data.respond_to?(method_sym)
    @data.send(method_sym)
  else
    super
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/keypay_api/resource.rb', line 3

def data
  @data
end