Class: Safelylaunch::HttpConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/safelylaunch/http_connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tokenObject (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_timeObject (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

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/safelylaunch/http_connection.rb', line 7

def connection
  @connection
end

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/safelylaunch/http_connection.rb', line 7

def host
  @host
end

#loggerObject (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