Class: Algolia::Configuration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id, api_key, hosts, client_name, opts = {}) {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/algolia/configuration.rb', line 23

def initialize(app_id, api_key, hosts, client_name, opts = {})
  @hosts = hosts
  @app_id = app_id
  @api_key = api_key
  @client_side_validation = opts[:client_side_validation].nil? ? true : opts[:client_side_validation]
  @write_timeout = opts[:write_timeout] || 30_000
  @read_timeout = opts[:read_timeout] || 5_000
  @connect_timeout = opts[:connect_timeout] || 2_000
  @compression_type = opts[:compression_type] || "none"
  @requester = opts[:requester]

  @user_agent = UserAgent.new.add(client_name, VERSION)

  if opts[:user_agent_segments]
    opts[:user_agent_segments].each do |segment|
      @user_agent.add(segment)
    end
  end

  @header_params = {
    "X-Algolia-Application-Id" => app_id,
    "X-Algolia-API-Key" => api_key,
    "Content-Type" => "application/json",
    "User-Agent" => @user_agent.value
  }
  @header_params.transform_keys!(&:downcase)

  yield(self) if block_given?
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#app_idObject

Returns the value of attribute app_id.



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

def app_id
  @app_id
end

#client_side_validationtrue, false

Set this to false to skip client side validation in the operation. Default to true.

Returns:

  • (true, false)


21
22
23
# File 'lib/algolia/configuration.rb', line 21

def client_side_validation
  @client_side_validation
end

#compression_typeObject

Returns the value of attribute compression_type.



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

def compression_type
  @compression_type
end

#connect_timeoutObject

Returns the value of attribute connect_timeout.



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

def connect_timeout
  @connect_timeout
end

#header_paramsObject

Returns the value of attribute header_params.



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

def header_params
  @header_params
end

#hostsObject

Returns the value of attribute hosts.



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

def hosts
  @hosts
end

#read_timeoutObject

Returns the value of attribute read_timeout.



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

def read_timeout
  @read_timeout
end

#requesterObject

Returns the value of attribute requester.



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

def requester
  @requester
end

#user_agentObject

Returns the value of attribute user_agent.



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

def user_agent
  @user_agent
end

#write_timeoutObject

Returns the value of attribute write_timeout.



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

def write_timeout
  @write_timeout
end

Class Method Details

.defaultObject

The default Configuration object.



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

def self.default
  @@default ||= Configuration.new
end

Instance Method Details

#add_user_agent_segment(segment, version = nil) ⇒ Object



65
66
67
68
69
70
# File 'lib/algolia/configuration.rb', line 65

def add_user_agent_segment(segment, version = nil)
  @user_agent.add(segment, version)
  @header_params["user-agent"] = @user_agent.value

  self
end

#set_client_api_key(api_key) ⇒ Object



53
54
55
56
57
58
# File 'lib/algolia/configuration.rb', line 53

def set_client_api_key(api_key)
  @api_key = api_key
  @header_params["X-Algolia-API-Key"] = api_key

  self
end