Class: Tavus::Resources::Objectives
- Inherits:
-
Object
- Object
- Tavus::Resources::Objectives
- Defined in:
- lib/tavus/resources/objectives.rb
Instance Method Summary collapse
-
#build_patch_operation(field, value, operation: "replace") ⇒ Hash
Helper method to build patch operations.
-
#create(data:) ⇒ Hash
Create new objectives.
-
#delete(objectives_id) ⇒ Hash
Delete an objective.
-
#get(objectives_id) ⇒ Hash
Get a single objective by ID.
-
#initialize(client) ⇒ Objectives
constructor
A new instance of Objectives.
-
#list(**options) ⇒ Hash
List all objectives.
-
#patch(objectives_id, operations) ⇒ Hash
Update an objective using JSON Patch operations.
-
#update_field(objectives_id, field, value) ⇒ Hash
Convenient method to update a field.
Constructor Details
#initialize(client) ⇒ Objectives
Returns a new instance of Objectives.
6 7 8 |
# File 'lib/tavus/resources/objectives.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#build_patch_operation(field, value, operation: "replace") ⇒ Hash
Helper method to build patch operations
63 64 65 66 67 |
# File 'lib/tavus/resources/objectives.rb', line 63 def build_patch_operation(field, value, operation: "replace") op = { op: operation, path: field } op[:value] = value unless operation == "remove" op end |
#create(data:) ⇒ Hash
Create new objectives
13 14 15 16 17 18 |
# File 'lib/tavus/resources/objectives.rb', line 13 def create(data:) raise ArgumentError, "data must be an array" unless data.is_a?(Array) raise ArgumentError, "data cannot be empty" if data.empty? @client.post("/v2/objectives", body: { data: data }) end |
#delete(objectives_id) ⇒ Hash
Delete an objective
82 83 84 |
# File 'lib/tavus/resources/objectives.rb', line 82 def delete(objectives_id) @client.delete("/v2/objectives/#{objectives_id}") end |
#get(objectives_id) ⇒ Hash
Get a single objective by ID
23 24 25 |
# File 'lib/tavus/resources/objectives.rb', line 23 def get(objectives_id) @client.get("/v2/objectives/#{objectives_id}") end |
#list(**options) ⇒ Hash
List all objectives
32 33 34 |
# File 'lib/tavus/resources/objectives.rb', line 32 def list(**) @client.get("/v2/objectives", params: ) end |
#patch(objectives_id, operations) ⇒ Hash
Update an objective using JSON Patch operations
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tavus/resources/objectives.rb', line 46 def patch(objectives_id, operations) raise ArgumentError, "Operations must be an array" unless operations.is_a?(Array) raise ArgumentError, "Operations cannot be empty" if operations.empty? operations.each do |op| raise ArgumentError, "Each operation must have 'op' and 'path'" unless op[:op] && op[:path] raise ArgumentError, "Operation 'op' must be one of: add, remove, replace, copy, move, test" unless %w[add remove replace copy move test].include?(op[:op]) end @client.patch("/v2/objectives/#{objectives_id}", body: operations) end |
#update_field(objectives_id, field, value) ⇒ Hash
Convenient method to update a field
74 75 76 77 |
# File 'lib/tavus/resources/objectives.rb', line 74 def update_field(objectives_id, field, value) operation = build_patch_operation(field, value, operation: "replace") patch(objectives_id, [operation]) end |