intrinsic-sdk 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c046c7d01d3d5d678745df42b07fd00ccd78c3219bee86416c8c6a44457f95a9
4
+ data.tar.gz: 3fac940db16e92f716ab2f64ebc9638ed7f0866cf0a1d627d7d63be996b10ee0
5
+ SHA512:
6
+ metadata.gz: 9c4a4a5813da9bce1acaf7fdf6075b38264e0ac9cc815cd1a09f29332678f022afbdc0ebdf01401a1657c66fb5b0d0f0b0c517f7b11f9928a0ff544d2793c7cc
7
+ data.tar.gz: 1577d898e504a9df265f15b17288a18092bdbfd192397ea0f20aaea4f3bef78a652974ee9f648fe2f81e1c7a2bac19534852c3750186e9f6d69f492f6f546cf3
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Intrinsic
4
+ class Environment
5
+ DEFAULT = "https://intrinsicapi.com"
6
+ end
7
+ end
data/lib/gemconfig.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Intrinsic
4
+ module Gemconfig
5
+ VERSION = ""
6
+ AUTHORS = [""].freeze
7
+ EMAIL = ""
8
+ SUMMARY = ""
9
+ DESCRIPTION = ""
10
+ HOMEPAGE = "https://github.com/fern-demo/intrinsic-ruby"
11
+ SOURCE_CODE_URI = "https://github.com/fern-demo/intrinsic-ruby"
12
+ CHANGELOG_URI = "https://github.com/fern-demo/intrinsic-ruby/blob/master/CHANGELOG.md"
13
+ end
14
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../requests"
4
+ require_relative "../types/detection_object"
5
+ require "async"
6
+
7
+ module Intrinsic
8
+ class DetectionsClient
9
+ attr_reader :request_client
10
+
11
+ # @param request_client [RequestClient]
12
+ # @return [DetectionsClient]
13
+ def initialize(request_client:)
14
+ # @type [RequestClient]
15
+ @request_client = request_client
16
+ end
17
+
18
+ # @param id [String] Detection ID
19
+ # @param request_options [RequestOptions]
20
+ # @return [DetectionObject]
21
+ def get_detection(id:, request_options: nil)
22
+ response = @request_client.conn.get("/api/v2/detections/#{id}") do |req|
23
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
24
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
25
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
26
+ end
27
+ DetectionObject.from_json(json_object: response.body)
28
+ end
29
+ end
30
+
31
+ class AsyncDetectionsClient
32
+ attr_reader :request_client
33
+
34
+ # @param request_client [AsyncRequestClient]
35
+ # @return [AsyncDetectionsClient]
36
+ def initialize(request_client:)
37
+ # @type [AsyncRequestClient]
38
+ @request_client = request_client
39
+ end
40
+
41
+ # @param id [String] Detection ID
42
+ # @param request_options [RequestOptions]
43
+ # @return [DetectionObject]
44
+ def get_detection(id:, request_options: nil)
45
+ Async do
46
+ response = @request_client.conn.get("/api/v2/detections/#{id}") do |req|
47
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
48
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
49
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
50
+ end
51
+ DetectionObject.from_json(json_object: response.body)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../requests"
4
+ require_relative "../types/list_event_types_response"
5
+ require_relative "../types/event_type_field"
6
+ require_relative "../types/event_type_object"
7
+ require "async"
8
+
9
+ module Intrinsic
10
+ class EventTypesClient
11
+ attr_reader :request_client
12
+
13
+ # @param request_client [RequestClient]
14
+ # @return [EventTypesClient]
15
+ def initialize(request_client:)
16
+ # @type [RequestClient]
17
+ @request_client = request_client
18
+ end
19
+
20
+ # @param request_options [RequestOptions]
21
+ # @return [ListEventTypesResponse]
22
+ def get_event_types(request_options: nil)
23
+ response = @request_client.conn.get("/api/v2/event-types") do |req|
24
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
25
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
26
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
27
+ end
28
+ ListEventTypesResponse.from_json(json_object: response.body)
29
+ end
30
+
31
+ # @param name [String] Name of the event type to create.
32
+ # @param fields [Array<Hash>] Fields of the event typeRequest of type Array<EventTypeField>, as a Hash
33
+ # * :field_name (String)
34
+ # * :type (EVENT_TYPE_FIELD_TYPE)
35
+ # * :optional (Boolean)
36
+ # @param request_options [RequestOptions]
37
+ # @return [EventTypeObject]
38
+ def create_event_type(name:, fields:, request_options: nil)
39
+ response = @request_client.conn.post("/api/v2/event-types") do |req|
40
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
41
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
42
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
43
+ req.body = { **(request_options&.additional_body_parameters || {}), name: name, fields: fields }.compact
44
+ end
45
+ EventTypeObject.from_json(json_object: response.body)
46
+ end
47
+ end
48
+
49
+ class AsyncEventTypesClient
50
+ attr_reader :request_client
51
+
52
+ # @param request_client [AsyncRequestClient]
53
+ # @return [AsyncEventTypesClient]
54
+ def initialize(request_client:)
55
+ # @type [AsyncRequestClient]
56
+ @request_client = request_client
57
+ end
58
+
59
+ # @param request_options [RequestOptions]
60
+ # @return [ListEventTypesResponse]
61
+ def get_event_types(request_options: nil)
62
+ Async do
63
+ response = @request_client.conn.get("/api/v2/event-types") do |req|
64
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
65
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
66
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
67
+ end
68
+ ListEventTypesResponse.from_json(json_object: response.body)
69
+ end
70
+ end
71
+
72
+ # @param name [String] Name of the event type to create.
73
+ # @param fields [Array<Hash>] Fields of the event typeRequest of type Array<EventTypeField>, as a Hash
74
+ # * :field_name (String)
75
+ # * :type (EVENT_TYPE_FIELD_TYPE)
76
+ # * :optional (Boolean)
77
+ # @param request_options [RequestOptions]
78
+ # @return [EventTypeObject]
79
+ def create_event_type(name:, fields:, request_options: nil)
80
+ Async do
81
+ response = @request_client.conn.post("/api/v2/event-types") do |req|
82
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
83
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
84
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
85
+ req.body = { **(request_options&.additional_body_parameters || {}), name: name, fields: fields }.compact
86
+ end
87
+ EventTypeObject.from_json(json_object: response.body)
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../requests"
4
+ require_relative "../types/create_event_sync_request"
5
+ require_relative "../types/create_event_sync_response"
6
+ require_relative "../types/create_event_async_request"
7
+ require_relative "../types/create_event_async_response"
8
+ require "async"
9
+
10
+ module Intrinsic
11
+ class EventsClient
12
+ attr_reader :request_client
13
+
14
+ # @param request_client [RequestClient]
15
+ # @return [EventsClient]
16
+ def initialize(request_client:)
17
+ # @type [RequestClient]
18
+ @request_client = request_client
19
+ end
20
+
21
+ # Creates an event in a synchronous, blocking matter. Note for long-running tasks, the Asynchronous API is recommended instead. Returns an ID for the event created as well as the set of detections that were run.
22
+ #
23
+ # @param event_type_name [String] The type of event being created. To create an event type, see the event types API.
24
+ # @param request [CREATE_EVENT_SYNC_REQUEST]
25
+ # @param request_options [RequestOptions]
26
+ # @return [CreateEventSyncResponse]
27
+ def create_event_sync(event_type_name:, request:, request_options: nil)
28
+ response = @request_client.conn.post("/api/v2/events/sync/#{event_type_name}") do |req|
29
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
30
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
31
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
32
+ req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
33
+ end
34
+ CreateEventSyncResponse.from_json(json_object: response.body)
35
+ end
36
+
37
+ # Creates an event in an asynchronous manner. Returns an ID for the event created as well as the set of detection ids associated with the event.
38
+ #
39
+ # @param event_type_name [String] The type of event being created. To create an event type, see the event types API.
40
+ # @param request [CREATE_EVENT_ASYNC_REQUEST]
41
+ # @param request_options [RequestOptions]
42
+ # @return [CreateEventAsyncResponse]
43
+ def create_event_async(event_type_name:, request:, request_options: nil)
44
+ response = @request_client.conn.post("/api/v2/events/async/#{event_type_name}") do |req|
45
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
46
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
47
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
48
+ req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
49
+ end
50
+ CreateEventAsyncResponse.from_json(json_object: response.body)
51
+ end
52
+ end
53
+
54
+ class AsyncEventsClient
55
+ attr_reader :request_client
56
+
57
+ # @param request_client [AsyncRequestClient]
58
+ # @return [AsyncEventsClient]
59
+ def initialize(request_client:)
60
+ # @type [AsyncRequestClient]
61
+ @request_client = request_client
62
+ end
63
+
64
+ # Creates an event in a synchronous, blocking matter. Note for long-running tasks, the Asynchronous API is recommended instead. Returns an ID for the event created as well as the set of detections that were run.
65
+ #
66
+ # @param event_type_name [String] The type of event being created. To create an event type, see the event types API.
67
+ # @param request [CREATE_EVENT_SYNC_REQUEST]
68
+ # @param request_options [RequestOptions]
69
+ # @return [CreateEventSyncResponse]
70
+ def create_event_sync(event_type_name:, request:, request_options: nil)
71
+ Async do
72
+ response = @request_client.conn.post("/api/v2/events/sync/#{event_type_name}") do |req|
73
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
74
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
75
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
76
+ req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
77
+ end
78
+ CreateEventSyncResponse.from_json(json_object: response.body)
79
+ end
80
+ end
81
+
82
+ # Creates an event in an asynchronous manner. Returns an ID for the event created as well as the set of detection ids associated with the event.
83
+ #
84
+ # @param event_type_name [String] The type of event being created. To create an event type, see the event types API.
85
+ # @param request [CREATE_EVENT_ASYNC_REQUEST]
86
+ # @param request_options [RequestOptions]
87
+ # @return [CreateEventAsyncResponse]
88
+ def create_event_async(event_type_name:, request:, request_options: nil)
89
+ Async do
90
+ response = @request_client.conn.post("/api/v2/events/async/#{event_type_name}") do |req|
91
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
92
+ req.headers["X-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
93
+ req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
94
+ req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
95
+ end
96
+ CreateEventAsyncResponse.from_json(json_object: response.body)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Intrinsic
4
+ CREATE_EVENT_ASYNC_REQUEST = Hash
5
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require_relative "detection_object"
5
+ require_relative "fired_rule_object"
6
+ require "json"
7
+
8
+ module Intrinsic
9
+ class CreateEventAsyncResponse
10
+ attr_reader :object, :id, :event_type_id, :content, :created_at, :detections, :fired_rules, :additional_properties
11
+
12
+ # @param object [String]
13
+ # @param id [String] ID of the created event
14
+ # @param event_type_id [String] ID of the event type that was created
15
+ # @param content [Hash{String => String}] Arbitrary JSON payload for the request body
16
+ # @param created_at [DateTime] Timestamp of when the event was created
17
+ # @param detections [Array<DetectionObject>] List of pending detection ids created for the event
18
+ # @param fired_rules [Array<FiredRuleObject>] List of fired rules created for the event
19
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
20
+ # @return [CreateEventAsyncResponse]
21
+ def initialize(object:, id:, event_type_id:, content:, created_at:, detections:, fired_rules:,
22
+ additional_properties: nil)
23
+ # @type [String]
24
+ @object = object
25
+ # @type [String] ID of the created event
26
+ @id = id
27
+ # @type [String] ID of the event type that was created
28
+ @event_type_id = event_type_id
29
+ # @type [Hash{String => String}] Arbitrary JSON payload for the request body
30
+ @content = content
31
+ # @type [DateTime] Timestamp of when the event was created
32
+ @created_at = created_at
33
+ # @type [Array<DetectionObject>] List of pending detection ids created for the event
34
+ @detections = detections
35
+ # @type [Array<FiredRuleObject>] List of fired rules created for the event
36
+ @fired_rules = fired_rules
37
+ # @type [OpenStruct] Additional properties unmapped to the current class definition
38
+ @additional_properties = additional_properties
39
+ end
40
+
41
+ # Deserialize a JSON object to an instance of CreateEventAsyncResponse
42
+ #
43
+ # @param json_object [JSON]
44
+ # @return [CreateEventAsyncResponse]
45
+ def self.from_json(json_object:)
46
+ struct = JSON.parse(json_object, object_class: OpenStruct)
47
+ parsed_json = JSON.parse(json_object)
48
+ object = struct.object
49
+ id = struct.id
50
+ event_type_id = struct.event_type_id
51
+ content = struct.content
52
+ created_at = (DateTime.parse(parsed_json["created_at"]) unless parsed_json["created_at"].nil?)
53
+ detections = parsed_json["detections"]&.map do |v|
54
+ v = v.to_json
55
+ DetectionObject.from_json(json_object: v)
56
+ end
57
+ fired_rules = parsed_json["fired_rules"]&.map do |v|
58
+ v = v.to_json
59
+ FiredRuleObject.from_json(json_object: v)
60
+ end
61
+ new(object: object, id: id, event_type_id: event_type_id, content: content, created_at: created_at,
62
+ detections: detections, fired_rules: fired_rules, additional_properties: struct)
63
+ end
64
+
65
+ # Serialize an instance of CreateEventAsyncResponse to a JSON object
66
+ #
67
+ # @return [JSON]
68
+ def to_json(*_args)
69
+ {
70
+ "object": @object,
71
+ "id": @id,
72
+ "event_type_id": @event_type_id,
73
+ "content": @content,
74
+ "created_at": @created_at,
75
+ "detections": @detections,
76
+ "fired_rules": @fired_rules
77
+ }.to_json
78
+ end
79
+
80
+ # 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.
81
+ #
82
+ # @param obj [Object]
83
+ # @return [Void]
84
+ def self.validate_raw(obj:)
85
+ obj.object.is_a?(String) != false || raise("Passed value for field obj.object is not the expected type, validation failed.")
86
+ obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
87
+ obj.event_type_id.is_a?(String) != false || raise("Passed value for field obj.event_type_id is not the expected type, validation failed.")
88
+ obj.content.is_a?(Hash) != false || raise("Passed value for field obj.content is not the expected type, validation failed.")
89
+ obj.created_at.is_a?(DateTime) != false || raise("Passed value for field obj.created_at is not the expected type, validation failed.")
90
+ obj.detections.is_a?(Array) != false || raise("Passed value for field obj.detections is not the expected type, validation failed.")
91
+ obj.fired_rules.is_a?(Array) != false || raise("Passed value for field obj.fired_rules is not the expected type, validation failed.")
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Intrinsic
4
+ CREATE_EVENT_SYNC_REQUEST = Hash
5
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require_relative "detection_object"
5
+ require_relative "fired_rule_object"
6
+ require "json"
7
+
8
+ module Intrinsic
9
+ class CreateEventSyncResponse
10
+ attr_reader :object, :id, :event_type_id, :content, :created_at, :detections, :fired_rules, :additional_properties
11
+
12
+ # @param object [String]
13
+ # @param id [String] ID of the created event
14
+ # @param event_type_id [String] ID of the event type that was created
15
+ # @param content [Hash{String => String}] Arbitrary JSON payload for the request body
16
+ # @param created_at [DateTime] Timestamp of when the event was created
17
+ # @param detections [Array<DetectionObject>] List of detections created for the event
18
+ # @param fired_rules [Array<FiredRuleObject>] List of fired rules created for the event
19
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
20
+ # @return [CreateEventSyncResponse]
21
+ def initialize(object:, id:, event_type_id:, content:, created_at:, detections:, fired_rules:,
22
+ additional_properties: nil)
23
+ # @type [String]
24
+ @object = object
25
+ # @type [String] ID of the created event
26
+ @id = id
27
+ # @type [String] ID of the event type that was created
28
+ @event_type_id = event_type_id
29
+ # @type [Hash{String => String}] Arbitrary JSON payload for the request body
30
+ @content = content
31
+ # @type [DateTime] Timestamp of when the event was created
32
+ @created_at = created_at
33
+ # @type [Array<DetectionObject>] List of detections created for the event
34
+ @detections = detections
35
+ # @type [Array<FiredRuleObject>] List of fired rules created for the event
36
+ @fired_rules = fired_rules
37
+ # @type [OpenStruct] Additional properties unmapped to the current class definition
38
+ @additional_properties = additional_properties
39
+ end
40
+
41
+ # Deserialize a JSON object to an instance of CreateEventSyncResponse
42
+ #
43
+ # @param json_object [JSON]
44
+ # @return [CreateEventSyncResponse]
45
+ def self.from_json(json_object:)
46
+ struct = JSON.parse(json_object, object_class: OpenStruct)
47
+ parsed_json = JSON.parse(json_object)
48
+ object = struct.object
49
+ id = struct.id
50
+ event_type_id = struct.event_type_id
51
+ content = struct.content
52
+ created_at = (DateTime.parse(parsed_json["created_at"]) unless parsed_json["created_at"].nil?)
53
+ detections = parsed_json["detections"]&.map do |v|
54
+ v = v.to_json
55
+ DetectionObject.from_json(json_object: v)
56
+ end
57
+ fired_rules = parsed_json["fired_rules"]&.map do |v|
58
+ v = v.to_json
59
+ FiredRuleObject.from_json(json_object: v)
60
+ end
61
+ new(object: object, id: id, event_type_id: event_type_id, content: content, created_at: created_at,
62
+ detections: detections, fired_rules: fired_rules, additional_properties: struct)
63
+ end
64
+
65
+ # Serialize an instance of CreateEventSyncResponse to a JSON object
66
+ #
67
+ # @return [JSON]
68
+ def to_json(*_args)
69
+ {
70
+ "object": @object,
71
+ "id": @id,
72
+ "event_type_id": @event_type_id,
73
+ "content": @content,
74
+ "created_at": @created_at,
75
+ "detections": @detections,
76
+ "fired_rules": @fired_rules
77
+ }.to_json
78
+ end
79
+
80
+ # 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.
81
+ #
82
+ # @param obj [Object]
83
+ # @return [Void]
84
+ def self.validate_raw(obj:)
85
+ obj.object.is_a?(String) != false || raise("Passed value for field obj.object is not the expected type, validation failed.")
86
+ obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
87
+ obj.event_type_id.is_a?(String) != false || raise("Passed value for field obj.event_type_id is not the expected type, validation failed.")
88
+ obj.content.is_a?(Hash) != false || raise("Passed value for field obj.content is not the expected type, validation failed.")
89
+ obj.created_at.is_a?(DateTime) != false || raise("Passed value for field obj.created_at is not the expected type, validation failed.")
90
+ obj.detections.is_a?(Array) != false || raise("Passed value for field obj.detections is not the expected type, validation failed.")
91
+ obj.fired_rules.is_a?(Array) != false || raise("Passed value for field obj.fired_rules is not the expected type, validation failed.")
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "detection_object_status"
4
+ require_relative "violated_policy_object"
5
+ require "json"
6
+
7
+ module Intrinsic
8
+ class DetectionObject
9
+ attr_reader :object, :id, :event_id, :status, :violates_policy, :violated_policies, :explanation,
10
+ :additional_properties
11
+
12
+ # @param object [String]
13
+ # @param id [String] ID of the detection
14
+ # @param event_id [String] ID of the event associated with a detection
15
+ # @param status [DETECTION_OBJECT_STATUS]
16
+ # @param violates_policy [Boolean] Whether any policies were violated
17
+ # @param violated_policies [Array<ViolatedPolicyObject>]
18
+ # @param explanation [String] Explanation of the detection outcome
19
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
20
+ # @return [DetectionObject]
21
+ def initialize(object:, event_id:, status:, id: nil, violates_policy: nil, violated_policies: nil,
22
+ explanation: nil, additional_properties: nil)
23
+ # @type [String]
24
+ @object = object
25
+ # @type [String] ID of the detection
26
+ @id = id
27
+ # @type [String] ID of the event associated with a detection
28
+ @event_id = event_id
29
+ # @type [DETECTION_OBJECT_STATUS]
30
+ @status = status
31
+ # @type [Boolean] Whether any policies were violated
32
+ @violates_policy = violates_policy
33
+ # @type [Array<ViolatedPolicyObject>]
34
+ @violated_policies = violated_policies
35
+ # @type [String] Explanation of the detection outcome
36
+ @explanation = explanation
37
+ # @type [OpenStruct] Additional properties unmapped to the current class definition
38
+ @additional_properties = additional_properties
39
+ end
40
+
41
+ # Deserialize a JSON object to an instance of DetectionObject
42
+ #
43
+ # @param json_object [JSON]
44
+ # @return [DetectionObject]
45
+ def self.from_json(json_object:)
46
+ struct = JSON.parse(json_object, object_class: OpenStruct)
47
+ parsed_json = JSON.parse(json_object)
48
+ object = struct.object
49
+ id = struct.id
50
+ event_id = struct.event_id
51
+ status = DETECTION_OBJECT_STATUS.key(parsed_json["status"]) || parsed_json["status"]
52
+ violates_policy = struct.violates_policy
53
+ violated_policies = parsed_json["violated_policies"]&.map do |v|
54
+ v = v.to_json
55
+ ViolatedPolicyObject.from_json(json_object: v)
56
+ end
57
+ explanation = struct.explanation
58
+ new(object: object, id: id, event_id: event_id, status: status, violates_policy: violates_policy,
59
+ violated_policies: violated_policies, explanation: explanation, additional_properties: struct)
60
+ end
61
+
62
+ # Serialize an instance of DetectionObject to a JSON object
63
+ #
64
+ # @return [JSON]
65
+ def to_json(*_args)
66
+ {
67
+ "object": @object,
68
+ "id": @id,
69
+ "event_id": @event_id,
70
+ "status": DETECTION_OBJECT_STATUS[@status] || @status,
71
+ "violates_policy": @violates_policy,
72
+ "violated_policies": @violated_policies,
73
+ "explanation": @explanation
74
+ }.to_json
75
+ end
76
+
77
+ # 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.
78
+ #
79
+ # @param obj [Object]
80
+ # @return [Void]
81
+ def self.validate_raw(obj:)
82
+ obj.object.is_a?(String) != false || raise("Passed value for field obj.object is not the expected type, validation failed.")
83
+ obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
84
+ obj.event_id.is_a?(String) != false || raise("Passed value for field obj.event_id is not the expected type, validation failed.")
85
+ obj.status.is_a?(DETECTION_OBJECT_STATUS) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
86
+ obj.violates_policy&.is_a?(Boolean) != false || raise("Passed value for field obj.violates_policy is not the expected type, validation failed.")
87
+ obj.violated_policies&.is_a?(Array) != false || raise("Passed value for field obj.violated_policies is not the expected type, validation failed.")
88
+ obj.explanation&.is_a?(String) != false || raise("Passed value for field obj.explanation is not the expected type, validation failed.")
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Intrinsic
4
+ # @type [DETECTION_OBJECT_STATUS]
5
+ DETECTION_OBJECT_STATUS = { pending: "PENDING", completed: "COMPLETED", failure: "FAILURE" }.freeze
6
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "error_schema_error"
4
+ require "json"
5
+
6
+ module Intrinsic
7
+ class ErrorSchema
8
+ attr_reader :error, :additional_properties
9
+
10
+ # @param error [ErrorSchemaError]
11
+ # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
12
+ # @return [ErrorSchema]
13
+ def initialize(error: nil, additional_properties: nil)
14
+ # @type [ErrorSchemaError]
15
+ @error = error
16
+ # @type [OpenStruct] Additional properties unmapped to the current class definition
17
+ @additional_properties = additional_properties
18
+ end
19
+
20
+ # Deserialize a JSON object to an instance of ErrorSchema
21
+ #
22
+ # @param json_object [JSON]
23
+ # @return [ErrorSchema]
24
+ def self.from_json(json_object:)
25
+ struct = JSON.parse(json_object, object_class: OpenStruct)
26
+ parsed_json = JSON.parse(json_object)
27
+ if parsed_json["error"].nil?
28
+ error = nil
29
+ else
30
+ error = parsed_json["error"].to_json
31
+ error = ErrorSchemaError.from_json(json_object: error)
32
+ end
33
+ new(error: error, additional_properties: struct)
34
+ end
35
+
36
+ # Serialize an instance of ErrorSchema to a JSON object
37
+ #
38
+ # @return [JSON]
39
+ def to_json(*_args)
40
+ { "error": @error }.to_json
41
+ end
42
+
43
+ # 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.
44
+ #
45
+ # @param obj [Object]
46
+ # @return [Void]
47
+ def self.validate_raw(obj:)
48
+ obj.error.nil? || ErrorSchemaError.validate_raw(obj: obj.error)
49
+ end
50
+ end
51
+ end