module EbanqApi::ResponseWrapper

Provides a helpers for wrapping of Ebanq API responses

Public Instance Methods

wrap(response) click to toggle source

Transform Ebanq API response to OpenStruct data structure in case it is a hash. Otherwise returns ruby array etc.

Attributes

  • response - response from EbanqAPI

# File lib/ebanq_api/response_wrapper.rb, line 14
def wrap(response)
  if response.is_a?(Hash)
    response.keys.each { |key| response[key] = wrap(response[key]) }
    wrap_hash(response)
  elsif response.is_a?(Array)
    response.map(&method(:wrap_hash))
  else
    response
  end
end

Private Instance Methods

wrap_hash(response) click to toggle source
# File lib/ebanq_api/response_wrapper.rb, line 27
def wrap_hash(response)
  response.is_a?(Hash) ? OpenStruct.new(response) : response
end