Class: SlimpayClient::Resource

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

Overview

An abstract resource to be inherited from.

Defines API resource non-semantic methods.

Instance Method Summary collapse

Methods inherited from Base

#generate_api_methods

Constructor Details

#initializeResource

Returns a new instance of Resource.



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

def initialize
  @resource_name = self.class.to_s.demodulize.underscore.dasherize.pluralize
  super
end

Instance Method Details

#get_one(reference = 1) ⇒ Object

Shortcut method to get a resource with only resource’s reference.

The above example shall return the same result as

mandates = SlimpayClient::Mandate.new
mandates.get_mandates({creditorReference: @creditor_reference, reference: 1})
Example:
mandates = SlimpayClient::Mandate.new
mandates.get_one(1)
Arguments:
reference: (String)


22
23
24
25
26
27
# File 'lib/slimpay_client/resource.rb', line 22

def get_one(reference = 1)
  url = "#{@endpoint}/creditors/#{@creditor_reference}/#{@resource_name}/#{reference}"
  response = HTTParty.get(url, headers: options)
  generate_api_methods(JSON.parse(response.body))
  SlimpayClient.answer(response)
end