Class: Algolia::BaseConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/algolia/config/base_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BaseConfig

Returns a new instance of BaseConfig.

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/algolia/config/base_config.rb', line 17

def initialize(opts = {})
  raise AlgoliaError, 'No Application ID provided, please set :application_id' unless opts.has_key?(:application_id)
  raise AlgoliaError, 'No API key provided, please set :api_key' unless opts.has_key?(:api_key)

  @app_id  = opts[:application_id]
  @api_key = opts[:api_key]

  @headers = {
    Defaults::HEADER_API_KEY => @api_key,
    Defaults::HEADER_APP_ID => @app_id,
    'Content-Type' => 'application/json; charset=utf-8',
    'User-Agent' => UserAgent.value
  }

  @batch_size          = opts[:batch_size] || Defaults::BATCH_SIZE
  @read_timeout        = opts[:read_timeout] || Defaults::READ_TIMEOUT
  @write_timeout       = opts[:write_timeout] || Defaults::WRITE_TIMEOUT
  @connect_timeout     = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
  @compression_type    = opts[:compression_type] || Defaults::NONE_ENCODING
  @symbolize_keys      = opts.has_key?(:symbolize_keys) ? opts[:symbolize_keys] : true
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def api_key
  @api_key
end

#app_idObject

Returns the value of attribute app_id.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def app_id
  @app_id
end

#batch_sizeObject

Returns the value of attribute batch_size.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def batch_size
  @batch_size
end

#compression_typeObject

Returns the value of attribute compression_type.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def compression_type
  @compression_type
end

#connect_timeoutObject

Returns the value of attribute connect_timeout.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def connect_timeout
  @connect_timeout
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def headers
  @headers
end

#read_timeoutObject

Returns the value of attribute read_timeout.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def read_timeout
  @read_timeout
end

#symbolize_keysObject

Returns the value of attribute symbolize_keys.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def symbolize_keys
  @symbolize_keys
end

#use_latest_settingsObject

Returns the value of attribute use_latest_settings.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def use_latest_settings
  @use_latest_settings
end

#write_timeoutObject

Returns the value of attribute write_timeout.



5
6
7
# File 'lib/algolia/config/base_config.rb', line 5

def write_timeout
  @write_timeout
end

Instance Method Details

#set_extra_header(key, value) ⇒ Object



39
40
41
# File 'lib/algolia/config/base_config.rb', line 39

def set_extra_header(key, value)
  @headers[key] = value
end