class FlowCl::Client
Public Class Methods
new(key, secret, options = {})
click to toggle source
# File lib/flow_cl/client.rb, line 20 def initialize(key, secret, options = {}) @key = key @secret = secret @sandbox = options.delete(:sandbox) @logger = options.delete(:logger) end
Private Instance Methods
conn()
click to toggle source
Main faraday connection
# File lib/flow_cl/client.rb, line 30 def conn url = @sandbox ? API_SANDBOX_URL : API_URL @conn ||= Faraday.new(url: url) do |faraday| faraday.use ErrorHandler faraday.response :logger if @logger faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end
final_params(params)
click to toggle source
# File lib/flow_cl/client.rb, line 57 def final_params(params) params.merge!({ apiKey: @key }) params[:s] = signature(params) params end
parsed_response(response)
click to toggle source
# File lib/flow_cl/client.rb, line 39 def parsed_response(response) JSON.parse(response.body) end
private_get(path, params = {})
click to toggle source
Perform an authenticated GET request
# File lib/flow_cl/client.rb, line 44 def private_get(path, params = {}) response = conn.get path, final_params(params) parsed_response(response) end
private_post(path, params = {})
click to toggle source
Perform an authenticated POST request
# File lib/flow_cl/client.rb, line 51 def private_post(path, params = {}) response = conn.post path, URI.encode_www_form(final_params(params)) parsed_response(response) end
signature(params)
click to toggle source
Generate a signature based on OpenSSL
# File lib/flow_cl/client.rb, line 66 def signature(params) formatted_params = params.sort.flatten.map(&:to_s).join OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret, formatted_params) end