Class: Gusto::RequestClient
- Inherits:
-
Object
- Object
- Gusto::RequestClient
- 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::RequestClient constructor
Constructor Details
#initialize(base_url: nil, environment: Gusto::Environment::DEMO, max_retries: nil, timeout_in_seconds: nil, token:, gusto_api_version: nil) ⇒ Gusto::RequestClient
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/requests.rb', line 34 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 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)
17 18 19 |
# File 'lib/requests.rb', line 17 def base_url @base_url end |
#conn ⇒ Faraday (readonly)
15 16 17 |
# File 'lib/requests.rb', line 15 def conn @conn end |
#default_environment ⇒ String (readonly)
21 22 23 |
# File 'lib/requests.rb', line 21 def default_environment @default_environment end |
#token ⇒ String (readonly)
19 20 21 |
# File 'lib/requests.rb', line 19 def token @token end |
Instance Method Details
#get_headers ⇒ Hash{String => String}
60 61 62 63 64 |
# File 'lib/requests.rb', line 60 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
56 57 58 |
# File 'lib/requests.rb', line 56 def get_url(request_options: nil) &.base_url || @default_environment || @base_url end |