Class: Elastic::EnterpriseSearch::WorkplaceSearch::Client

Inherits:
Client
  • Object
show all
Includes:
Utils, Actions
Defined in:
lib/elastic/workplace-search/workplace_search.rb

Overview

The Workplace Search Client Extends EnterpriseSearch client but overrides authentication to use access token.

Constant Summary

Constants included from Utils

Utils::DEFAULT_HOST

Constants inherited from Client

Client::DEFAULT_TIMEOUT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#stringify_keys, symbolize_keys

Methods included from Actions

#auto_query_refinement_details, #command_sync_jobs, #content_source, #create_analytics_event, #create_batch_synonym_sets, #create_content_source, #create_external_identity, #current_user, #delete_all_documents, #delete_content_source, #delete_documents, #delete_documents_by_query, #delete_external_identity, #delete_synonym_set, #document, #external_identity, #index_documents, #list_content_sources, #list_documents, #list_external_identities, #list_synonym_sets, #put_content_source, #put_content_source_icons, #put_external_identity, #put_synonym_set, #put_triggers_blocklist, #search, #synonym_set, #triggers_blocklist

Methods inherited from Client

#adapter, #app_search, #host, #log, #logger, #open_timeout, #overall_timeout, #trace, #tracer, #transport, #workplace_search

Methods included from Actions

#health, #put_read_only, #read_only, #search_engines, #stats, #version

Methods included from Request

#basic_auth_header, #delete, #get, #post, #put, #request, #setup_authentication_header

Constructor Details

#initialize(options = {}) ⇒ Client

Create a new Elastic::EnterpriseSearch::WorkplaceSearch::Client client

Parameters:

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

    a hash of configuration options

Options Hash (options):

  • :access_token (String)

    the access token for workplace search

  • :endpoint (String)

    the endpoint Workplace Search

  • :kibana_url (String)

    The base URL of your Kibana instance



39
40
41
42
# File 'lib/elastic/workplace-search/workplace_search.rb', line 39

def initialize(options = {})
  @kibana_url = options[:kibana_url]
  super(options)
end

Instance Attribute Details

#kibana_urlObject

Returns the value of attribute kibana_url.



30
31
32
# File 'lib/elastic/workplace-search/workplace_search.rb', line 30

def kibana_url
  @kibana_url
end

Instance Method Details

#authorization_url(client_id, redirect_uri) ⇒ Object

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
59
60
61
62
# File 'lib/elastic/workplace-search/workplace_search.rb', line 52

def authorization_url(client_id, redirect_uri)
  raise ArgumentError, 'kibana_url The base URL of your Kibana instance must be set in the client' unless kibana_url

  [
    kibana_url,
    '/app/enterprise_search/workplace_search/p/oauth/authorize?',
    'response_type=code&',
    "client_id=#{client_id}&",
    "redirect_uri=#{CGI.escape(redirect_uri)}"
  ].join
end

#http_authObject



44
45
46
# File 'lib/elastic/workplace-search/workplace_search.rb', line 44

def http_auth
  @options[:http_auth]
end

#http_auth=(access_token) ⇒ Object



48
49
50
# File 'lib/elastic/workplace-search/workplace_search.rb', line 48

def http_auth=(access_token)
  @options[:http_auth] = access_token
end

#request_access_token(client_id, client_secret, authorization_code, redirect_uri) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/elastic/workplace-search/workplace_search.rb', line 64

def request_access_token(client_id, client_secret, authorization_code, redirect_uri)
  response = request(
    :post,
    '/ws/oauth/token',
    {
      grant_type: 'authorization_code',
      client_id: client_id,
      client_secret: client_secret,
      redirect_uri: redirect_uri,
      code: authorization_code
    }
  )
  response.body['access_token']
end