Class: ElasticsearchServerless::Client
- Inherits:
-
Object
- Object
- ElasticsearchServerless::Client
- Includes:
- API
- Defined in:
- lib/elasticsearch-serverless.rb
Constant Summary collapse
- VALID_PARAMETERS =
[:adapter, :log, :logger, :serializer_class, :trace, :tracer, :headers, :request_timeout, :retry_on_status, :retry_on_failure, :delay_on_retry, :opentelemetry_tracer_provider]
Constants included from API
API::API_NAMESPACES, API::HTTP_DELETE, API::HTTP_GET, API::HTTP_HEAD, API::HTTP_POST, API::HTTP_PUT, API::UPPERCASE_APIS
Instance Method Summary collapse
- #essential_parameters(url, api_key) ⇒ Object
-
#initialize(api_key:, url:, arguments: {}) ⇒ Client
constructor
Initializes an Elasticsearch Serverless Client.
-
#method_missing(name, *args, &block) ⇒ Object
Metaprogramming for integration with Transport.
- #respond_to_missing?(method_name, *args) ⇒ Boolean
- #user_agent ⇒ Object
- #validate_arguments(arguments) ⇒ Object
Methods included from API
Methods included from API::Actions
#bulk, #clear_scroll, #close_point_in_time, #count, #create, #delete, #delete_by_query, #delete_script, #exists, #exists_source, #explain, #field_caps, #get, #get_script, #get_source, #index, #info, #mget, #msearch, #msearch_template, #mtermvectors, #open_point_in_time, #ping, #put_script, #rank_eval, #reindex, #render_search_template, #scripts_painless_execute, #scroll, #search, #search_mvt, #search_template, #terms_enum, #termvector, #termvectors, #update, #update_by_query
Constructor Details
#initialize(api_key:, url:, arguments: {}) ⇒ Client
Initializes an Elasticsearch Serverless Client
51 52 53 54 55 |
# File 'lib/elasticsearch-serverless.rb', line 51 def initialize(api_key:, url:, arguments: {}) validate_arguments(arguments) arguments.merge!(essential_parameters(url, api_key)) @transport = Elastic::Transport::Client.new(arguments) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Metaprogramming for integration with Transport
78 79 80 81 82 83 84 |
# File 'lib/elasticsearch-serverless.rb', line 78 def method_missing(name, *args, &block) if methods.include?(name) super else @transport.send(name, *args, &block) end end |
Instance Method Details
#essential_parameters(url, api_key) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/elasticsearch-serverless.rb', line 57 def essential_parameters(url, api_key) { host: url, transport_options: { headers: { 'Authorization' => "ApiKey #{api_key}", 'Elastic-Api-Version' => ElasticsearchServerless::API_VERSION, user_agent: user_agent } }, compression: true } end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
86 87 88 |
# File 'lib/elasticsearch-serverless.rb', line 86 def respond_to_missing?(method_name, *args) @transport.respond_to?(method_name) || super end |
#user_agent ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/elasticsearch-serverless.rb', line 90 def user_agent user_agent = [ "elasticsearch-serverless-ruby/#{ElasticsearchServerless::VERSION}", "elastic-transport-ruby/#{Elastic::Transport::VERSION}", "RUBY_VERSION: #{RUBY_VERSION}" ] if RbConfig::CONFIG && RbConfig::CONFIG['host_os'] user_agent << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}" end user_agent.join('; ') end |
#validate_arguments(arguments) ⇒ Object
71 72 73 74 75 |
# File 'lib/elasticsearch-serverless.rb', line 71 def validate_arguments(arguments) arguments.map do |k, _| raise ArgumentError, "Parameter #{k}" unless VALID_PARAMETERS.include?(k) end end |