insion 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.md +21 -0
- data/README.md +172 -0
- data/changelog.md +4 -0
- data/lib/Insion/client.rb +404 -0
- data/lib/Insion/environment.rb +7 -0
- data/lib/Insion/errors/api_error.rb +8 -0
- data/lib/Insion/errors/client_error.rb +17 -0
- data/lib/Insion/errors/redirect_error.rb +8 -0
- data/lib/Insion/errors/response_error.rb +42 -0
- data/lib/Insion/errors/server_error.rb +11 -0
- data/lib/Insion/errors/timeout_error.rb +8 -0
- data/lib/Insion/internal/errors/constraint_error.rb +10 -0
- data/lib/Insion/internal/errors/type_error.rb +10 -0
- data/lib/Insion/internal/http/base_request.rb +51 -0
- data/lib/Insion/internal/http/raw_client.rb +248 -0
- data/lib/Insion/internal/iterators/cursor_item_iterator.rb +28 -0
- data/lib/Insion/internal/iterators/cursor_page_iterator.rb +63 -0
- data/lib/Insion/internal/iterators/item_iterator.rb +65 -0
- data/lib/Insion/internal/iterators/offset_item_iterator.rb +30 -0
- data/lib/Insion/internal/iterators/offset_page_iterator.rb +103 -0
- data/lib/Insion/internal/json/request.rb +41 -0
- data/lib/Insion/internal/json/serializable.rb +25 -0
- data/lib/Insion/internal/multipart/multipart_encoder.rb +141 -0
- data/lib/Insion/internal/multipart/multipart_form_data.rb +78 -0
- data/lib/Insion/internal/multipart/multipart_form_data_part.rb +51 -0
- data/lib/Insion/internal/multipart/multipart_request.rb +40 -0
- data/lib/Insion/internal/types/array.rb +47 -0
- data/lib/Insion/internal/types/boolean.rb +34 -0
- data/lib/Insion/internal/types/enum.rb +56 -0
- data/lib/Insion/internal/types/hash.rb +36 -0
- data/lib/Insion/internal/types/model/field.rb +38 -0
- data/lib/Insion/internal/types/model.rb +208 -0
- data/lib/Insion/internal/types/type.rb +35 -0
- data/lib/Insion/internal/types/union.rb +161 -0
- data/lib/Insion/internal/types/unknown.rb +15 -0
- data/lib/Insion/internal/types/utils.rb +116 -0
- data/lib/Insion/types/content.rb +13 -0
- data/lib/Insion/types/content_external_urls.rb +13 -0
- data/lib/Insion/types/create_appeal_response.rb +9 -0
- data/lib/Insion/types/create_appeal_response_data.rb +19 -0
- data/lib/Insion/types/create_appeal_response_data_action_status.rb +13 -0
- data/lib/Insion/types/delete_api_v1ingest_request.rb +9 -0
- data/lib/Insion/types/error_response.rb +9 -0
- data/lib/Insion/types/error_response_error.rb +9 -0
- data/lib/Insion/types/get_api_v1records_record_id_request.rb +9 -0
- data/lib/Insion/types/get_api_v1records_request.rb +21 -0
- data/lib/Insion/types/get_api_v1records_request_status.rb +12 -0
- data/lib/Insion/types/get_api_v1users_request.rb +21 -0
- data/lib/Insion/types/get_api_v1users_request_status.rb +13 -0
- data/lib/Insion/types/get_api_v1users_user_id_request.rb +9 -0
- data/lib/Insion/types/ingest_record_request.rb +23 -0
- data/lib/Insion/types/ingest_record_response.rb +15 -0
- data/lib/Insion/types/ingest_user_response.rb +11 -0
- data/lib/Insion/types/list_records_response.rb +11 -0
- data/lib/Insion/types/list_users_response.rb +11 -0
- data/lib/Insion/types/metadata.rb +23 -0
- data/lib/Insion/types/moderate_request.rb +23 -0
- data/lib/Insion/types/moderate_response.rb +21 -0
- data/lib/Insion/types/moderate_response_status.rb +12 -0
- data/lib/Insion/types/post_api_v1users_user_id_create_appeal_request.rb +11 -0
- data/lib/Insion/types/record.rb +35 -0
- data/lib/Insion/types/record_input.rb +21 -0
- data/lib/Insion/types/record_moderation_status.rb +12 -0
- data/lib/Insion/types/record_response.rb +9 -0
- data/lib/Insion/types/success_response.rb +9 -0
- data/lib/Insion/types/user.rb +33 -0
- data/lib/Insion/types/user_action_status.rb +13 -0
- data/lib/Insion/types/user_input.rb +23 -0
- data/lib/Insion/types/user_response.rb +9 -0
- data/lib/Insion/version.rb +5 -0
- data/lib/Insion.rb +72 -0
- data/lib/insion.rb +4 -0
- data/reference.md +676 -0
- metadata +121 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 58f1b1643f098dbdd6b3ddfeccabc56390e1b68d4be312f14b2ae527c1d49c6e
|
|
4
|
+
data.tar.gz: 3458f14402789bb47e7cf75b61768c2da8d44cb35800572ca61b16513e4a47a1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3f10319da44058b286b19c46e0bcbda2e48a50ea524182f44de0f474b3996266b4d36a864be8bb737b329f2fc4f4aa5281709e7dda8d05b4b13a6e34fa136681
|
|
7
|
+
data.tar.gz: eddecbc7b2858ee70c63ec6d81745d1f80e287a4c99dd5f8b0921cb8d1eeae6ddc355bb81ee177aaf97dff73ed682a430b3b4b1b91b2faba4d40382fe45d1ed2
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Insion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Insion Ruby Library
|
|
2
|
+
|
|
3
|
+
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=Insion%2FRuby)
|
|
4
|
+
|
|
5
|
+
The Insion Ruby library provides convenient access to the Insion APIs from Ruby.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Reference](#reference)
|
|
10
|
+
- [Usage](#usage)
|
|
11
|
+
- [Environments](#environments)
|
|
12
|
+
- [Errors](#errors)
|
|
13
|
+
- [Advanced](#advanced)
|
|
14
|
+
- [Retries](#retries)
|
|
15
|
+
- [Timeouts](#timeouts)
|
|
16
|
+
- [Additional Headers](#additional-headers)
|
|
17
|
+
- [Additional Query Parameters](#additional-query-parameters)
|
|
18
|
+
- [Contributing](#contributing)
|
|
19
|
+
|
|
20
|
+
## Reference
|
|
21
|
+
|
|
22
|
+
A full reference for this library is available [here](./reference.md).
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Instantiate and use the client with the following:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require "insion"
|
|
30
|
+
|
|
31
|
+
client = Insion::Client.new(token: "<token>")
|
|
32
|
+
|
|
33
|
+
client.moderate_a_record(
|
|
34
|
+
client_id: "clientId",
|
|
35
|
+
name: "name",
|
|
36
|
+
entity: "entity",
|
|
37
|
+
content: "content"
|
|
38
|
+
)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Environments
|
|
42
|
+
|
|
43
|
+
This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.
|
|
44
|
+
### Environments
|
|
45
|
+
```ruby
|
|
46
|
+
require "Insion"
|
|
47
|
+
|
|
48
|
+
Insion = Insion::Client.new(
|
|
49
|
+
base_url: Insion::Environment::DEFAULT
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Custom URL
|
|
54
|
+
```ruby
|
|
55
|
+
require "Insion"
|
|
56
|
+
|
|
57
|
+
client = Insion::Client.new(
|
|
58
|
+
base_url: "https://example.com"
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Errors
|
|
63
|
+
|
|
64
|
+
Failed API calls will raise errors that can be rescued from granularly.
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
require "Insion"
|
|
68
|
+
|
|
69
|
+
client = Insion::Client.new(
|
|
70
|
+
base_url: "https://example.com"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
begin
|
|
74
|
+
result = client.moderate_a_record
|
|
75
|
+
rescue Insion::Errors::TimeoutError
|
|
76
|
+
puts "API didn't respond before our timeout elapsed"
|
|
77
|
+
rescue Insion::Errors::ServiceUnavailableError
|
|
78
|
+
puts "API returned status 503, is probably overloaded, try again later"
|
|
79
|
+
rescue Insion::Errors::ServerError
|
|
80
|
+
puts "API returned some other 5xx status, this is probably a bug"
|
|
81
|
+
rescue Insion::Errors::ResponseError => e
|
|
82
|
+
puts "API returned an unexpected status other than 5xx: #{e.code} #{e.message}"
|
|
83
|
+
rescue Insion::Errors::ApiError => e
|
|
84
|
+
puts "Some other error occurred when calling the API: #{e.message}"
|
|
85
|
+
end
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Advanced
|
|
89
|
+
|
|
90
|
+
### Retries
|
|
91
|
+
|
|
92
|
+
The SDK is instrumented with automatic retries. A request will be retried as long as the request is deemed
|
|
93
|
+
retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
|
|
94
|
+
|
|
95
|
+
A request is deemed retryable when any of the following HTTP status codes is returned:
|
|
96
|
+
|
|
97
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
98
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
99
|
+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (Internal Server Error)
|
|
100
|
+
|
|
101
|
+
The `retryStatusCodes` configuration controls which [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) status codes are retried:
|
|
102
|
+
|
|
103
|
+
- `legacy` (default): Retries `408`, `429`, `500`, `502`, `503`, `504`, `521`, `522`, `524`
|
|
104
|
+
- `recommended`: Retries `408`, `429`, `502`, `503`, `504` only (excludes `500 Internal Server Error` to avoid retrying non-idempotent failures)
|
|
105
|
+
|
|
106
|
+
Use the `max_retries` option to configure this behavior.
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
require "Insion"
|
|
110
|
+
|
|
111
|
+
client = Insion::Client.new(
|
|
112
|
+
base_url: "https://example.com",
|
|
113
|
+
max_retries: 3 # Configure max retries (default is 2)
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Timeouts
|
|
118
|
+
|
|
119
|
+
The SDK defaults to a 60 second timeout. Use the `timeout` option to configure this behavior.
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
require "Insion"
|
|
123
|
+
|
|
124
|
+
response = client.moderate_a_record(
|
|
125
|
+
...,
|
|
126
|
+
timeout: 30 # 30 second timeout
|
|
127
|
+
)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Additional Headers
|
|
131
|
+
|
|
132
|
+
If you would like to send additional headers as part of the request, use the `additional_headers` request option.
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
require "Insion"
|
|
136
|
+
|
|
137
|
+
response = client.moderate_a_record(
|
|
138
|
+
...,
|
|
139
|
+
request_options: {
|
|
140
|
+
additional_headers: {
|
|
141
|
+
"X-Custom-Header" => "custom-value"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Additional Query Parameters
|
|
148
|
+
|
|
149
|
+
If you would like to send additional query parameters as part of the request, use the `additional_query_parameters` request option.
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
require "Insion"
|
|
153
|
+
|
|
154
|
+
response = client.moderate_a_record(
|
|
155
|
+
...,
|
|
156
|
+
request_options: {
|
|
157
|
+
additional_query_parameters: {
|
|
158
|
+
"custom_param" => "custom-value"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
While we value open-source contributions to this SDK, this library is generated programmatically.
|
|
167
|
+
Additions made directly to this library would have to be moved over to our generation code,
|
|
168
|
+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
|
|
169
|
+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
|
|
170
|
+
an issue first to discuss with us!
|
|
171
|
+
|
|
172
|
+
On the other hand, contributions to the README are always very welcome!
|
data/changelog.md
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Insion
|
|
4
|
+
class Client
|
|
5
|
+
# Create or update a record and return its moderation result immediately.
|
|
6
|
+
#
|
|
7
|
+
# @param request_options [Hash]
|
|
8
|
+
# @param params [Insion::Types::ModerateRequest]
|
|
9
|
+
# @option request_options [String] :base_url
|
|
10
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
11
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
12
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
13
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
14
|
+
#
|
|
15
|
+
# @example
|
|
16
|
+
# client.moderate_a_record(
|
|
17
|
+
# client_id: "clientId",
|
|
18
|
+
# name: "name",
|
|
19
|
+
# entity: "entity",
|
|
20
|
+
# content: "content"
|
|
21
|
+
# )
|
|
22
|
+
#
|
|
23
|
+
# @return [Insion::Types::ModerateResponse]
|
|
24
|
+
def moderate_a_record(request_options: {}, **params)
|
|
25
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
26
|
+
request = Insion::Internal::JSON::Request.new(
|
|
27
|
+
base_url: request_options[:base_url],
|
|
28
|
+
method: "POST",
|
|
29
|
+
path: "api/v1/moderate",
|
|
30
|
+
body: Insion::Types::ModerateRequest.new(params).to_h,
|
|
31
|
+
request_options: request_options
|
|
32
|
+
)
|
|
33
|
+
begin
|
|
34
|
+
response = @client.send(request)
|
|
35
|
+
rescue Net::HTTPRequestTimeout
|
|
36
|
+
raise Insion::Errors::TimeoutError
|
|
37
|
+
end
|
|
38
|
+
code = response.code.to_i
|
|
39
|
+
if code.between?(200, 299)
|
|
40
|
+
Insion::Types::ModerateResponse.load(response.body)
|
|
41
|
+
else
|
|
42
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
43
|
+
raise error_class.new(response.body, code: code)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Create or update a content record for asynchronous moderation. Results are delivered through webhook events when
|
|
48
|
+
# moderation is performed.
|
|
49
|
+
#
|
|
50
|
+
# @param request_options [Hash]
|
|
51
|
+
# @param params [Insion::Types::IngestRecordRequest]
|
|
52
|
+
# @option request_options [String] :base_url
|
|
53
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
54
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
55
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
56
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
57
|
+
#
|
|
58
|
+
# @example
|
|
59
|
+
# client.ingest_a_record(
|
|
60
|
+
# client_id: "clientId",
|
|
61
|
+
# name: "name",
|
|
62
|
+
# entity: "entity",
|
|
63
|
+
# content: "content"
|
|
64
|
+
# )
|
|
65
|
+
#
|
|
66
|
+
# @return [Insion::Types::IngestRecordResponse]
|
|
67
|
+
def ingest_a_record(request_options: {}, **params)
|
|
68
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
69
|
+
request = Insion::Internal::JSON::Request.new(
|
|
70
|
+
base_url: request_options[:base_url],
|
|
71
|
+
method: "POST",
|
|
72
|
+
path: "api/v1/ingest",
|
|
73
|
+
body: Insion::Types::RecordInput.new(params).to_h,
|
|
74
|
+
request_options: request_options
|
|
75
|
+
)
|
|
76
|
+
begin
|
|
77
|
+
response = @client.send(request)
|
|
78
|
+
rescue Net::HTTPRequestTimeout
|
|
79
|
+
raise Insion::Errors::TimeoutError
|
|
80
|
+
end
|
|
81
|
+
code = response.code.to_i
|
|
82
|
+
if code.between?(200, 299)
|
|
83
|
+
Insion::Types::IngestRecordResponse.load(response.body)
|
|
84
|
+
else
|
|
85
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
86
|
+
raise error_class.new(response.body, code: code)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Remove a record from the moderation system by its client ID.
|
|
91
|
+
#
|
|
92
|
+
# @param request_options [Hash]
|
|
93
|
+
# @param params [Insion::Types::DeleteAPIV1IngestRequest]
|
|
94
|
+
# @option request_options [String] :base_url
|
|
95
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
96
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
97
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
98
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
99
|
+
#
|
|
100
|
+
# @example
|
|
101
|
+
# client.delete_a_record(client_id: "clientId")
|
|
102
|
+
#
|
|
103
|
+
# @return [Insion::Types::SuccessResponse]
|
|
104
|
+
def delete_a_record(request_options: {}, **params)
|
|
105
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
106
|
+
request = Insion::Internal::JSON::Request.new(
|
|
107
|
+
base_url: request_options[:base_url],
|
|
108
|
+
method: "DELETE",
|
|
109
|
+
path: "api/v1/ingest",
|
|
110
|
+
body: Insion::Types::DeleteAPIV1IngestRequest.new(params).to_h,
|
|
111
|
+
request_options: request_options
|
|
112
|
+
)
|
|
113
|
+
begin
|
|
114
|
+
response = @client.send(request)
|
|
115
|
+
rescue Net::HTTPRequestTimeout
|
|
116
|
+
raise Insion::Errors::TimeoutError
|
|
117
|
+
end
|
|
118
|
+
code = response.code.to_i
|
|
119
|
+
if code.between?(200, 299)
|
|
120
|
+
Insion::Types::SuccessResponse.load(response.body)
|
|
121
|
+
else
|
|
122
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
123
|
+
raise error_class.new(response.body, code: code)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Create or update a user without ingesting a record.
|
|
128
|
+
#
|
|
129
|
+
# @param request_options [Hash]
|
|
130
|
+
# @param params [Insion::Types::UserInput]
|
|
131
|
+
# @option request_options [String] :base_url
|
|
132
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
133
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
134
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
135
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
136
|
+
#
|
|
137
|
+
# @example
|
|
138
|
+
# client.ingest_a_user(client_id: "clientId")
|
|
139
|
+
#
|
|
140
|
+
# @return [Insion::Types::IngestUserResponse]
|
|
141
|
+
def ingest_a_user(request_options: {}, **params)
|
|
142
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
143
|
+
request = Insion::Internal::JSON::Request.new(
|
|
144
|
+
base_url: request_options[:base_url],
|
|
145
|
+
method: "POST",
|
|
146
|
+
path: "api/v1/ingest/user",
|
|
147
|
+
body: Insion::Types::UserInput.new(params).to_h,
|
|
148
|
+
request_options: request_options
|
|
149
|
+
)
|
|
150
|
+
begin
|
|
151
|
+
response = @client.send(request)
|
|
152
|
+
rescue Net::HTTPRequestTimeout
|
|
153
|
+
raise Insion::Errors::TimeoutError
|
|
154
|
+
end
|
|
155
|
+
code = response.code.to_i
|
|
156
|
+
if code.between?(200, 299)
|
|
157
|
+
Insion::Types::IngestUserResponse.load(response.body)
|
|
158
|
+
else
|
|
159
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
160
|
+
raise error_class.new(response.body, code: code)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# List the records belonging to the authenticated organization.
|
|
165
|
+
#
|
|
166
|
+
# @param request_options [Hash]
|
|
167
|
+
# @param params [Hash]
|
|
168
|
+
# @option request_options [String] :base_url
|
|
169
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
170
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
171
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
172
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
173
|
+
# @option params [Integer, nil] :limit
|
|
174
|
+
# @option params [String, nil] :starting_after
|
|
175
|
+
# @option params [String, nil] :ending_before
|
|
176
|
+
# @option params [String, nil] :client_id
|
|
177
|
+
# @option params [String, nil] :user
|
|
178
|
+
# @option params [String, nil] :entity
|
|
179
|
+
# @option params [Insion::Types::GetAPIV1RecordsRequestStatus, nil] :status
|
|
180
|
+
#
|
|
181
|
+
# @example
|
|
182
|
+
# client.list_records
|
|
183
|
+
#
|
|
184
|
+
# @return [Insion::Types::ListRecordsResponse]
|
|
185
|
+
def list_records(request_options: {}, **params)
|
|
186
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
187
|
+
query_params = {}
|
|
188
|
+
query_params["limit"] = params[:limit] if params.key?(:limit)
|
|
189
|
+
query_params["starting_after"] = params[:starting_after] if params.key?(:starting_after)
|
|
190
|
+
query_params["ending_before"] = params[:ending_before] if params.key?(:ending_before)
|
|
191
|
+
query_params["clientId"] = params[:client_id] if params.key?(:client_id)
|
|
192
|
+
query_params["user"] = params[:user] if params.key?(:user)
|
|
193
|
+
query_params["entity"] = params[:entity] if params.key?(:entity)
|
|
194
|
+
query_params["status"] = params[:status] if params.key?(:status)
|
|
195
|
+
|
|
196
|
+
request = Insion::Internal::JSON::Request.new(
|
|
197
|
+
base_url: request_options[:base_url],
|
|
198
|
+
method: "GET",
|
|
199
|
+
path: "api/v1/records",
|
|
200
|
+
query: query_params,
|
|
201
|
+
request_options: request_options
|
|
202
|
+
)
|
|
203
|
+
begin
|
|
204
|
+
response = @client.send(request)
|
|
205
|
+
rescue Net::HTTPRequestTimeout
|
|
206
|
+
raise Insion::Errors::TimeoutError
|
|
207
|
+
end
|
|
208
|
+
code = response.code.to_i
|
|
209
|
+
if code.between?(200, 299)
|
|
210
|
+
Insion::Types::ListRecordsResponse.load(response.body)
|
|
211
|
+
else
|
|
212
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
213
|
+
raise error_class.new(response.body, code: code)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Retrieve one record by its Insion record ID.
|
|
218
|
+
#
|
|
219
|
+
# @param request_options [Hash]
|
|
220
|
+
# @param params [Hash]
|
|
221
|
+
# @option request_options [String] :base_url
|
|
222
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
223
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
224
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
225
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
226
|
+
# @option params [String] :record_id
|
|
227
|
+
#
|
|
228
|
+
# @example
|
|
229
|
+
# client.retrieve_a_record(record_id: "recordId")
|
|
230
|
+
#
|
|
231
|
+
# @return [Insion::Types::RecordResponse]
|
|
232
|
+
def retrieve_a_record(request_options: {}, **params)
|
|
233
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
234
|
+
request = Insion::Internal::JSON::Request.new(
|
|
235
|
+
base_url: request_options[:base_url],
|
|
236
|
+
method: "GET",
|
|
237
|
+
path: "api/v1/records/#{URI.encode_uri_component(params[:record_id].to_s)}",
|
|
238
|
+
request_options: request_options
|
|
239
|
+
)
|
|
240
|
+
begin
|
|
241
|
+
response = @client.send(request)
|
|
242
|
+
rescue Net::HTTPRequestTimeout
|
|
243
|
+
raise Insion::Errors::TimeoutError
|
|
244
|
+
end
|
|
245
|
+
code = response.code.to_i
|
|
246
|
+
if code.between?(200, 299)
|
|
247
|
+
Insion::Types::RecordResponse.load(response.body)
|
|
248
|
+
else
|
|
249
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
250
|
+
raise error_class.new(response.body, code: code)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# List the users belonging to the authenticated organization.
|
|
255
|
+
#
|
|
256
|
+
# @param request_options [Hash]
|
|
257
|
+
# @param params [Hash]
|
|
258
|
+
# @option request_options [String] :base_url
|
|
259
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
260
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
261
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
262
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
263
|
+
# @option params [Integer, nil] :limit
|
|
264
|
+
# @option params [String, nil] :starting_after
|
|
265
|
+
# @option params [String, nil] :ending_before
|
|
266
|
+
# @option params [String, nil] :client_id
|
|
267
|
+
# @option params [String, nil] :email
|
|
268
|
+
# @option params [Insion::Types::GetAPIV1UsersRequestStatus, nil] :status
|
|
269
|
+
# @option params [String, nil] :user
|
|
270
|
+
#
|
|
271
|
+
# @example
|
|
272
|
+
# client.list_users
|
|
273
|
+
#
|
|
274
|
+
# @return [Insion::Types::ListUsersResponse]
|
|
275
|
+
def list_users(request_options: {}, **params)
|
|
276
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
277
|
+
query_params = {}
|
|
278
|
+
query_params["limit"] = params[:limit] if params.key?(:limit)
|
|
279
|
+
query_params["starting_after"] = params[:starting_after] if params.key?(:starting_after)
|
|
280
|
+
query_params["ending_before"] = params[:ending_before] if params.key?(:ending_before)
|
|
281
|
+
query_params["clientId"] = params[:client_id] if params.key?(:client_id)
|
|
282
|
+
query_params["email"] = params[:email] if params.key?(:email)
|
|
283
|
+
query_params["status"] = params[:status] if params.key?(:status)
|
|
284
|
+
query_params["user"] = params[:user] if params.key?(:user)
|
|
285
|
+
|
|
286
|
+
request = Insion::Internal::JSON::Request.new(
|
|
287
|
+
base_url: request_options[:base_url],
|
|
288
|
+
method: "GET",
|
|
289
|
+
path: "api/v1/users",
|
|
290
|
+
query: query_params,
|
|
291
|
+
request_options: request_options
|
|
292
|
+
)
|
|
293
|
+
begin
|
|
294
|
+
response = @client.send(request)
|
|
295
|
+
rescue Net::HTTPRequestTimeout
|
|
296
|
+
raise Insion::Errors::TimeoutError
|
|
297
|
+
end
|
|
298
|
+
code = response.code.to_i
|
|
299
|
+
if code.between?(200, 299)
|
|
300
|
+
Insion::Types::ListUsersResponse.load(response.body)
|
|
301
|
+
else
|
|
302
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
303
|
+
raise error_class.new(response.body, code: code)
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# Retrieve one user by its Insion user ID.
|
|
308
|
+
#
|
|
309
|
+
# @param request_options [Hash]
|
|
310
|
+
# @param params [Hash]
|
|
311
|
+
# @option request_options [String] :base_url
|
|
312
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
313
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
314
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
315
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
316
|
+
# @option params [String] :user_id
|
|
317
|
+
#
|
|
318
|
+
# @example
|
|
319
|
+
# client.retrieve_a_user(user_id: "userId")
|
|
320
|
+
#
|
|
321
|
+
# @return [Insion::Types::UserResponse]
|
|
322
|
+
def retrieve_a_user(request_options: {}, **params)
|
|
323
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
324
|
+
request = Insion::Internal::JSON::Request.new(
|
|
325
|
+
base_url: request_options[:base_url],
|
|
326
|
+
method: "GET",
|
|
327
|
+
path: "api/v1/users/#{URI.encode_uri_component(params[:user_id].to_s)}",
|
|
328
|
+
request_options: request_options
|
|
329
|
+
)
|
|
330
|
+
begin
|
|
331
|
+
response = @client.send(request)
|
|
332
|
+
rescue Net::HTTPRequestTimeout
|
|
333
|
+
raise Insion::Errors::TimeoutError
|
|
334
|
+
end
|
|
335
|
+
code = response.code.to_i
|
|
336
|
+
if code.between?(200, 299)
|
|
337
|
+
Insion::Types::UserResponse.load(response.body)
|
|
338
|
+
else
|
|
339
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
340
|
+
raise error_class.new(response.body, code: code)
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
# Create an appeal for a suspended user. Appeals must be enabled for the organization.
|
|
345
|
+
#
|
|
346
|
+
# @param request_options [Hash]
|
|
347
|
+
# @param params [Insion::Types::PostAPIV1UsersUserIDCreateAppealRequest]
|
|
348
|
+
# @option request_options [String] :base_url
|
|
349
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
350
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
351
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
352
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
353
|
+
# @option params [String] :user_id
|
|
354
|
+
#
|
|
355
|
+
# @example
|
|
356
|
+
# client.create_an_appeal(
|
|
357
|
+
# user_id: "userId",
|
|
358
|
+
# text: "text"
|
|
359
|
+
# )
|
|
360
|
+
#
|
|
361
|
+
# @return [Insion::Types::CreateAppealResponse]
|
|
362
|
+
def create_an_appeal(request_options: {}, **params)
|
|
363
|
+
params = Insion::Internal::Types::Utils.normalize_keys(params)
|
|
364
|
+
request_data = Insion::Types::PostAPIV1UsersUserIDCreateAppealRequest.new(params).to_h
|
|
365
|
+
non_body_param_names = %w[userId]
|
|
366
|
+
body = request_data.except(*non_body_param_names)
|
|
367
|
+
|
|
368
|
+
request = Insion::Internal::JSON::Request.new(
|
|
369
|
+
base_url: request_options[:base_url],
|
|
370
|
+
method: "POST",
|
|
371
|
+
path: "api/v1/users/#{URI.encode_uri_component(params[:user_id].to_s)}/create_appeal",
|
|
372
|
+
body: body,
|
|
373
|
+
request_options: request_options
|
|
374
|
+
)
|
|
375
|
+
begin
|
|
376
|
+
response = @client.send(request)
|
|
377
|
+
rescue Net::HTTPRequestTimeout
|
|
378
|
+
raise Insion::Errors::TimeoutError
|
|
379
|
+
end
|
|
380
|
+
code = response.code.to_i
|
|
381
|
+
if code.between?(200, 299)
|
|
382
|
+
Insion::Types::CreateAppealResponse.load(response.body)
|
|
383
|
+
else
|
|
384
|
+
error_class = Insion::Errors::ResponseError.subclass_for_code(code)
|
|
385
|
+
raise error_class.new(response.body, code: code)
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
# @param token [String]
|
|
390
|
+
# @param base_url [String, nil]
|
|
391
|
+
# @param max_retries [Integer]
|
|
392
|
+
#
|
|
393
|
+
# @return [void]
|
|
394
|
+
def initialize(token:, base_url: nil, max_retries: 2)
|
|
395
|
+
@raw_client = Insion::Internal::Http::RawClient.new(
|
|
396
|
+
base_url: base_url || Insion::Environment::DEFAULT,
|
|
397
|
+
headers: {
|
|
398
|
+
Authorization: "Bearer #{token}"
|
|
399
|
+
},
|
|
400
|
+
max_retries: max_retries
|
|
401
|
+
)
|
|
402
|
+
end
|
|
403
|
+
end
|
|
404
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Insion
|
|
4
|
+
module Errors
|
|
5
|
+
class ClientError < ResponseError
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class UnauthorizedError < ClientError
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class ForbiddenError < ClientError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class NotFoundError < ClientError
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Insion
|
|
4
|
+
module Errors
|
|
5
|
+
class ResponseError < ApiError
|
|
6
|
+
attr_reader :code
|
|
7
|
+
|
|
8
|
+
def initialize(msg, code:)
|
|
9
|
+
@code = code
|
|
10
|
+
super(msg)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def inspect
|
|
14
|
+
"#<#{self.class.name} @code=#{code} @body=#{message}>"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Returns the most appropriate error class for the given code.
|
|
18
|
+
#
|
|
19
|
+
# @return [Class]
|
|
20
|
+
def self.subclass_for_code(code)
|
|
21
|
+
case code
|
|
22
|
+
when 300..399
|
|
23
|
+
RedirectError
|
|
24
|
+
when 401
|
|
25
|
+
UnauthorizedError
|
|
26
|
+
when 403
|
|
27
|
+
ForbiddenError
|
|
28
|
+
when 404
|
|
29
|
+
NotFoundError
|
|
30
|
+
when 400..499
|
|
31
|
+
ClientError
|
|
32
|
+
when 503
|
|
33
|
+
ServiceUnavailableError
|
|
34
|
+
when 500..599
|
|
35
|
+
ServerError
|
|
36
|
+
else
|
|
37
|
+
ResponseError
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|