Sha256: f58619b949debec88b259e4fd89b970485ba2f69f89ac22e5de9daf8cbff60fa

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require 'faraday'
require 'json'

require 'algolia/enums/call_type'

module Algolia
  module Search
    class Config < AlgoliaConfig
      include CallType
      attr_accessor :default_hosts

      # Initialize a config
      #
      # @option options [String] :app_id
      # @option options [String] :api_key
      # @option options [Hash] :custom_hosts
      #
      def initialize(opts = {})
        super(opts)
        @default_hosts = []
        hosts          = []
        hosts << Transport::StatefulHost.new("#{app_id}-dsn.algolia.net", accept: READ)
        hosts << Transport::StatefulHost.new("#{app_id}.algolia.net", accept: WRITE)

        stateful_hosts = 1.upto(3).map do |i|
          Transport::StatefulHost.new("#{app_id}-#{i}.algolianet.com", accept: READ | WRITE)
        end.shuffle

        if opts.has_key?(:custom_hosts)
          opts[:custom_hosts].each do |host|
            host = Transport::StatefulHost.new(host)
            @default_hosts.push(host)
          end
        else
          @default_hosts = hosts + stateful_hosts
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
algolia-2.0.0.pre.alpha.4 lib/algolia/config/search_config.rb
algolia-2.0.0.pre.alpha.3 lib/algolia/config/search_config.rb
algolia-2.0.0.pre.alpha.2 lib/algolia/config/search_config.rb