Class: Braintrust::API::Internal::Projects
- Inherits:
-
Object
- Object
- Braintrust::API::Internal::Projects
- Defined in:
- lib/braintrust/api/internal/projects.rb
Overview
Internal Projects API Not part of the public API - use through Eval.run
Instance Method Summary collapse
-
#create(name:) ⇒ Hash
Create or get a project by name (idempotent) POST /v1/project.
-
#delete(id:) ⇒ Hash
Delete a project DELETE /v1/project/:id.
-
#initialize(state) ⇒ Projects
constructor
A new instance of Projects.
Constructor Details
#initialize(state) ⇒ Projects
Returns a new instance of Projects.
14 15 16 |
# File 'lib/braintrust/api/internal/projects.rb', line 14 def initialize(state) @state = state end |
Instance Method Details
#create(name:) ⇒ Hash
Create or get a project by name (idempotent) POST /v1/project
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/braintrust/api/internal/projects.rb', line 22 def create(name:) uri = URI("#{@state.api_url}/v1/project") request = Net::HTTP::Post.new(uri) request["Content-Type"] = "application/json" request["Authorization"] = "Bearer #{@state.api_key}" request.body = JSON.dump({name: name}) response = Braintrust::Internal::Http.with_redirects(uri, request) unless response.is_a?(Net::HTTPSuccess) raise Error, "HTTP #{response.code} for POST #{uri}: #{response.body}" end JSON.parse(response.body) end |
#delete(id:) ⇒ Hash
Delete a project DELETE /v1/project/:id
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/braintrust/api/internal/projects.rb', line 43 def delete(id:) uri = URI("#{@state.api_url}/v1/project/#{id}") request = Net::HTTP::Delete.new(uri) request["Authorization"] = "Bearer #{@state.api_key}" response = Braintrust::Internal::Http.with_redirects(uri, request) unless response.is_a?(Net::HTTPSuccess) raise Error, "HTTP #{response.code} for DELETE #{uri}: #{response.body}" end JSON.parse(response.body) end |