class InvertirOnline::Client::REST

Constants

BASE_URL
ENDPOINTS
METHODS
SignRequestMiddleware

Sign the query string using HMAC(sha-256) and appends to query string

TimestampRequestMiddleware

Generate a timestamp in milliseconds and append to query string

Public Class Methods

add_query_param(query, key, value) click to toggle source
# File lib/invertir-online/client/rest.rb, line 34
def self.add_query_param(query, key, value)
  query = query.to_s
  query << '&' unless query.empty?
  query << "#{Faraday::Utils.escape key}=#{Faraday::Utils.escape value}"
end
new(user: '', password: '', adapter: Faraday.default_adapter) click to toggle source
# File lib/invertir-online/client/rest.rb, line 15
def initialize(user: '', password: '',
               adapter: Faraday.default_adapter)
  @clients = {}
  response = Faraday.post('https://api.invertironline.com/token', username: user, password: password, grant_type: 'password')
  token = JSON.parse(response.body)["access_token"]
  @clients[:signed] = verified_client token, adapter
end

Public Instance Methods

camelize(str) click to toggle source
# File lib/invertir-online/client/rest.rb, line 48
def camelize(str)
  str.split('_')
     .map.with_index { |word, i| i.zero? ? word : word.capitalize }.join
end
replace_path_variables(endpoint, options) click to toggle source
# File lib/invertir-online/client/rest.rb, line 40
def replace_path_variables(endpoint, options)
  replaced_endpoint = endpoint
  options.each do |k, v|
    replaced_endpoint.gsub!(k.to_s, v)
  end
  replaced_endpoint
end
verified_client(token, adapter) click to toggle source
# File lib/invertir-online/client/rest/clients.rb, line 6
def verified_client(token, adapter)
  Faraday.new(url: "#{BASE_URL}/api") do |conn|
    conn.response :json, content_type: /\bjson$/
    conn.headers['Authorization'] = "Bearer #{token}"
    conn.adapter adapter
  end
end