Class: Safelylaunch::HttpConnection
- Inherits:
-
Object
- Object
- Safelylaunch::HttpConnection
- Defined in:
- lib/safelylaunch/http_connection.rb
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#cache_time ⇒ Object
readonly
Returns the value of attribute cache_time.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(api_token:, logger: Logger.new(STDOUT), cache_time: nil, host: 'http://localhost:2300') ⇒ HttpConnection
constructor
A new instance of HttpConnection.
Constructor Details
#initialize(api_token:, logger: Logger.new(STDOUT), cache_time: nil, host: 'http://localhost:2300') ⇒ HttpConnection
Returns a new instance of HttpConnection.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/safelylaunch/http_connection.rb', line 9 def initialize(api_token:, logger: Logger.new(STDOUT), cache_time: nil, host: 'http://localhost:2300') @api_token = api_token @logger = logger @host = host @cache_time = cache_time @cache = HttpCache.new @connection = Faraday.new(url: host, request: { timeout: 10 }) do |conn| conn.response :json, content_type: %r{application/json}, parser_options: { symbolize_names: true } conn.response :logger, logger conn.adapter Faraday.default_adapter end end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
7 8 9 |
# File 'lib/safelylaunch/http_connection.rb', line 7 def api_token @api_token end |
#cache_time ⇒ Object (readonly)
Returns the value of attribute cache_time.
7 8 9 |
# File 'lib/safelylaunch/http_connection.rb', line 7 def cache_time @cache_time end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/safelylaunch/http_connection.rb', line 7 def connection @connection end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/safelylaunch/http_connection.rb', line 7 def host @host end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/safelylaunch/http_connection.rb', line 7 def logger @logger end |
Instance Method Details
#get(key) ⇒ Object
25 26 27 |
# File 'lib/safelylaunch/http_connection.rb', line 25 def get(key) cache_time ? cached_check_toggle(key) : check_toggle(key) end |