Module: Gemini::HTTP

Includes:
HTTPHeaders
Included in:
Client
Defined in:
lib/gemini/http.rb

Instance Method Summary collapse

Methods included from HTTPHeaders

#add_headers

Instance Method Details

#delete(path:) ⇒ Object



57
58
59
60
61
62
# File 'lib/gemini/http.rb', line 57

def delete(path:)
  parse_json(conn.delete(uri(path: path)) do |req|
    req.headers = headers
    req.params = { key: @api_key }
  end&.body)
end

#get(path:, parameters: nil) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/gemini/http.rb', line 7

def get(path:, parameters: nil)
  # Gemini API requires API key as a parameter
  params = (parameters || {}).merge(key: @api_key)
  parse_json(conn.get(uri(path: path), params) do |req|
    req.headers = headers
  end&.body)
end

#json_post(path:, parameters:, query_parameters: {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gemini/http.rb', line 22

def json_post(path:, parameters:, query_parameters: {})
  # Check if there are streaming parameters
  stream_proc = parameters[:stream] if parameters[:stream].respond_to?(:call)
  
  # Determine if we're in streaming mode
  is_streaming = !stream_proc.nil?
  
  # For SSE streaming, add alt=sse to query parameters
  if is_streaming
    query_parameters = query_parameters.merge(alt: 'sse')
  end
  
  # In Gemini API, API key is passed as a query parameter
  query_params = query_parameters.merge(key: @api_key)
  
  # Streaming mode
  if is_streaming
    handle_streaming_request(path, parameters, query_params, stream_proc)
  else
    # Normal batch response mode
    parse_json(conn.post(uri(path: path)) do |req|
      configure_json_post_request(req, parameters)
      req.params = req.params.merge(query_params)
    end&.body)
  end
end

#multipart_post(path:, parameters: nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/gemini/http.rb', line 49

def multipart_post(path:, parameters: nil)
  parse_json(conn(multipart: true).post(uri(path: path)) do |req|
    req.headers = headers.merge({ "Content-Type" => "multipart/form-data" })
    req.params = { key: @api_key }
    req.body = multipart_parameters(parameters)
  end&.body)
end

#post(path:) ⇒ Object



15
16
17
18
19
20
# File 'lib/gemini/http.rb', line 15

def post(path:)
  parse_json(conn.post(uri(path: path)) do |req|
    req.headers = headers
    req.params = { key: @api_key }
  end&.body)
end