Sha256: 19d9b87411471b1334c59b522d15e17363b6c7a76c5e470903b86a2b2249980c

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

module Nazrin
  class DocumentClient
    attr_reader :client

    def initialize
      @client = Aws::CloudSearchDomain::Client.new(
        endpoint: Nazrin.config.document_endpoint,
        region: Nazrin.config.region,
        access_key_id: Nazrin.config.access_key_id,
        secret_access_key: Nazrin.config.secret_access_key)
    end

    def add_document(id, field_data)
      ActiveSupport::Deprecation.warn 'config.debug_mode is deprecated. Use config.mode = \'sandbox\' instead.' and return nil if Nazrin.config.debug_mode
      return nil if Nazrin.config.mode == 'sandbox'
      client.upload_documents(
        documents: [
          {
            type: 'add',
            id: id,
            fields: field_data
          }
        ].to_json,
        content_type: 'application/json')
    end

    def delete_document(id)
      ActiveSupport::Deprecation.warn 'config.debug_mode is deprecated. Use config.mode = \'sandbox\' instead.' and return nil if Nazrin.config.debug_mode
      return nil if Nazrin.config.mode == 'sandbox'
      client.upload_documents(
        documents: [
          {
            type: 'delete',
            id: id
          }
        ].to_json,
        content_type: 'application/json')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nazrin-2.3.0 lib/nazrin/document_client.rb
nazrin-2.2.0 lib/nazrin/document_client.rb
nazrin-2.1.2 lib/nazrin/document_client.rb
nazrin-2.1.1 lib/nazrin/document_client.rb