Class: Algolia::Transport::RequestOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/algolia/transport/request_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ RequestOptions

Returns a new instance of RequestOptions.

Parameters:

  • config (Search::Config)


8
9
10
11
12
13
14
# File 'lib/algolia/transport/request_options.rb', line 8

def initialize(config)
  @header_params = {}
  @query_params = {}
  @timeout = nil
  @connect_timeout = nil
  @compression_type = config.compression_type
end

Instance Attribute Details

#compression_typeObject

Returns the value of attribute compression_type.



4
5
6
# File 'lib/algolia/transport/request_options.rb', line 4

def compression_type
  @compression_type
end

#connect_timeoutObject

Returns the value of attribute connect_timeout.



4
5
6
# File 'lib/algolia/transport/request_options.rb', line 4

def connect_timeout
  @connect_timeout
end

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/algolia/transport/request_options.rb', line 4

def data
  @data
end

#header_paramsObject

Returns the value of attribute header_params.



4
5
6
# File 'lib/algolia/transport/request_options.rb', line 4

def header_params
  @header_params
end

#query_paramsObject

Returns the value of attribute query_params.



4
5
6
# File 'lib/algolia/transport/request_options.rb', line 4

def query_params
  @query_params
end

#timeoutObject

Returns the value of attribute timeout.



4
5
6
# File 'lib/algolia/transport/request_options.rb', line 4

def timeout
  @timeout
end

Instance Method Details

#add_compression_type(opts = {}) ⇒ Object

Add or update compression_type

Parameters:

  • opts (Hash) (defaults to: {})


78
79
80
81
# File 'lib/algolia/transport/request_options.rb', line 78

def add_compression_type(opts = {})
  @compression_type = opts[:compression_type] || @compression_type
  opts.delete(:compression_type)
end

#add_connect_timeout(opts = {}) ⇒ Object

Add or update connect timeout

Parameters:

  • opts (Hash) (defaults to: {})


69
70
71
72
# File 'lib/algolia/transport/request_options.rb', line 69

def add_connect_timeout(opts = {})
  @connect_timeout = opts[:connect_timeout] || @connect_timeout
  opts.delete(:connect_timeout)
end

#add_header_params(opts = {}) ⇒ Object

Add or update header_params

Parameters:

  • opts (Hash) (defaults to: {})


32
33
34
35
36
37
38
39
40
# File 'lib/algolia/transport/request_options.rb', line 32

def add_header_params(opts = {})
  return if opts[:header_params].nil?

  opts[:header_params].each do |opt, value|
    @header_params[opt.to_s] = value
  end

  opts.delete(:header_params)
end

#add_query_params(opts = {}) ⇒ Object

Add or update query parameters

Parameters:

  • opts (Hash) (defaults to: {})


46
47
48
49
50
51
52
53
54
# File 'lib/algolia/transport/request_options.rb', line 46

def add_query_params(opts = {})
  return if opts[:query_params].nil?

  opts[:query_params].each do |opt, value|
    @query_params[opt.to_sym] = value
  end

  opts.delete(:query_params)
end

#add_timeout(opts = {}) ⇒ Object

Add or update timeout

Parameters:

  • opts (Hash) (defaults to: {})


60
61
62
63
# File 'lib/algolia/transport/request_options.rb', line 60

def add_timeout(opts = {})
  @timeout = opts[:timeout] || @timeout
  opts.delete(:timeout)
end

#create(opts = {}) ⇒ Object

Create and format headers and query params from request options

Parameters:

  • opts (Hash) (defaults to: {})


20
21
22
23
24
25
26
# File 'lib/algolia/transport/request_options.rb', line 20

def create(opts = {})
  add_header_params(opts)
  add_query_params(opts)
  add_timeout(opts)
  add_connect_timeout(opts)
  add_compression_type(opts)
end