module Lotohelp::Request

Requests library

Public Class Methods

get(path) click to toggle source

Constructing a GET request on the API

@return [ Hash ]

# File lib/lotohelp/request.rb, line 11
def self.get(path)
  params = {
    user_token: Lotohelp::Config.auth_token,
    user_email: Lotohelp::Config.auth_email
  }

  self.do_req(path, :get, params)
end
post(path, params) click to toggle source

Constructing a POST request on the API

@return [ Hash ]

# File lib/lotohelp/request.rb, line 23
def self.post(path, params)
  auth_params = {
    user_token: Lotohelp::Config.auth_token,
    user_email: Lotohelp::Config.auth_email
  }
  request_params = auth_params.merge!(params)

  self.do_req(path, :post, request_params)
end

Private Class Methods

do_req(path, method, params) click to toggle source

Executing the request on the API

@return [ Hash ]

# File lib/lotohelp/request.rb, line 38
def self.do_req(path, method, params)
  request = Typhoeus::Request.new(
    "#{Lotohelp.entrypoint}#{path}",
    method: method,
    params: params,
    headers: { Accept: "application/json" }
  )

  result = request.run

  response = {
    :code => result.code,
    :body => JSON.parse(result.body),
    :header => result.headers
  }
end