module KeyPayAPI::Client::Connection

Public Instance Methods

delete(path, options = {}) click to toggle source
# File lib/keypay_api/client/connection.rb, line 17
def delete(path, options = {})
  request :delete, path, options
end
get(path, options = {}) click to toggle source
# File lib/keypay_api/client/connection.rb, line 5
def get(path, options = {})
  request :get, path, options
end
post(path, options = {}) click to toggle source
# File lib/keypay_api/client/connection.rb, line 9
def post(path, options = {})
  request :post, path, options
end
put(path, options = {}) click to toggle source
# File lib/keypay_api/client/connection.rb, line 13
def put(path, options = {})
  request :put, path, options
end

Private Instance Methods

parse_data(original_data) click to toggle source
# File lib/keypay_api/client/connection.rb, line 30
def parse_data(original_data)
  return unless original_data

  data = original_data.length == 1 ? original_data.first : original_data  

  case data
  when Hash  then Resource.new(self, data)
  when Array then ResourceCollection.new(self, data)
  when nil   then nil
  else data
  end
end
request(http_method, path, options) click to toggle source
# File lib/keypay_api/client/connection.rb, line 23
def request(http_method, path, options)
  response = self.class.send(http_method, path, { body: options })
  raise KeyPayAPI::Error.new response.message if !response.success?
  data = response.parsed_response
  parse_data(data)
end