Class: Gusto::AsyncRequestClient
- Inherits:
-
Object
- Object
- Gusto::AsyncRequestClient
- Defined in:
- lib/requests.rb
Instance Attribute Summary collapse
- #base_url ⇒ String readonly
- #conn ⇒ Faraday readonly
- #default_environment ⇒ String readonly
- #token ⇒ String readonly
Instance Method Summary collapse
- #get_headers ⇒ Hash{String => String}
- #get_url(request_options: nil) ⇒ String
- #initialize(base_url: nil, environment: Gusto::Environment::DEMO, max_retries: nil, timeout_in_seconds: nil, token:, gusto_api_version: nil) ⇒ Gusto::AsyncRequestClient constructor
Constructor Details
#initialize(base_url: nil, environment: Gusto::Environment::DEMO, max_retries: nil, timeout_in_seconds: nil, token:, gusto_api_version: nil) ⇒ Gusto::AsyncRequestClient
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/requests.rb', line 87 def initialize(base_url: nil, environment: Gusto::Environment::DEMO, max_retries: nil, timeout_in_seconds: nil, token:, gusto_api_version: nil) @default_environment = environment @base_url = environment || base_url @token = "Bearer #{token}" @headers = { } unless gusto_api_version.nil? @headers["X-Gusto-API-Version"] = gusto_api_version end @conn = Faraday.new(headers: @headers) do | faraday | faraday.request :multipart faraday.request :json faraday.response :raise_error, include_request: true faraday.adapter :async_http unless max_retries.nil? faraday.request :retry , { max: max_retries } end unless timeout_in_seconds.nil? faraday..timeout = timeout_in_seconds end end end |
Instance Attribute Details
#base_url ⇒ String (readonly)
70 71 72 |
# File 'lib/requests.rb', line 70 def base_url @base_url end |
#conn ⇒ Faraday (readonly)
68 69 70 |
# File 'lib/requests.rb', line 68 def conn @conn end |
#default_environment ⇒ String (readonly)
74 75 76 |
# File 'lib/requests.rb', line 74 def default_environment @default_environment end |
#token ⇒ String (readonly)
72 73 74 |
# File 'lib/requests.rb', line 72 def token @token end |
Instance Method Details
#get_headers ⇒ Hash{String => String}
114 115 116 117 118 |
# File 'lib/requests.rb', line 114 def get_headers headers = { "X-Fern-Language": 'Ruby', "X-Fern-SDK-Name": 'fern_gusto', "X-Fern-SDK-Version": '0.0.6-alpha6' } headers["Authorization"] = ((@token.is_a? Method) ? @token.call : @token) unless @token.nil? headers end |
#get_url(request_options: nil) ⇒ String
110 111 112 |
# File 'lib/requests.rb', line 110 def get_url(request_options: nil) &.base_url || @default_environment || @base_url end |