class Elastic::EnterpriseSearch::WorkplaceSearch::Client

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

Public Class Methods

new(options = {}) click to toggle source

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

@param options [Hash] a hash of configuration options @option options [String] :access_token the access token for workplace search @option options [String] :endpoint the endpoint Workplace Search

Calls superclass method Elastic::EnterpriseSearch::Client::new
# File lib/elastic/workplace-search/workplace_search.rb, line 50
def initialize(options = {})
  super(options)
end

Public Instance Methods

authorization_url(client_id, redirect_uri) click to toggle source
# File lib/elastic/workplace-search/workplace_search.rb, line 62
def authorization_url(client_id, redirect_uri)
  [
    host,
    '/ws/oauth/authorize?',
    'response_type=code&',
    "client_id=#{client_id}&",
    "redirect_uri=#{CGI.escape(redirect_uri)}"
  ].join
end
http_auth() click to toggle source
# File lib/elastic/workplace-search/workplace_search.rb, line 54
def http_auth
  @options[:http_auth]
end
http_auth=(access_token) click to toggle source
# File lib/elastic/workplace-search/workplace_search.rb, line 58
def http_auth=(access_token)
  @options[:http_auth] = access_token
end
request_access_token(client_id, client_secret, authorization_code, redirect_uri) click to toggle source
# File lib/elastic/workplace-search/workplace_search.rb, line 72
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