Class: RubyCode::SearchProviders::Base

Inherits:
Object
  • Object
show all
Includes:
Concerns::ErrorHandling, Concerns::HttpClient
Defined in:
lib/rubycode/search_providers/base.rb

Overview

Base class for search providers

Direct Known Subclasses

BraveSearch, DuckduckgoInstant, ExaAi

Instance Method Summary collapse

Constructor Details

#initialize(config: nil, api_key: nil) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
# File 'lib/rubycode/search_providers/base.rb', line 13

def initialize(config: nil, api_key: nil)
  @config = config
  @api_key = api_key
  validate_api_key! if requires_api_key?
end

Instance Method Details

#search(query, max_results: 5) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubycode/search_providers/base.rb', line 19

def search(query, max_results: 5)
  uri_or_request = build_request(query, max_results)

  debug_search_request(query, max_results, uri_or_request) if debug_enabled?

  response = make_http_request(uri_or_request)

  debug_search_response(response) if debug_enabled?

  parse_results(response.body, max_results)
end