Class: Courier::RequestClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorization_token:, environment: Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil) ⇒ RequestClient

Parameters:

  • environment (Environment) (defaults to: Environment::PRODUCTION)
  • max_retries (Long) (defaults to: nil)

    The number of times to retry a failed request, defaults to 2.

  • timeout_in_seconds (Long) (defaults to: nil)
  • authorization_token (String)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/requests.rb', line 17

def initialize(authorization_token:, environment: Environment::PRODUCTION, max_retries: nil,
               timeout_in_seconds: nil)
  @default_environment = environment
  @base_url = environment
  @headers = {
    "X-Fern-Language": "Ruby",
    "X-Fern-SDK-Name": "Courier",
    "X-Fern-SDK-Version": "3.0.0-beta1",
    "Authorization": %(Bearer #{authorization_token || ENV["COURIER_AUTH_TOKEN"]})
  }
  @conn = Faraday.new(@base_url, headers: @headers) do |faraday|
    faraday.request :json
    faraday.response :raise_error, include_request: true
    faraday.request :retry, { max: max_retries } unless max_retries.nil?
    faraday.options.timeout = timeout_in_seconds unless timeout_in_seconds.nil?
  end
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#connObject (readonly)

Returns the value of attribute conn.



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

def conn
  @conn
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end