Class: Merge::AsyncRequestClient

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: Merge::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, account_token: nil) ⇒ Merge::AsyncRequestClient

Parameters:

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

    Token identifying the end user.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/requests.rb', line 74

def initialize(api_key:, base_url: nil, environment: Merge::Environment::PRODUCTION, max_retries: nil,
               timeout_in_seconds: nil, account_token: nil)
  @default_environment = environment
  @base_url = environment || base_url
  @api_key = "Bearer #{api_key}"
  @headers = {}
  @headers["X-Account-Token"] =  unless .nil?
  @conn = Faraday.new(headers: @headers) 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

#api_keyString (readonly)

Returns:

  • (String)


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

def api_key
  @api_key
end

#base_urlString (readonly)

Returns:

  • (String)


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

def base_url
  @base_url
end

#connFaraday (readonly)

Returns:

  • (Faraday)


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

def conn
  @conn
end

#default_environmentString (readonly)

Returns:

  • (String)


65
66
67
# File 'lib/requests.rb', line 65

def default_environment
  @default_environment
end

Instance Method Details

#get_headersHash{String => String}

Returns:

  • (Hash{String => String})


98
99
100
101
102
# File 'lib/requests.rb', line 98

def get_headers
  headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "merge_ruby_client", "X-Fern-SDK-Version": "0.1.4" }
  headers["Authorization"] = ((@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)


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

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