Class: GeminiCache::ApiClient
- Inherits:
-
Object
- Object
- GeminiCache::ApiClient
- Defined in:
- lib/gemini_cache/api_client.rb
Overview
Client for making HTTP requests to the Gemini API
Defined Under Namespace
Classes: ApiError
Instance Method Summary collapse
-
#create_cache(content) ⇒ Hash
Creates a new cache.
-
#delete_cache(name) ⇒ Hash
Deletes a cache.
-
#initialize ⇒ ApiClient
constructor
Initializes a new API client.
-
#list_caches ⇒ Hash
Lists all caches.
-
#update_cache(name, content) ⇒ Hash
Updates an existing cache.
Constructor Details
#initialize ⇒ ApiClient
Initializes a new API client
8 9 10 11 12 13 |
# File 'lib/gemini_cache/api_client.rb', line 8 def initialize @conn = Faraday.new( url: GeminiCache.configuration.api_base_url, headers: { 'Content-Type' => 'application/json' } ) end |
Instance Method Details
#create_cache(content) ⇒ Hash
Creates a new cache
19 20 21 22 23 24 25 26 |
# File 'lib/gemini_cache/api_client.rb', line 19 def create_cache(content) response = @conn.post('/v1beta/cachedContents') do |req| req.params['key'] = api_key req.body = content end handle_response(response) end |
#delete_cache(name) ⇒ Hash
Deletes a cache
57 58 59 60 61 62 63 |
# File 'lib/gemini_cache/api_client.rb', line 57 def delete_cache(name) response = @conn.delete("/v1beta/#{name}") do |req| req.params['key'] = api_key end handle_response(response) end |
#list_caches ⇒ Hash
Lists all caches
31 32 33 34 35 36 37 |
# File 'lib/gemini_cache/api_client.rb', line 31 def list_caches response = @conn.get('/v1beta/cachedContents') do |req| req.params['key'] = api_key end handle_response(response) end |
#update_cache(name, content) ⇒ Hash
Updates an existing cache
44 45 46 47 48 49 50 51 |
# File 'lib/gemini_cache/api_client.rb', line 44 def update_cache(name, content) response = @conn.patch("/v1beta/#{name}") do |req| req.params['key'] = api_key req.body = content end handle_response(response) end |