Class: GeminiCache::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/gemini_cache/api_client.rb

Defined Under Namespace

Classes: ApiError

Instance Method Summary collapse

Constructor Details

#initializeApiClient

Returns a new instance of ApiClient.



5
6
7
8
9
10
# File 'lib/gemini_cache/api_client.rb', line 5

def initialize
  @conn = Faraday.new(
    url: GeminiCache.configuration.api_base_url,
    headers: { 'Content-Type' => 'application/json' }
  )
end

Instance Method Details

#create_cache(content) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/gemini_cache/api_client.rb', line 12

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) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/gemini_cache/api_client.rb', line 38

def delete_cache(name)
  response = @conn.delete("/v1beta/#{name}") do |req|
    req.params['key'] = api_key
  end

  handle_response(response)
end

#list_cachesObject



21
22
23
24
25
26
27
# File 'lib/gemini_cache/api_client.rb', line 21

def list_caches
  response = @conn.get('/v1beta/cachedContents') do |req|
    req.params['key'] = api_key
  end

  handle_response(response)
end

#update_cache(name, content) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/gemini_cache/api_client.rb', line 29

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