Class: Vapi::VariableExtractionPlan
- Inherits:
-
Object
- Object
- Vapi::VariableExtractionPlan
- Defined in:
- lib/vapi_server_sdk/types/variable_extraction_plan.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#aliases ⇒ Array<Vapi::VariableExtractionAlias>
readonly
These are additional variables to create.
-
#schema ⇒ Vapi::JsonSchema
readonly
This is the schema to extract.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Vapi::VariableExtractionPlan
Deserialize a JSON object to an instance of VariableExtractionPlan.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(schema: OMIT, aliases: OMIT, additional_properties: nil) ⇒ Vapi::VariableExtractionPlan constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of VariableExtractionPlan to a JSON object.
Constructor Details
#initialize(schema: OMIT, aliases: OMIT, additional_properties: nil) ⇒ Vapi::VariableExtractionPlan
246 247 248 249 250 251 252 253 |
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 246 def initialize(schema: OMIT, aliases: OMIT, additional_properties: nil) @schema = schema if schema != OMIT @aliases = aliases if aliases != OMIT @additional_properties = additional_properties @_field_set = { "schema": schema, "aliases": aliases }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
125 126 127 |
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 125 def additional_properties @additional_properties end |
#aliases ⇒ Array<Vapi::VariableExtractionAlias> (readonly)
Returns These are additional variables to create. These will be accessible during the call as ‘{key}` and stored in `call.artifact.variableValues` after the call. Example: “`json { “aliases”: [ { “key”: “customerName”, “value”: “{name}” }, { “key”: “fullName”, “value”: “{firstName} {lastName}” }, { “key”: “greeting”, “value”: “Hello {name}, welcome to {company}!” }, { “key”: “customerEmail”, “value”: “href="0">addresses.city}” }, { “key”: “something”, “value”: “liquid}” } ] } “` This will create variables `customerName`, `fullName`, `customerEmail`, `greeting`, and `something`. To access these variables, you can reference them as `{customerName}`, `{fullName}`, `{customerEmail}`, `{greeting}`, and `{something}`.
123 124 125 |
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 123 def aliases @aliases end |
#schema ⇒ Vapi::JsonSchema (readonly)
Returns This is the schema to extract. Examples:
-
To extract object properties, you can use the following schema:
“‘json { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” } } } “` These will be extracted as `name }` and `age }` respectively. To emphasize, object properties are extracted as direct global variables.
-
To extract nested properties, you can use the following schema:
“‘json { “type”: “object”, “properties”: { “name”: { “type”: “object”, “properties”: { “first”: { “type”: “string” }, “last”: { “type”: “string” } } } } } “` These will be extracted as `name }`. And, `name.first }` and `name.last }` will be accessible.
-
To extract array items, you can use the following schema:
“‘json { “type”: “array”, “title”: “zipCodes”, “items”: { “type”: “string” } } “` This will be extracted as `zipCodes }`. To access the array items, you can use `zipCodes }` and `zipCodes }`.
-
To extract array of objects, you can use the following schema:
“‘json { “type”: “array”, “name”: “people”, “items”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” }, “zipCodes”: { “type”: “array”, “items”: { “type”: “string” } } } } } “` This will be extracted as `people }`. To access the array items, you can use `people.name }`, `people.age }`, `people.zipCodes }`, `people.zipCodes }` and `people.zipCodes }`.
88 89 90 |
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 88 def schema @schema end |
Class Method Details
.from_json(json_object:) ⇒ Vapi::VariableExtractionPlan
Deserialize a JSON object to an instance of VariableExtractionPlan
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 259 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) if parsed_json["schema"].nil? schema = nil else schema = parsed_json["schema"].to_json schema = Vapi::JsonSchema.from_json(json_object: schema) end aliases = parsed_json["aliases"]&.map do |item| item = item.to_json Vapi::VariableExtractionAlias.from_json(json_object: item) end new( schema: schema, aliases: aliases, additional_properties: struct ) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given
hash and check each fields type against the current object's property
definitions.
292 293 294 295 |
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 292 def self.validate_raw(obj:) obj.schema.nil? || Vapi::JsonSchema.validate_raw(obj: obj.schema) obj.aliases&.is_a?(Array) != false || raise("Passed value for field obj.aliases is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of VariableExtractionPlan to a JSON object
282 283 284 |
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 282 def to_json(*_args) @_field_set&.to_json end |