Class: Pinnacle::RequestClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url: nil, environment: Pinnacle::Environment::DEFAULT, max_retries: nil, timeout_in_seconds: nil) ⇒ Pinnacle::RequestClient

Parameters:

  • base_url (String) (defaults to: nil)
  • environment (Pinnacle::Environment) (defaults to: Pinnacle::Environment::DEFAULT)
  • 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)
  • api_key (String)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/requests.rb', line 25

def initialize(api_key:, base_url: nil, environment: Pinnacle::Environment::DEFAULT, max_retries: nil,
               timeout_in_seconds: nil)
  @default_environment = environment
  @base_url = environment || base_url
  @api_key = api_key
  @conn = Faraday.new 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

#api_keyString (readonly)

Returns:

  • (String)


15
16
17
# File 'lib/requests.rb', line 15

def api_key
  @api_key
end

#base_urlString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/requests.rb', line 13

def base_url
  @base_url
end

#connFaraday (readonly)

Returns:

  • (Faraday)


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

def conn
  @conn
end

#default_environmentString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/requests.rb', line 17

def default_environment
  @default_environment
end

Instance Method Details

#get_headersHash{String => String}

Returns:

  • (Hash{String => String})


45
46
47
48
49
# File 'lib/requests.rb', line 45

def get_headers
  headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "rcs", "X-Fern-SDK-Version": "1.0.2" }
  headers["PINNACLE-API-Key"] = ((@api_key.is_a? Method) ? @api_key.call : @api_key) unless @api_key.nil?
  headers
end

#get_url(request_options: nil) ⇒ String

Parameters:

Returns:

  • (String)


40
41
42
# File 'lib/requests.rb', line 40

def get_url(request_options: nil)
  request_options&.base_url || @default_environment || @base_url
end