Class: WeShipClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/we_ship_client/client.rb

Direct Known Subclasses

TokenClient

Constant Summary collapse

DEFAULT_TIMEOUT =
90

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_client: LoogiHttp::Connection, logger: LoogiHttp.logger, timeout: nil) ⇒ Client

Returns a new instance of Client.

Parameters:

  • http_client (LoogiHttp::Connection) (defaults to: LoogiHttp::Connection)
  • logger (Logger) (defaults to: LoogiHttp.logger)
  • timeout (Integer, nil) (defaults to: nil)

    The request timeout



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/we_ship_client/client.rb', line 15

def initialize(http_client: LoogiHttp::Connection, logger: LoogiHttp.logger, timeout: nil)
  timeout ||= DEFAULT_TIMEOUT

  @http_client = http_client.new(
    Faraday::Connection.new do |connection|
      connection.request :json
      connection.adapter Faraday.default_adapter
      connection.options[:open_timeout] = timeout
      connection.options[:timeout] = timeout
    end
  )
  @logger = logger
end

Instance Attribute Details

#http_clientObject (readonly)

Returns the value of attribute http_client.



10
11
12
# File 'lib/we_ship_client/client.rb', line 10

def http_client
  @http_client
end

#loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/we_ship_client/client.rb', line 10

def logger
  @logger
end

Instance Method Details

#base_urlObject



29
30
31
# File 'lib/we_ship_client/client.rb', line 29

def base_url
  ENV['WE_SHIP_BASE_URL']
end