module Ponominalu::API

Constants

BASE_URL

Base part of Ponominalu API endpoint url.

Public Class Methods

call_method(method_name, args = {}, &block) click to toggle source

API method call. @param [String] method_name A name of the method. @param [Hash] args Method arguments. @return [Hashie::Mash] Mashed server response.

# File lib/ponominalu/api.rb, line 11
def call_method(method_name, args = {}, &block)
  method_name_str = method_name.to_s
  url = create_url(method_name_str)
  args = Helpers.flatten(args)

  response = connection(url).send(Ponominalu.http_verb,
    method_name_str, args).body
  Response.process(response, block)
end
connection(url) click to toggle source

Faraday connection. @param [String] url Connection URL (either full or just prefix). @return [Faraday::Connection] Created connection.

# File lib/ponominalu/api.rb, line 24
def connection(url)
  Faraday.new(url, Ponominalu.faraday_options) do |faraday|
    faraday.request  :multipart
    faraday.request  :url_encoded
    faraday.request  :retry, Ponominalu.max_retries
    faraday.response :ponominalu
    faraday.adapter  Ponominalu.adapter
  end
end

Private Class Methods

create_url(method_name) click to toggle source

Creates a complete url from prefixes and the method name @param [String] method_name A name of the method. @return [String] url

# File lib/ponominalu/api.rb, line 38
def create_url(method_name)
  filename = File.expand_path('../simple_methods.yml', __FILE__)
  simple_methods = YAML.load_file(filename)
  url_prefix = simple_methods.include?(method_name) ? '/simple/' :
    '/partner/'
  BASE_URL + url_prefix
end