class Clever::Connection
Constants
- OPEN_TIMEOUT
- TIMEOUT
Public Class Methods
new(client)
click to toggle source
# File lib/clever/connection.rb, line 8 def initialize(client) @client = client end
Public Instance Methods
connection()
click to toggle source
# File lib/clever/connection.rb, line 20 def connection return @connection if @connection @connection = Faraday.new(@client.api_url) do |connection| connection.request :json connection.response :logger, @client.logger if @client.logger connection.response :json, content_type: /\bjson$/ connection.adapter Faraday.default_adapter end @connection.basic_auth(@client.vendor_key, @client.vendor_secret) @connection end
execute(path, method = :get, params = nil, body = nil)
click to toggle source
# File lib/clever/connection.rb, line 12 def execute(path, method = :get, params = nil, body = nil) Response.new(raw_request(path, method, params, body)) end
log(message = '')
click to toggle source
# File lib/clever/connection.rb, line 33 def log(message = '') return unless @client.logger @client.logger.info message end
set_token(token)
click to toggle source
# File lib/clever/connection.rb, line 16 def set_token(token) connection.authorization :Bearer, token end
Private Instance Methods
raw_request(path, method, params, body)
click to toggle source
# File lib/clever/connection.rb, line 41 def raw_request(path, method, params, body) p "request #{path} #{params}" connection.public_send(method) do |request| request.options.open_timeout = OPEN_TIMEOUT request.options.timeout = TIMEOUT request.url path, params request.headers['Accept-Header'] = 'application/json' request.body = body end end