module Minter::Api::Connection

Constants

DEFAULT_HEADERS

Public Instance Methods

check_params(params, allowed_params) click to toggle source
# File lib/minter/api/connection.rb, line 15
def check_params(params, allowed_params)
  return params if (params.keys - allowed_params).empty?

  raise ParamsError
end

Private Instance Methods

build_url(node_url, path) click to toggle source
# File lib/minter/api/connection.rb, line 39
def build_url(node_url, path)
  URI.parse(node_url + path)
end
connection() click to toggle source
# File lib/minter/api/connection.rb, line 35
def connection
  @connection ||= new_connection
end
get(path, params = {}) click to toggle source
# File lib/minter/api/connection.rb, line 23
def get(path, params = {})
  response = connection.get(build_url(config[:node_url], path), params: params)

  Minter::Api::Result.new(response)
end
new_connection() click to toggle source
# File lib/minter/api/connection.rb, line 43
def new_connection
  HTTP.timeout(timeout_config).headers(accept: ACCEPT_HEADER, content_type: CONTENT_TYPE_HEADER)
end
post(path, params = {}) click to toggle source
# File lib/minter/api/connection.rb, line 29
def post(path, params = {})
  response = connection.post(build_url(config[:node_url], path), params: params)

  Minter::Api::Result.new(response)
end
timeout_config() click to toggle source
# File lib/minter/api/connection.rb, line 47
def timeout_config
  @timeout_config ||= {
    connect: config[:connect_timeout],
    write: config[:write_timeout],
    read: config[:read_timeout]
  }
end