class Paylike::Resource

Base resource class

Public Class Methods

all(params = {}) click to toggle source

Resource collection finder, uses the default limit

@param params [Hash] URI parameters to pass to the endpoint. @return [Array] of [Paylike::Resource] instances

Calls superclass method
# File lib/paylike/resource.rb, line 14
def self.all(params = {})
  params[:limit] ||= 100
  super(params)
end
extract_error(_, parsed_response) click to toggle source

Extracts the error message from the response

@param response [HTTP::Response] the server response @param parsed_response [Object] the parsed server response

@return [String]

# File lib/paylike/resource.rb, line 54
def self.extract_error(_, parsed_response)
  parsed_response.delete('message') if parsed_response.respond_to?(:delete)
end
find(id, params = {}) click to toggle source

Resource finder

@param id [String] resource indentifier @return [Paylike::Resource] instance

# File lib/paylike/resource.rb, line 23
def self.find(id, params = {})
  objectify(request(:get, uri_sans_merchant_id(id), params: params))
end
parse_response(response) click to toggle source

Custom response parser to extract successful payloads

@param response [HTTP::Response] object @return [Object] on parsable responses

Calls superclass method
# File lib/paylike/resource.rb, line 38
def self.parse_response(response)
  parsed = super

  return parsed.values.first if parsed.is_a?(Hash) && parsed.size == 1

  return parsed.first if parsed.is_a?(Array) && parsed.size == 1

  parsed
end
uri_sans_merchant_id(*args) click to toggle source

Like `uri`, but removes any merchant ID from the path

@return [String]

# File lib/paylike/resource.rb, line 30
def self.uri_sans_merchant_id(*args)
  uri(*args).to_s.gsub(%r{\/merchants\/[\w]+}, '')
end