class Riffer::Providers::Gemini::Client
HTTP transport for the Gemini REST API. Riffer builds one from the configured api_key by default; construct your own to tune the HTTP knobs and assign it to Riffer.config.gemini.client. Any object implementing post and post_stream with these contracts works there βthe class is a default implementation, not a required base.
Riffer.configure do |config| config.gemini.client = Riffer::Providers::Gemini::Client.new( api_key: ENV["GEMINI_API_KEY"], read_timeout: 120 ) end
Constants
- DEFAULT_BASE_URL
-
@rbs @api_key: String? @rbs @base_url: String @rbs @open_timeout: Integer @rbs @read_timeout: Integer @rbs @write_timeout: Integer? @rbs @proxy_address: String? @rbs @proxy_port: Integer?
- DEFAULT_OPEN_TIMEOUT
- DEFAULT_READ_TIMEOUT
Public Class Methods
Source
# File lib/riffer/providers/gemini/client.rb, line 34 def initialize(api_key: nil, base_url: DEFAULT_BASE_URL, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: nil, proxy_address: nil, proxy_port: nil) @api_key = api_key @base_url = base_url @open_timeout = open_timeout @read_timeout = read_timeout @write_timeout = write_timeout @proxy_address = proxy_address @proxy_port = proxy_port end
: (?api_key: String?, ?base_url: String, ?open_timeout: Integer, ?read_timeout: Integer, ?write_timeout: Integer?, ?proxy_address: String?, ?proxy_port: Integer?) -> void
Public Instance Methods
Source
# File lib/riffer/providers/gemini/client.rb, line 50 def post(path, body) uri = URI("#{@base_url}/#{path}") response = start_http(uri) { |http| http.request(build_request(uri, body)) } handle_api_error!(response) unless response.is_a?(Net::HTTPSuccess) JSON.parse(response.body, symbolize_names: true) end
POSTs a JSON body to an API path and returns the parsed response hash. Raises Riffer::Error when the API responds with a non-success status.
Source
# File lib/riffer/providers/gemini/client.rb, line 62 def post_stream(path, body, &block) uri = URI("#{@base_url}/#{path}") start_http(uri) do |http| http.request(build_request(uri, body)) do |response| handle_api_error!(response) unless response.is_a?(Net::HTTPSuccess) begin response.read_body(&block) rescue IOError # A pre-buffered body (VCR/WebMock playback) raises IOError on a # streaming read; hand over the full body instead. yield(response.body) end end end end
POSTs a JSON body to an API path, yielding raw response body chunks as they arrive. Raises Riffer::Error when the API responds with a non-success status.