Class: Clever::Connection
- Inherits:
-
Object
- Object
- Clever::Connection
- Defined in:
- lib/clever/connection.rb
Constant Summary collapse
- OPEN_TIMEOUT =
60
- TIMEOUT =
120
Instance Method Summary collapse
- #connection ⇒ Object
- #execute(path, method = :get, params = nil, body = nil) ⇒ Object
-
#initialize(client) ⇒ Connection
constructor
A new instance of Connection.
- #log(message = '') ⇒ Object
- #set_token(token) ⇒ Object
Constructor Details
#initialize(client) ⇒ Connection
Returns a new instance of Connection.
8 9 10 |
# File 'lib/clever/connection.rb', line 8 def initialize(client) @client = client end |
Instance Method Details
#connection ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
12 13 14 |
# 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 = '') ⇒ Object
33 34 35 36 37 |
# File 'lib/clever/connection.rb', line 33 def log( = '') return unless @client.logger @client.logger.info end |
#set_token(token) ⇒ Object
16 17 18 |
# File 'lib/clever/connection.rb', line 16 def set_token(token) connection. :Bearer, token end |