Module: OpenRouter::HTTP

Included in:
Client
Defined in:
lib/open_router/http.rb

Instance Method Summary collapse

Instance Method Details

#delete(path:) ⇒ Object



35
36
37
38
39
40
# File 'lib/open_router/http.rb', line 35

def delete(path:)
  response = conn.delete(uri(path:)) do |req|
    req.headers = headers
  end
  normalize_body(response&.body)
end

#get(path:) ⇒ Object



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

def get(path:)
  response = conn.get(uri(path:)) do |req|
    req.headers = headers
  end
  normalize_body(response&.body)
end

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



27
28
29
30
31
32
33
# File 'lib/open_router/http.rb', line 27

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

#post(path:, parameters:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/open_router/http.rb', line 14

def post(path:, parameters:)
  response = conn.post(uri(path:)) do |req|
    if parameters[:stream].respond_to?(:call)
      req.options.on_data = to_json_stream(user_proc: parameters[:stream])
      parameters[:stream] = true # Necessary to tell OpenRouter to stream.
    end

    req.headers = headers
    req.body = parameters.to_json
  end
  normalize_body(response&.body)
end