class EcalClient::Api::Base

Constants

API_ENDPOINT

Protected Instance Methods

api_sign(parameters = {}, body = nil) click to toggle source
# File lib/ecal_client/api/base.rb, line 24
def api_sign(parameters = {}, body = nil)
  sorted_keys = parameters.keys.sort
  string = @secret.dup
  string << sorted_keys.inject("") { |memo, key| memo << "#{key}#{parameters[key]}" }
  string << body.to_json if body
  Digest::MD5.hexdigest(string)
end
connection() click to toggle source
# File lib/ecal_client/api/base.rb, line 12
def connection
  @connection ||= Faraday.new(url: API_ENDPOINT) do |faraday|
    faraday.request  :url_encoded
    faraday.response :logger if EcalClient.configuration.options[:verbose]
    faraday.adapter  Faraday.default_adapter
  end
end
generate_params(params, body) click to toggle source
# File lib/ecal_client/api/base.rb, line 32
def generate_params(params, body)
  params.merge(apiSign: api_sign(params, body))
end
headers() click to toggle source
# File lib/ecal_client/api/base.rb, line 20
def headers
  header_json
end
logging(msg) click to toggle source
# File lib/ecal_client/api/base.rb, line 47
def logging(msg)
  puts "[ECAL-CLIENT] #{msg}" if EcalClient.configuration.options[:verbose]
end

Private Instance Methods

header_json() click to toggle source
# File lib/ecal_client/api/base.rb, line 53
def header_json
  {
    'User-Agent'        => 'Ecal Client SDK',
    'Content-Type'      => 'application/json'
  }
end