Module: Anthropic::HTTP
Instance Method Summary collapse
-
#delete(path:) ⇒ Object
Unused - leave in until v1 since someone might be using it.
- #get(path:, parameters: nil) ⇒ Object
-
#json_post(path:, parameters: {}) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
-
#multipart_post(path:, parameters: nil) ⇒ Object
Unused - leave in until v1 since someone might be using it.
Methods included from HTTPHeaders
Instance Method Details
#delete(path:) ⇒ Object
Unused - leave in until v1 since someone might be using it.
47 48 49 50 51 |
# File 'lib/anthropic/http.rb', line 47 def delete(path:) to_json(conn.delete(uri(path: path)) do |req| req.headers = headers end&.body) end |
#get(path:, parameters: nil) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/anthropic/http.rb', line 10 def get(path:, parameters: nil) response = conn.get(uri(path: path), parameters) do |req| req.headers = headers end response&.body end |
#json_post(path:, parameters: {}) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/anthropic/http.rb', line 19 def json_post(path:, parameters: {}) str_resp = {} response = conn.post(uri(path: path)) do |req| if parameters.respond_to?(:key?) && parameters[:stream].is_a?(Proc) req..on_data = to_json_stream(user_proc: parameters[:stream], response: str_resp, preprocess: parameters[:preprocess_stream]) parameters[:stream] = true # Necessary to tell Anthropic to stream. parameters.delete(:preprocess_stream) end req.headers = headers req.body = parameters.to_json end str_resp.empty? ? response.body : str_resp end |
#multipart_post(path:, parameters: nil) ⇒ Object
Unused - leave in until v1 since someone might be using it.
39 40 41 42 43 44 |
# File 'lib/anthropic/http.rb', line 39 def multipart_post(path:, parameters: nil) to_json(conn(multipart: true).post(uri(path: path)) do |req| req.headers = headers.merge({ "Content-Type" => "multipart/form-data" }) req.body = multipart_parameters(parameters) end&.body) end |