Class: RubyCode::SearchProviders::Base
- Inherits:
-
Object
- Object
- RubyCode::SearchProviders::Base
- Includes:
- Concerns::ErrorHandling, Concerns::HttpClient
- Defined in:
- lib/rubycode/search_providers/base.rb
Overview
Base class for search providers
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(config: nil, api_key: nil) ⇒ Base
constructor
A new instance of Base.
- #search(query, max_results: 5) ⇒ Object
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 |