Class: Jeckle::API
- Inherits:
-
Object
- Object
- Jeckle::API
- Defined in:
- lib/jeckle/api.rb
Instance Attribute Summary collapse
- #base_uri ⇒ Object
-
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
- #headers ⇒ Object
-
#logger ⇒ Object
Returns the value of attribute logger.
- #namespaces ⇒ Object
-
#open_timeout ⇒ Object
writeonly
Sets the attribute open_timeout.
- #params ⇒ Object
-
#read_timeout ⇒ Object
writeonly
Sets the attribute read_timeout.
-
#request_timeout ⇒ Object
readonly
Returns the value of attribute request_timeout.
Instance Method Summary collapse
Instance Attribute Details
#base_uri ⇒ Object
26 27 28 |
# File 'lib/jeckle/api.rb', line 26 def base_uri [@base_uri, *namespaces.values].join '/' end |
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
5 6 7 |
# File 'lib/jeckle/api.rb', line 5 def basic_auth @basic_auth end |
#headers ⇒ Object
34 35 36 |
# File 'lib/jeckle/api.rb', line 34 def headers @headers || {} end |
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'lib/jeckle/api.rb', line 3 def logger @logger end |
#namespaces ⇒ Object
38 39 40 |
# File 'lib/jeckle/api.rb', line 38 def namespaces @namespaces || {} end |
#open_timeout=(value) ⇒ Object (writeonly)
Sets the attribute open_timeout
4 5 6 |
# File 'lib/jeckle/api.rb', line 4 def open_timeout=(value) @open_timeout = value end |
#params ⇒ Object
30 31 32 |
# File 'lib/jeckle/api.rb', line 30 def params @params || {} end |
#read_timeout=(value) ⇒ Object (writeonly)
Sets the attribute read_timeout
4 5 6 |
# File 'lib/jeckle/api.rb', line 4 def read_timeout=(value) @read_timeout = value end |
#request_timeout ⇒ Object (readonly)
Returns the value of attribute request_timeout.
5 6 7 |
# File 'lib/jeckle/api.rb', line 5 def request_timeout @request_timeout end |
Instance Method Details
#connection ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/jeckle/api.rb', line 7 def connection @connection ||= Faraday.new(url: base_uri, request: timeout).tap do |conn| conn.headers = headers conn.params = params conn.response :logger, logger conn.basic_auth basic_auth[:username], basic_auth[:password] if basic_auth conn.instance_exec &@middlewares_block if @middlewares_block end end |
#middlewares(&block) ⇒ Object
42 43 44 45 46 |
# File 'lib/jeckle/api.rb', line 42 def middlewares(&block) raise Jeckle::ArgumentError, 'A block is required when configuring API middlewares' unless block_given? @middlewares_block = block end |
#timeout ⇒ Object
48 49 50 51 52 53 |
# File 'lib/jeckle/api.rb', line 48 def timeout {}.tap do |t| t[:open_timeout] = @open_timeout if @open_timeout t[:timeout] = @read_timeout if @read_timeout end end |