Class: Leif::Connection
- Inherits:
-
Object
- Object
- Leif::Connection
- Defined in:
- lib/leif/connection.rb
Defined Under Namespace
Classes: Exchange
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(connection) ⇒ Connection
constructor
A new instance of Connection.
- #request(path, data = {}, method = :unset) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Connection
Returns a new instance of Connection.
8 9 10 |
# File 'lib/leif/connection.rb', line 8 def initialize(connection) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/leif/connection.rb', line 6 def connection @connection end |
Class Method Details
.default_connection(url, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/leif/connection.rb', line 23 def self.default_connection(url, = {}) ssl_verify = .fetch(:ssl_verify, true) Faraday.new(url: url, ssl: { verify: ssl_verify }) do |config| config.request :url_encoded config.response :json, :content_type => /\bjson$/ config.adapter Faraday.default_adapter end end |
.to_url(url, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/leif/connection.rb', line 12 def self.to_url(url, = {}) connection = default_connection(url, ) if .has_key?(:username) and .has_key?(:password) connection.basic_auth .fetch(:username), .fetch(:password) elsif .has_key?(:token) connection.token_auth .fetch(:token) end new(connection) end |