Class: Latitude::API::RequestOptions
- Inherits:
-
Object
- Object
- Latitude::API::RequestOptions
- Defined in:
- lib/latitude/api/request_options.rb
Constant Summary collapse
- ALLOWED =
i[ api_key api_version api_base open_timeout read_timeout write_timeout max_network_retries proxy idempotency_key headers ].freeze
Instance Attribute Summary collapse
-
#api_base ⇒ Object
readonly
Returns the value of attribute api_base.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#idempotency_key ⇒ Object
readonly
Returns the value of attribute idempotency_key.
-
#max_network_retries ⇒ Object
readonly
Returns the value of attribute max_network_retries.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#write_timeout ⇒ Object
readonly
Returns the value of attribute write_timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_to(config) ⇒ Object
-
#initialize(opts = {}) ⇒ RequestOptions
constructor
A new instance of RequestOptions.
- #merge(other) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ RequestOptions
Returns a new instance of RequestOptions.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/latitude/api/request_options.rb', line 24 def initialize(opts = {}) opts ||= {} validate!(opts) @api_key = opts[:api_key] @api_version = opts[:api_version] @api_base = opts[:api_base] @open_timeout = opts[:open_timeout] @read_timeout = opts[:read_timeout] @write_timeout = opts[:write_timeout] @max_network_retries = opts[:max_network_retries] @proxy = opts[:proxy] @idempotency_key = opts[:idempotency_key] @headers = opts[:headers] || {} end |
Instance Attribute Details
#api_base ⇒ Object (readonly)
Returns the value of attribute api_base.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def api_base @api_base end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def api_key @api_key end |
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def api_version @api_version end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def headers @headers end |
#idempotency_key ⇒ Object (readonly)
Returns the value of attribute idempotency_key.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def idempotency_key @idempotency_key end |
#max_network_retries ⇒ Object (readonly)
Returns the value of attribute max_network_retries.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def max_network_retries @max_network_retries end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def open_timeout @open_timeout end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def proxy @proxy end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def read_timeout @read_timeout end |
#write_timeout ⇒ Object (readonly)
Returns the value of attribute write_timeout.
19 20 21 |
# File 'lib/latitude/api/request_options.rb', line 19 def write_timeout @write_timeout end |
Class Method Details
.wrap(opts) ⇒ Object
39 40 41 42 43 |
# File 'lib/latitude/api/request_options.rb', line 39 def self.wrap(opts) return opts if opts.is_a?(RequestOptions) new(opts || {}) end |
Instance Method Details
#apply_to(config) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/latitude/api/request_options.rb', line 67 def apply_to(config) overrides = to_h.compact overrides.delete(:idempotency_key) overrides.delete(:headers) return config if overrides.empty? config.dup_with(**overrides) end |
#merge(other) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/latitude/api/request_options.rb', line 45 def merge(other) other = self.class.wrap(other) merged = to_h.merge(other.to_h) { |_k, a, b| b.nil? ? a : b } merged[:headers] = @headers.merge(other.headers || {}) self.class.new(merged) end |
#to_h ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/latitude/api/request_options.rb', line 52 def to_h { api_key: @api_key, api_version: @api_version, api_base: @api_base, open_timeout: @open_timeout, read_timeout: @read_timeout, write_timeout: @write_timeout, max_network_retries: @max_network_retries, proxy: @proxy, idempotency_key: @idempotency_key, headers: @headers, } end |