Class: NewDemoApiClient::AsyncRequestClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, base_url: nil, environment: NewDemoApiClient::Environment::DEFAULT, max_retries: nil, timeout_in_seconds: nil) ⇒ NewDemoApiClient::AsyncRequestClient

Parameters:

  • base_url (String) (defaults to: nil)
  • environment (NewDemoApiClient::Environment) (defaults to: NewDemoApiClient::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)
  • token (String)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/requests.rb', line 70

def initialize(token:, base_url: nil, environment: NewDemoApiClient::Environment::DEFAULT, max_retries: nil,
               timeout_in_seconds: nil)
  @default_environment = environment
  @base_url = environment || base_url
  @token = "Bearer #{token}"
  @conn = Faraday.new do |faraday|
    faraday.request :multipart
    faraday.request :json
    faraday.response :raise_error, include_request: true
    faraday.adapter :async_http
    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_urlString (readonly)

Returns:

  • (String)


58
59
60
# File 'lib/requests.rb', line 58

def base_url
  @base_url
end

#connFaraday (readonly)

Returns:

  • (Faraday)


56
57
58
# File 'lib/requests.rb', line 56

def conn
  @conn
end

#default_environmentString (readonly)

Returns:

  • (String)


62
63
64
# File 'lib/requests.rb', line 62

def default_environment
  @default_environment
end

#tokenString (readonly)

Returns:

  • (String)


60
61
62
# File 'lib/requests.rb', line 60

def token
  @token
end

Instance Method Details

#get_headersHash{String => String}

Returns:

  • (Hash{String => String})


92
93
94
95
96
# File 'lib/requests.rb', line 92

def get_headers
  headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "test_sdk", "X-Fern-SDK-Version": "0.0.4" }
  headers["Authorization"] = ((@token.is_a? Method) ? @token.call : @token) unless @token.nil?
  headers
end

#get_url(request_options: nil) ⇒ String

Parameters:

Returns:

  • (String)


87
88
89
# File 'lib/requests.rb', line 87

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