Module: Elastic::EnterpriseSearch::Request

Included in:
Client
Defined in:
lib/elastic/enterprise-search/request.rb

Overview

Module included in Elastic::Enterprise::Client for http requests.

Instance Method Summary collapse

Instance Method Details

#basic_auth_headerObject



75
76
77
78
# File 'lib/elastic/enterprise-search/request.rb', line 75

def basic_auth_header
  credentials = Base64.strict_encode64("#{http_auth[:user]}:#{http_auth[:password]}")
  "Basic #{credentials}"
end

#delete(path, params = {}, headers = {}) ⇒ Object



45
46
47
# File 'lib/elastic/enterprise-search/request.rb', line 45

def delete(path, params = {}, headers = {})
  request(:delete, path, params, headers)
end

#get(path, params = {}, headers = {}) ⇒ Object



33
34
35
# File 'lib/elastic/enterprise-search/request.rb', line 33

def get(path, params = {}, headers = {})
  request(:get, path, params, headers)
end

#post(path, params = {}, body = {}, headers = {}) ⇒ Object



37
38
39
# File 'lib/elastic/enterprise-search/request.rb', line 37

def post(path, params = {}, body = {}, headers = {})
  request(:post, path, params, body, headers)
end

#put(path, params = {}, body = {}, headers = {}) ⇒ Object



41
42
43
# File 'lib/elastic/enterprise-search/request.rb', line 41

def put(path, params = {}, body = {}, headers = {})
  request(:put, path, params, body, headers)
end

#request(method, path, params = {}, body = {}, headers = {}) ⇒ Object

Construct and send a request to the API.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/elastic/enterprise-search/request.rb', line 50

def request(method, path, params = {}, body = {}, headers = {})
  meta_headers = { authorization: decide_authorization(params) }
  headers = if !headers.is_a?(Hash)
              meta_headers
            else
              headers.merge(meta_headers)
            end
  Elastic::API::Response.new(
    @transport.perform_request(method.to_s.upcase, path, params, body, headers)
  )
end

#setup_authentication_headerObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/elastic/enterprise-search/request.rb', line 62

def setup_authentication_header
  if instance_of? Elastic::EnterpriseSearch::Client
    basic_auth_header
  else
    case http_auth
    when Hash
      basic_auth_header
    when String
      "Bearer #{http_auth}"
    end
  end
end