Class: GeminiCache::ApiClient

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeApiClient

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

Parameters:

  • content (String)

    JSON string of cache content

Returns:

  • (Hash)

    API response

Raises:



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

Parameters:

  • name (String)

    cache name

Returns:

  • (Hash)

    API response

Raises:



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_cachesHash

Lists all caches

Returns:

  • (Hash)

    API response

Raises:



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

Parameters:

  • name (String)

    cache name

  • content (String)

    JSON string of new content

Returns:

  • (Hash)

    API response

Raises:



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