copyleaks 5.0.0
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/.gitignore +17 -0
- data/CHANGELOG.md +102 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +487 -0
- data/Rakefile +13 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/copyleaks/ai_detection_client.rb +27 -0
- data/lib/copyleaks/ai_image_detection_client.rb +35 -0
- data/lib/copyleaks/ai_video_detection_client.rb +20 -0
- data/lib/copyleaks/api.rb +247 -0
- data/lib/copyleaks/app.config.rb +36 -0
- data/lib/copyleaks/image_plagiarism_client.rb +19 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionExplainModel.rb +26 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionMatchModel.rb +33 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionMatchTextModel.rb +31 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionPatternMatchModel.rb +32 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionPatternStatisticsModel.rb +46 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionPatternsModel.rb +38 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionPositionsModel.rb +39 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionResponseModel.rb +68 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionResultModel.rb +41 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionScannedDocumentModel.rb +21 -0
- data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionSummaryModel.rb +34 -0
- data/lib/copyleaks/models/auth_token.rb +46 -0
- data/lib/copyleaks/models/constants/CopyleaksAiImageDetectionModels.rb +5 -0
- data/lib/copyleaks/models/constants/CopyleaksAiImageMaskTypes.rb +11 -0
- data/lib/copyleaks/models/constants/CopyleaksAiVideoDetectionModels.rb +5 -0
- data/lib/copyleaks/models/constants/CopyleaksAlertCodes.rb +7 -0
- data/lib/copyleaks/models/constants/CopyleaksTextModerationConstants.rb +15 -0
- data/lib/copyleaks/models/constants/CopyleaksTextModerationLanguages.rb +6 -0
- data/lib/copyleaks/models/constants/index.rb +10 -0
- data/lib/copyleaks/models/delete_request_model.rb +50 -0
- data/lib/copyleaks/models/exceptions/auth_expired_exception.rb +7 -0
- data/lib/copyleaks/models/exceptions/command_exception.rb +13 -0
- data/lib/copyleaks/models/exceptions/copyleaks_api_exception.rb +18 -0
- data/lib/copyleaks/models/exceptions/index.rb +8 -0
- data/lib/copyleaks/models/exceptions/rate_limit_exception.rb +8 -0
- data/lib/copyleaks/models/exceptions/under_maintenance_exception.rb +8 -0
- data/lib/copyleaks/models/exports/export_crawled_version.rb +6 -0
- data/lib/copyleaks/models/exports/export_model.rb +87 -0
- data/lib/copyleaks/models/exports/export_pdf_report.rb +6 -0
- data/lib/copyleaks/models/exports/export_results.rb +30 -0
- data/lib/copyleaks/models/exports/export_target.rb +42 -0
- data/lib/copyleaks/models/exports/index.rb +8 -0
- data/lib/copyleaks/models/id_object.rb +22 -0
- data/lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionAsyncRequestModel.rb +63 -0
- data/lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb +135 -0
- data/lib/copyleaks/models/imageDetection/requests/CopyleaksAsyncWebhooksModel.rb +37 -0
- data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectedObjectModel.rb +31 -0
- data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionImageInfoModel.rb +31 -0
- data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionResponseModel.rb +79 -0
- data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionResultModel.rb +40 -0
- data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionScannedDocumentModel.rb +46 -0
- data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionSummaryModel.rb +33 -0
- data/lib/copyleaks/models/imageDetection/responses/CopyleaksImageMetadataModel.rb +45 -0
- data/lib/copyleaks/models/imageDetection/responses/CopyleaksImageShapeModel.rb +31 -0
- data/lib/copyleaks/models/imagePlagiarism/requests/CopyleaksImagePlagiarismRequestModel.rb +51 -0
- data/lib/copyleaks/models/imagePlagiarism/responses/CopyleaksImagePlagiarismResponseModel.rb +187 -0
- data/lib/copyleaks/models/index.rb +51 -0
- data/lib/copyleaks/models/start_request_model.rb +40 -0
- data/lib/copyleaks/models/submissions/ai_detection/ai_detection_submission_model.rb +25 -0
- data/lib/copyleaks/models/submissions/ai_detection/natural_language_submission_model.rb +41 -0
- data/lib/copyleaks/models/submissions/file_ocr_submission_model.rb +36 -0
- data/lib/copyleaks/models/submissions/file_submission_model.rb +35 -0
- data/lib/copyleaks/models/submissions/index.rb +16 -0
- data/lib/copyleaks/models/submissions/properties/actions.rb +10 -0
- data/lib/copyleaks/models/submissions/properties/ai_generated_text.rb +40 -0
- data/lib/copyleaks/models/submissions/properties/ai_generated_text_explain.rb +6 -0
- data/lib/copyleaks/models/submissions/properties/ai_source_match.rb +6 -0
- data/lib/copyleaks/models/submissions/properties/assignment.rb +6 -0
- data/lib/copyleaks/models/submissions/properties/author.rb +18 -0
- data/lib/copyleaks/models/submissions/properties/copyleaks_db.rb +22 -0
- data/lib/copyleaks/models/submissions/properties/course.rb +6 -0
- data/lib/copyleaks/models/submissions/properties/cross_languages.rb +21 -0
- data/lib/copyleaks/models/submissions/properties/custom_metadata.rb +19 -0
- data/lib/copyleaks/models/submissions/properties/domains_mode.rb +8 -0
- data/lib/copyleaks/models/submissions/properties/enable_flag.rb +26 -0
- data/lib/copyleaks/models/submissions/properties/exclude.rb +57 -0
- data/lib/copyleaks/models/submissions/properties/exclude_code.rb +19 -0
- data/lib/copyleaks/models/submissions/properties/filter.rb +49 -0
- data/lib/copyleaks/models/submissions/properties/index.rb +43 -0
- data/lib/copyleaks/models/submissions/properties/indexing.rb +25 -0
- data/lib/copyleaks/models/submissions/properties/indexing_repository.rb +26 -0
- data/lib/copyleaks/models/submissions/properties/institution.rb +6 -0
- data/lib/copyleaks/models/submissions/properties/internal_ai_source_match.rb +7 -0
- data/lib/copyleaks/models/submissions/properties/language.rb +18 -0
- data/lib/copyleaks/models/submissions/properties/masking_policy.rb +11 -0
- data/lib/copyleaks/models/submissions/properties/overview.rb +42 -0
- data/lib/copyleaks/models/submissions/properties/pdf_colors.rb +48 -0
- data/lib/copyleaks/models/submissions/properties/pdf_properties.rb +51 -0
- data/lib/copyleaks/models/submissions/properties/pdf_report_version.rb +9 -0
- data/lib/copyleaks/models/submissions/properties/pdf_version.rb +10 -0
- data/lib/copyleaks/models/submissions/properties/references.rb +26 -0
- data/lib/copyleaks/models/submissions/properties/repository.rb +18 -0
- data/lib/copyleaks/models/submissions/properties/scan_method_algorithm.rb +8 -0
- data/lib/copyleaks/models/submissions/properties/scanning.rb +44 -0
- data/lib/copyleaks/models/submissions/properties/scanning_exclude.rb +47 -0
- data/lib/copyleaks/models/submissions/properties/scanning_include.rb +25 -0
- data/lib/copyleaks/models/submissions/properties/scanning_repository.rb +23 -0
- data/lib/copyleaks/models/submissions/properties/sensitive_data_protection.rb +42 -0
- data/lib/copyleaks/models/submissions/properties/submission_properties.rb +179 -0
- data/lib/copyleaks/models/submissions/properties/webhooks.rb +42 -0
- data/lib/copyleaks/models/submissions/properties/writing_feedback.rb +30 -0
- data/lib/copyleaks/models/submissions/submission_model.rb +24 -0
- data/lib/copyleaks/models/submissions/url_submission_model.rb +41 -0
- data/lib/copyleaks/models/submissions/webhooks/CompletedWebhook.rb +67 -0
- data/lib/copyleaks/models/submissions/webhooks/CreditsCheckedWebhook.rb +24 -0
- data/lib/copyleaks/models/submissions/webhooks/ErrorWebhook.rb +22 -0
- data/lib/copyleaks/models/submissions/webhooks/ExportCompletedWebhook.rb +25 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/BaseModels/Metadata.rb +61 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/BaseModels/StatusWebhook.rb +23 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/BaseModels/Webhook.rb +25 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/CompletedModels/Notifications.rb +24 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/CompletedModels/Results.rb +54 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/CompletedModels/ScannedDocument.rb +36 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ErrorModels/Error.rb +49 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ExportModels/Task.rb +29 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/NewResultsModels/NewResultScore.rb +22 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/NewResultsModels/NewResultsInternet.rb +37 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/NewResultsModels/NewResultsRepositories.rb +28 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/NotificationsModels/Alerts.rb +91 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Batch.rb +26 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Database.rb +26 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Internet.rb +23 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Repositories.rb +36 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/RepositoryMetadata.rb +11 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Score.rb +20 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/SharedResultsModel.rb +22 -0
- data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Tags.rb +12 -0
- data/lib/copyleaks/models/submissions/webhooks/IndexedWebhook.rb +9 -0
- data/lib/copyleaks/models/submissions/webhooks/NewResultWebhook.rb +32 -0
- data/lib/copyleaks/models/submissions/webhooks/index.rb +34 -0
- data/lib/copyleaks/models/submissions/writing_assistant/score_weights.rb +26 -0
- data/lib/copyleaks/models/submissions/writing_assistant/writing_assistant_submission_model.rb +32 -0
- data/lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationLabel.rb +21 -0
- data/lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb +45 -0
- data/lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb +55 -0
- data/lib/copyleaks/models/textModeration/responses/submodules/ModerationsModel.rb +27 -0
- data/lib/copyleaks/models/textModeration/responses/submodules/Text.rb +27 -0
- data/lib/copyleaks/models/textModeration/responses/submodules/TextModerationChars.rb +32 -0
- data/lib/copyleaks/models/textModeration/responses/submodules/TextModerationScannedDocument.rb +55 -0
- data/lib/copyleaks/models/textModeration/responses/submodules/TextModerationsLegend.rb +29 -0
- data/lib/copyleaks/models/videoDetection/requests/CopyleaksAiVideoDetectionRequestModel.rb +61 -0
- data/lib/copyleaks/models/videoDetection/responses/CopyleaksAiVideoDetectionResponseModel.rb +177 -0
- data/lib/copyleaks/text_moderation_client.rb +18 -0
- data/lib/copyleaks/utils/copyleaks_client.utils.rb +101 -0
- data/lib/copyleaks/utils/http_client.rb +164 -0
- data/lib/copyleaks/utils/multipart.rb +86 -0
- data/lib/copyleaks/utils/status-code.utils.rb +23 -0
- data/lib/copyleaks/version.rb +3 -0
- data/lib/copyleaks/writing_assistant_client.rb +26 -0
- data/lib/copyleaks.rb +11 -0
- data/lib/index.rb +4 -0
- metadata +248 -0
data/lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionAsyncRequestModel.rb
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Copyleaks
|
|
2
|
+
# Async AI image detection request: Copyleaks downloads the image from url and posts the result to webhooks.url.
|
|
3
|
+
class CopyleaksAiImageDetectionAsyncRequestModel
|
|
4
|
+
attr_reader :url, :file_name, :model, :webhooks, :mask_type, :object_detection, :headers, :sandbox,
|
|
5
|
+
:developer_payload
|
|
6
|
+
|
|
7
|
+
# @param url [String] Publicly accessible image URL.
|
|
8
|
+
# @param file_name [String] With extension: .jpg, .jpeg, .png, .webp, .tiff, .bmp, .heic, .heif.
|
|
9
|
+
# @param model [String] See CopyleaksAiImageDetectionModels.
|
|
10
|
+
# @param webhooks [CopyleaksAsyncWebhooksModel, String] A String is used as webhooks.url.
|
|
11
|
+
# @param mask_type [String, nil] CopyleaksAiImageMaskTypes::BINARY (server default) or HEATMAP.
|
|
12
|
+
# @param object_detection [Array<String>, nil] Up to 3 objects to locate, for example ['face'].
|
|
13
|
+
# @param headers [Array<Array<String>>, nil] Sent with the image download, e.g. [['X-Custom-Auth', 'my-token']].
|
|
14
|
+
# @param sandbox [Boolean, nil] Free mock results. Server default: false.
|
|
15
|
+
# @param developer_payload [String, nil] Echoed back in the webhook.
|
|
16
|
+
def initialize(url:, file_name:, model:, webhooks:, mask_type: nil, object_detection: nil, headers: nil,
|
|
17
|
+
sandbox: nil, developer_payload: nil)
|
|
18
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionAsyncRequestModel - url must be a String' unless url.is_a?(String)
|
|
19
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionAsyncRequestModel - file_name must be a String' unless file_name.is_a?(String)
|
|
20
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionAsyncRequestModel - model must be a String' unless model.is_a?(String)
|
|
21
|
+
if !mask_type.nil? && !mask_type.is_a?(String)
|
|
22
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionAsyncRequestModel - mask_type must be a String'
|
|
23
|
+
end
|
|
24
|
+
unless Utils.headers_valid?(headers)
|
|
25
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionAsyncRequestModel - headers must be an Array of [name, value] String pairs'
|
|
26
|
+
end
|
|
27
|
+
if !sandbox.nil? && ![true, false].include?(sandbox)
|
|
28
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionAsyncRequestModel - sandbox must be a Boolean'
|
|
29
|
+
end
|
|
30
|
+
if !developer_payload.nil? && !developer_payload.is_a?(String)
|
|
31
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionAsyncRequestModel - developer_payload must be a String'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@url = url
|
|
35
|
+
@file_name = file_name
|
|
36
|
+
@model = model
|
|
37
|
+
@webhooks = CopyleaksAsyncWebhooksModel.coerce(webhooks)
|
|
38
|
+
@mask_type = mask_type
|
|
39
|
+
@object_detection = CopyleaksAiImageDetectionRequestModel.normalize_object_detection(object_detection)
|
|
40
|
+
@headers = headers
|
|
41
|
+
@sandbox = sandbox
|
|
42
|
+
@developer_payload = developer_payload
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def as_json(*_args)
|
|
46
|
+
{
|
|
47
|
+
url: @url,
|
|
48
|
+
fileName: @file_name,
|
|
49
|
+
model: @model,
|
|
50
|
+
maskType: @mask_type,
|
|
51
|
+
objectDetection: @object_detection,
|
|
52
|
+
headers: @headers,
|
|
53
|
+
webhooks: @webhooks.as_json,
|
|
54
|
+
sandbox: @sandbox,
|
|
55
|
+
developerPayload: @developer_payload
|
|
56
|
+
}.reject { |_k, v| v.nil? }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def to_json(*options)
|
|
60
|
+
as_json(*options).to_json(*options)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
module Copyleaks
|
|
2
|
+
# Synchronous AI image detection request. Pass the image as base64 (JSON body), or pass nil and the raw
|
|
3
|
+
# bytes as image:, e.g. image: File.binread(path) (multipart body, recommended: no base64 overhead).
|
|
4
|
+
class CopyleaksAiImageDetectionRequestModel
|
|
5
|
+
VALID_EXTENSIONS = %w[.png .bmp .jpg .jpeg .webp .heic .heif .avif].freeze
|
|
6
|
+
FILENAME_MIN_LENGTH = 5
|
|
7
|
+
FILENAME_MAX_LENGTH = 254
|
|
8
|
+
MAX_OBJECT_DETECTION_ENTRIES = 3
|
|
9
|
+
MAX_OBJECT_NAME_LENGTH = 32
|
|
10
|
+
|
|
11
|
+
attr_accessor :base64, :file_name, :model, :sandbox, :mask_type, :object_detection, :image
|
|
12
|
+
|
|
13
|
+
# @param file_name [String] With extension; see VALID_EXTENSIONS.
|
|
14
|
+
# @param model [String] See CopyleaksAiImageDetectionModels.
|
|
15
|
+
# @param sandbox [Boolean, nil] Test without using credits. nil omits the field (server default: false).
|
|
16
|
+
# @param mask_type [String, nil] See CopyleaksAiImageMaskTypes. Server default: BINARY.
|
|
17
|
+
# @param object_detection [Array<String>, nil] Up to 3 names, 1-32 chars each, e.g. ['face']. Adds detectedObjects.
|
|
18
|
+
# @param image [String, IO, nil] Raw image bytes or an IO, uploaded as multipart/form-data.
|
|
19
|
+
def initialize(base64, file_name, model, sandbox = nil, mask_type: nil, object_detection: nil, image: nil)
|
|
20
|
+
if !base64.nil? && !image.nil?
|
|
21
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionRequestModel - pass either base64 or image:, not both'
|
|
22
|
+
end
|
|
23
|
+
if !image.nil? && !image.is_a?(String) && !image.respond_to?(:read)
|
|
24
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionRequestModel - image - image must be a binary String or an IO'
|
|
25
|
+
end
|
|
26
|
+
if !sandbox.nil? && ![true, false].include?(sandbox)
|
|
27
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionRequestModel - sandbox - sandbox must be of type Boolean'
|
|
28
|
+
end
|
|
29
|
+
if !mask_type.nil? && !mask_type.is_a?(String)
|
|
30
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAiImageDetectionRequestModel - mask_type - mask_type must be of type String'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
@base64 = base64
|
|
34
|
+
@file_name = file_name
|
|
35
|
+
@model = model
|
|
36
|
+
@sandbox = sandbox
|
|
37
|
+
@mask_type = mask_type
|
|
38
|
+
@object_detection = self.class.normalize_object_detection(object_detection)
|
|
39
|
+
@image = image
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# True when image: is set, so the request is sent as multipart/form-data.
|
|
43
|
+
def multipart?
|
|
44
|
+
!@image.nil?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Nil fields are left out.
|
|
48
|
+
def to_hash
|
|
49
|
+
{
|
|
50
|
+
base64: @base64,
|
|
51
|
+
filename: @file_name,
|
|
52
|
+
model: @model,
|
|
53
|
+
sandbox: @sandbox,
|
|
54
|
+
maskType: @mask_type,
|
|
55
|
+
objectDetection: @object_detection
|
|
56
|
+
}.reject { |_k, v| v.nil? }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def to_json(*args)
|
|
60
|
+
to_hash.to_json(*args)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# @return [Copyleaks::MultipartForm] The body used when image: is set.
|
|
64
|
+
def to_multipart
|
|
65
|
+
form = MultipartForm.new
|
|
66
|
+
form.add_file('image', @image, @file_name.to_s)
|
|
67
|
+
form.add_field('filename', @file_name)
|
|
68
|
+
form.add_field('model', @model) unless @model.nil?
|
|
69
|
+
form.add_field('sandbox', @sandbox) unless @sandbox.nil?
|
|
70
|
+
form.add_field('maskType', @mask_type) unless @mask_type.nil?
|
|
71
|
+
# Multipart requests carry the object list as one JSON-encoded field.
|
|
72
|
+
form.add_field('objectDetection', @object_detection.to_json) unless @object_detection.nil?
|
|
73
|
+
form
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Optional client-side checks; the client never calls this, so the server has the final say.
|
|
77
|
+
# Limits: 512x512 to 6000x4500 px (27 MP), under 32 MB; PNG, JPEG, BMP, WebP, HEIC/HEIF, AVIF;
|
|
78
|
+
# file name 5 to 254 characters with a supported extension.
|
|
79
|
+
# @raise [ArgumentError] When a field is missing or invalid.
|
|
80
|
+
def validate!
|
|
81
|
+
if @image.nil? && (@base64.nil? || @base64.empty?)
|
|
82
|
+
raise ArgumentError, 'base64 or image is required'
|
|
83
|
+
end
|
|
84
|
+
raise ArgumentError, 'file_name is required' if @file_name.nil? || @file_name.empty?
|
|
85
|
+
raise ArgumentError, 'model is required' if @model.nil? || @model.empty?
|
|
86
|
+
|
|
87
|
+
validate_file_name!
|
|
88
|
+
validate_file_size!
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Accepts ['face', 'hand'] or [{ object: 'face' }] and returns [{ object: 'face' }, ...].
|
|
92
|
+
def self.normalize_object_detection(list)
|
|
93
|
+
return nil if list.nil?
|
|
94
|
+
|
|
95
|
+
unless list.is_a?(Array) && list.length <= MAX_OBJECT_DETECTION_ENTRIES
|
|
96
|
+
raise ArgumentError, "object_detection must be an Array of at most #{MAX_OBJECT_DETECTION_ENTRIES} entries"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
list.map do |entry|
|
|
100
|
+
name = entry.is_a?(Hash) ? (entry[:object] || entry['object']) : entry
|
|
101
|
+
unless name.is_a?(String) && !name.empty? && name.length <= MAX_OBJECT_NAME_LENGTH
|
|
102
|
+
raise ArgumentError, "object_detection entries must be non-empty Strings of at most #{MAX_OBJECT_NAME_LENGTH} characters"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
{ object: name }
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
private
|
|
110
|
+
|
|
111
|
+
def validate_file_name!
|
|
112
|
+
unless @file_name.length.between?(FILENAME_MIN_LENGTH, FILENAME_MAX_LENGTH)
|
|
113
|
+
raise ArgumentError, "file_name must be #{FILENAME_MIN_LENGTH} to #{FILENAME_MAX_LENGTH} characters"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
extension = File.extname(@file_name.downcase)
|
|
117
|
+
unless VALID_EXTENSIONS.include?(extension)
|
|
118
|
+
raise ArgumentError, "Unsupported file extension: #{extension}. Supported: #{VALID_EXTENSIONS.join(', ')}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def validate_file_size!
|
|
123
|
+
max_bytes = 32 * 1024 * 1024
|
|
124
|
+
size = if @image.nil?
|
|
125
|
+
# base64 is about 4/3 of the decoded size
|
|
126
|
+
@base64.length * 3 / 4
|
|
127
|
+
elsif @image.is_a?(String)
|
|
128
|
+
@image.bytesize
|
|
129
|
+
elsif @image.respond_to?(:size)
|
|
130
|
+
@image.size
|
|
131
|
+
end
|
|
132
|
+
raise ArgumentError, 'Image size exceeds maximum limit of 32MB' if size && size >= max_bytes
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Copyleaks
|
|
2
|
+
# Webhook settings for the asynchronous detectors (AI image async submit and AI video).
|
|
3
|
+
class CopyleaksAsyncWebhooksModel
|
|
4
|
+
attr_reader :url, :headers
|
|
5
|
+
|
|
6
|
+
# @param url [String] Where Copyleaks posts the detection result.
|
|
7
|
+
# @param headers [Array<Array<String>>, nil] Added to the webhook, e.g. [['Authorization', 'Bearer my-token']].
|
|
8
|
+
def initialize(url, headers = nil)
|
|
9
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAsyncWebhooksModel - url must be a String' unless url.is_a?(String)
|
|
10
|
+
unless Utils.headers_valid?(headers)
|
|
11
|
+
raise ArgumentError, 'Copyleaks::CopyleaksAsyncWebhooksModel - headers must be an Array of [name, value] String pairs'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
@url = url
|
|
15
|
+
@headers = headers
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Accepts a CopyleaksAsyncWebhooksModel or a URL String.
|
|
19
|
+
def self.coerce(value)
|
|
20
|
+
return value if value.is_a?(CopyleaksAsyncWebhooksModel)
|
|
21
|
+
return new(value) if value.is_a?(String)
|
|
22
|
+
|
|
23
|
+
raise ArgumentError, 'webhooks must be a Copyleaks::CopyleaksAsyncWebhooksModel or a URL String'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def as_json(*_args)
|
|
27
|
+
{
|
|
28
|
+
url: @url,
|
|
29
|
+
headers: @headers
|
|
30
|
+
}.reject { |_k, v| v.nil? }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_json(*options)
|
|
34
|
+
as_json(*options).to_json(*options)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Copyleaks
|
|
2
|
+
# One object located in the image, with its run-length encoded segmentation mask.
|
|
3
|
+
class CopyleaksAiImageDetectedObjectModel
|
|
4
|
+
# The object name from the request, for example "face".
|
|
5
|
+
attr_accessor :object
|
|
6
|
+
|
|
7
|
+
# RLE mask (starts and lengths) in the coordinate space of imageInfo.shape.
|
|
8
|
+
attr_accessor :mask
|
|
9
|
+
|
|
10
|
+
def initialize(object: nil, mask: nil)
|
|
11
|
+
@object = object
|
|
12
|
+
@mask = mask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.from_json(json_hash)
|
|
16
|
+
return nil unless json_hash.is_a?(Hash)
|
|
17
|
+
|
|
18
|
+
new(
|
|
19
|
+
object: json_hash['object'],
|
|
20
|
+
mask: CopyleaksAiImageDetectionResultModel.from_json(json_hash['mask'])
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_json(*args)
|
|
25
|
+
{
|
|
26
|
+
'object' => @object,
|
|
27
|
+
'mask' => @mask ? JSON.parse(@mask.to_json) : nil
|
|
28
|
+
}.to_json(*args)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Copyleaks
|
|
4
|
+
# Information about the analyzed image.
|
|
5
|
+
class CopyleaksAiImageDetectionImageInfoModel
|
|
6
|
+
attr_accessor :shape
|
|
7
|
+
|
|
8
|
+
attr_accessor :metadata
|
|
9
|
+
|
|
10
|
+
def initialize(shape: nil, metadata: nil)
|
|
11
|
+
@shape = shape
|
|
12
|
+
@metadata = metadata
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.from_json(json_hash)
|
|
16
|
+
return nil if json_hash.nil?
|
|
17
|
+
|
|
18
|
+
shape = CopyleaksImageShapeModel.from_json(json_hash['shape']) if json_hash['shape']
|
|
19
|
+
metadata = CopyleaksImageMetadataModel.from_json(json_hash['metadata']) if json_hash['metadata']
|
|
20
|
+
|
|
21
|
+
new(shape: shape, metadata: metadata)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_json(*args)
|
|
25
|
+
{
|
|
26
|
+
'shape' => @shape ? JSON.parse(@shape.to_json) : nil,
|
|
27
|
+
'metadata' => @metadata ? JSON.parse(@metadata.to_json) : nil
|
|
28
|
+
}.to_json(*args)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Copyleaks
|
|
4
|
+
# AI image detection result.
|
|
5
|
+
class CopyleaksAiImageDetectionResponseModel
|
|
6
|
+
attr_accessor :model
|
|
7
|
+
|
|
8
|
+
attr_accessor :result
|
|
9
|
+
|
|
10
|
+
attr_accessor :summary
|
|
11
|
+
|
|
12
|
+
attr_accessor :image_info
|
|
13
|
+
|
|
14
|
+
attr_accessor :scanned_document
|
|
15
|
+
|
|
16
|
+
attr_accessor :is_ai_detected
|
|
17
|
+
|
|
18
|
+
# Present only when the request set object_detection. Look entries up by object, not by position.
|
|
19
|
+
attr_accessor :detected_objects
|
|
20
|
+
|
|
21
|
+
# Set only in the webhook of a failed asynchronous scan; the result fields are then nil. Check it first.
|
|
22
|
+
attr_accessor :error
|
|
23
|
+
|
|
24
|
+
# Echoed from the asynchronous submit request.
|
|
25
|
+
attr_accessor :developer_payload
|
|
26
|
+
|
|
27
|
+
def initialize(model: nil, result: nil, summary: nil, image_info: nil, scanned_document: nil,
|
|
28
|
+
is_ai_detected: nil, detected_objects: nil, error: nil, developer_payload: nil)
|
|
29
|
+
@model = model
|
|
30
|
+
@result = result
|
|
31
|
+
@summary = summary
|
|
32
|
+
@image_info = image_info
|
|
33
|
+
@scanned_document = scanned_document
|
|
34
|
+
@is_ai_detected = is_ai_detected
|
|
35
|
+
@detected_objects = detected_objects
|
|
36
|
+
@error = error
|
|
37
|
+
@developer_payload = developer_payload
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.from_json(json_hash)
|
|
41
|
+
return nil if json_hash.nil?
|
|
42
|
+
|
|
43
|
+
result = CopyleaksAiImageDetectionResultModel.from_json(json_hash['result']) if json_hash['result']
|
|
44
|
+
summary = CopyleaksAiImageDetectionSummaryModel.from_json(json_hash['summary']) if json_hash['summary']
|
|
45
|
+
image_info = CopyleaksAiImageDetectionImageInfoModel.from_json(json_hash['imageInfo']) if json_hash['imageInfo']
|
|
46
|
+
scanned_document = CopyleaksAiImageDetectionScannedDocumentModel.from_json(json_hash['scannedDocument']) if json_hash['scannedDocument']
|
|
47
|
+
if json_hash['detectedObjects'].is_a?(Array)
|
|
48
|
+
detected_objects = json_hash['detectedObjects'].map { |o| CopyleaksAiImageDetectedObjectModel.from_json(o) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
new(
|
|
52
|
+
model: json_hash['model'],
|
|
53
|
+
result: result,
|
|
54
|
+
summary: summary,
|
|
55
|
+
image_info: image_info,
|
|
56
|
+
scanned_document: scanned_document,
|
|
57
|
+
is_ai_detected: json_hash['isAiDetected'],
|
|
58
|
+
detected_objects: detected_objects,
|
|
59
|
+
error: Error.from_json(json_hash['error']),
|
|
60
|
+
developer_payload: json_hash['developerPayload']
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def to_json(*args)
|
|
65
|
+
hash = {
|
|
66
|
+
'model' => @model,
|
|
67
|
+
'result' => @result ? JSON.parse(@result.to_json) : nil,
|
|
68
|
+
'summary' => @summary ? JSON.parse(@summary.to_json) : nil,
|
|
69
|
+
'imageInfo' => @image_info ? JSON.parse(@image_info.to_json) : nil,
|
|
70
|
+
'scannedDocument' => @scanned_document ? JSON.parse(@scanned_document.to_json) : nil
|
|
71
|
+
}
|
|
72
|
+
hash['isAiDetected'] = @is_ai_detected unless @is_ai_detected.nil?
|
|
73
|
+
hash['detectedObjects'] = @detected_objects.map { |o| JSON.parse(o.to_json) } unless @detected_objects.nil?
|
|
74
|
+
hash['error'] = JSON.parse(@error.to_json) unless @error.nil?
|
|
75
|
+
hash['developerPayload'] = @developer_payload unless @developer_payload.nil?
|
|
76
|
+
hash.to_json(*args)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Copyleaks
|
|
4
|
+
# RLE-encoded mask data for AI-detected regions.
|
|
5
|
+
class CopyleaksAiImageDetectionResultModel
|
|
6
|
+
# Start of each AI-detected segment in the flattened image array.
|
|
7
|
+
attr_accessor :starts
|
|
8
|
+
|
|
9
|
+
# Aligned with starts.
|
|
10
|
+
attr_accessor :lengths
|
|
11
|
+
|
|
12
|
+
# Heatmap mask only: one confidence band per segment, 0 (lowest) to 4 (highest). nil for the binary mask.
|
|
13
|
+
attr_accessor :labels
|
|
14
|
+
|
|
15
|
+
def initialize(starts: nil, lengths: nil, labels: nil)
|
|
16
|
+
@starts = starts
|
|
17
|
+
@lengths = lengths
|
|
18
|
+
@labels = labels
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.from_json(json_hash)
|
|
22
|
+
return nil if json_hash.nil?
|
|
23
|
+
|
|
24
|
+
new(
|
|
25
|
+
starts: json_hash['starts'],
|
|
26
|
+
lengths: json_hash['lengths'],
|
|
27
|
+
labels: json_hash['labels']
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_json(*args)
|
|
32
|
+
hash = {
|
|
33
|
+
'starts' => @starts,
|
|
34
|
+
'lengths' => @lengths
|
|
35
|
+
}
|
|
36
|
+
hash['labels'] = @labels unless @labels.nil?
|
|
37
|
+
hash.to_json(*args)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionScannedDocumentModel.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Copyleaks
|
|
4
|
+
# Metadata about the AI image detection scan operation.
|
|
5
|
+
class CopyleaksAiImageDetectionScannedDocumentModel
|
|
6
|
+
attr_accessor :scan_id
|
|
7
|
+
|
|
8
|
+
attr_accessor :actual_credits
|
|
9
|
+
|
|
10
|
+
attr_accessor :expected_credits
|
|
11
|
+
|
|
12
|
+
# ISO 8601 timestamp.
|
|
13
|
+
attr_accessor :creation_time
|
|
14
|
+
|
|
15
|
+
def initialize(scan_id: nil, actual_credits: nil, expected_credits: nil, creation_time: nil)
|
|
16
|
+
@scan_id = scan_id
|
|
17
|
+
@actual_credits = actual_credits
|
|
18
|
+
@expected_credits = expected_credits
|
|
19
|
+
@creation_time = creation_time
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.from_json(json_hash)
|
|
23
|
+
return nil unless json_hash.is_a?(Hash)
|
|
24
|
+
|
|
25
|
+
new(
|
|
26
|
+
scan_id: json_hash['scanId'],
|
|
27
|
+
actual_credits: json_hash['actualCredits'],
|
|
28
|
+
expected_credits: json_hash['expectedCredits'],
|
|
29
|
+
creation_time: json_hash['creationTime']
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def as_json(*_args)
|
|
34
|
+
{
|
|
35
|
+
'scanId' => @scan_id,
|
|
36
|
+
'actualCredits' => @actual_credits,
|
|
37
|
+
'expectedCredits' => @expected_credits,
|
|
38
|
+
'creationTime' => @creation_time
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def to_json(*args)
|
|
43
|
+
as_json.to_json(*args)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Copyleaks
|
|
4
|
+
# Summary statistics of the AI detection analysis.
|
|
5
|
+
class CopyleaksAiImageDetectionSummaryModel
|
|
6
|
+
# Share of pixels suspected to be human-created, 0.0-1.0.
|
|
7
|
+
attr_accessor :human
|
|
8
|
+
|
|
9
|
+
# Share of pixels suspected to be AI-generated, 0.0-1.0.
|
|
10
|
+
attr_accessor :ai
|
|
11
|
+
|
|
12
|
+
def initialize(human: nil, ai: nil)
|
|
13
|
+
@human = human
|
|
14
|
+
@ai = ai
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.from_json(json_hash)
|
|
18
|
+
return nil if json_hash.nil?
|
|
19
|
+
|
|
20
|
+
new(
|
|
21
|
+
human: json_hash['human'],
|
|
22
|
+
ai: json_hash['ai']
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_json(*args)
|
|
27
|
+
{
|
|
28
|
+
'human' => @human,
|
|
29
|
+
'ai' => @ai
|
|
30
|
+
}.to_json(*args)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Copyleaks
|
|
4
|
+
# Optional metadata extracted from the image.
|
|
5
|
+
class CopyleaksImageMetadataModel
|
|
6
|
+
# When the image was created, if available.
|
|
7
|
+
attr_accessor :issued_time
|
|
8
|
+
|
|
9
|
+
# The AI service or tool that created the image, if detected.
|
|
10
|
+
attr_accessor :issued_by
|
|
11
|
+
|
|
12
|
+
attr_accessor :app_or_device_used
|
|
13
|
+
|
|
14
|
+
# How the image was generated, if available.
|
|
15
|
+
attr_accessor :content_summary
|
|
16
|
+
|
|
17
|
+
def initialize(issued_time: nil, issued_by: nil, app_or_device_used: nil, content_summary: nil)
|
|
18
|
+
@issued_time = issued_time
|
|
19
|
+
@issued_by = issued_by
|
|
20
|
+
@app_or_device_used = app_or_device_used
|
|
21
|
+
@content_summary = content_summary
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.from_json(json_hash)
|
|
25
|
+
return nil unless json_hash.is_a?(Hash)
|
|
26
|
+
|
|
27
|
+
new(
|
|
28
|
+
issued_time: json_hash['issuedTime'],
|
|
29
|
+
issued_by: json_hash['issuedBy'],
|
|
30
|
+
app_or_device_used: json_hash['appOrDeviceUsed'],
|
|
31
|
+
content_summary: json_hash['contentSummary']
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def to_json(*args)
|
|
36
|
+
hash = {
|
|
37
|
+
'issuedTime' => @issued_time,
|
|
38
|
+
'issuedBy' => @issued_by,
|
|
39
|
+
'appOrDeviceUsed' => @app_or_device_used
|
|
40
|
+
}
|
|
41
|
+
hash['contentSummary'] = @content_summary unless @content_summary.nil?
|
|
42
|
+
hash.to_json(*args)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Copyleaks
|
|
4
|
+
# Dimensions of the analyzed image, in pixels.
|
|
5
|
+
class CopyleaksImageShapeModel
|
|
6
|
+
attr_accessor :height
|
|
7
|
+
|
|
8
|
+
attr_accessor :width
|
|
9
|
+
|
|
10
|
+
def initialize(height: nil, width: nil)
|
|
11
|
+
@height = height
|
|
12
|
+
@width = width
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.from_json(json_hash)
|
|
16
|
+
return nil if json_hash.nil?
|
|
17
|
+
|
|
18
|
+
new(
|
|
19
|
+
height: json_hash['height'],
|
|
20
|
+
width: json_hash['width']
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_json(*args)
|
|
25
|
+
{
|
|
26
|
+
'height' => @height,
|
|
27
|
+
'width' => @width
|
|
28
|
+
}.to_json(*args)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Copyleaks
|
|
2
|
+
# Request model for the Image Plagiarism Detector. The image is uploaded as multipart/form-data.
|
|
3
|
+
class CopyleaksImagePlagiarismRequestModel
|
|
4
|
+
FILENAME_MAX_LENGTH = 255
|
|
5
|
+
|
|
6
|
+
attr_reader :image, :filename, :sandbox, :developer_payload
|
|
7
|
+
|
|
8
|
+
# @param image [String, IO] Raw bytes, e.g. File.binread(path), or an IO. Under 20 MB, at most 75 megapixels;
|
|
9
|
+
# JPG, JPEG, PNG, GIF, BMP, WebP or ICO.
|
|
10
|
+
# @param filename [String] With extension, at most 255 characters.
|
|
11
|
+
# @param sandbox [Boolean, nil] Free mock results. Server default: false.
|
|
12
|
+
# @param developer_payload [String, nil] Echoed back in the response.
|
|
13
|
+
def initialize(image:, filename:, sandbox: nil, developer_payload: nil)
|
|
14
|
+
unless image.is_a?(String) || image.respond_to?(:read)
|
|
15
|
+
raise ArgumentError, 'Copyleaks::CopyleaksImagePlagiarismRequestModel - image must be a binary String or an IO'
|
|
16
|
+
end
|
|
17
|
+
unless filename.is_a?(String) && !filename.empty?
|
|
18
|
+
raise ArgumentError, 'Copyleaks::CopyleaksImagePlagiarismRequestModel - filename must be a non-empty String'
|
|
19
|
+
end
|
|
20
|
+
if filename.length > FILENAME_MAX_LENGTH
|
|
21
|
+
raise ArgumentError, "Copyleaks::CopyleaksImagePlagiarismRequestModel - filename must be at most #{FILENAME_MAX_LENGTH} characters"
|
|
22
|
+
end
|
|
23
|
+
if !sandbox.nil? && ![true, false].include?(sandbox)
|
|
24
|
+
raise ArgumentError, 'Copyleaks::CopyleaksImagePlagiarismRequestModel - sandbox must be a Boolean'
|
|
25
|
+
end
|
|
26
|
+
if !developer_payload.nil? && !developer_payload.is_a?(String)
|
|
27
|
+
raise ArgumentError, 'Copyleaks::CopyleaksImagePlagiarismRequestModel - developer_payload must be a String'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
@image = image
|
|
31
|
+
@filename = filename
|
|
32
|
+
@sandbox = sandbox
|
|
33
|
+
@developer_payload = developer_payload
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Always true.
|
|
37
|
+
def multipart?
|
|
38
|
+
true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return [Copyleaks::MultipartForm] Fields: image (file), filename, sandbox, developerPayload.
|
|
42
|
+
def to_multipart
|
|
43
|
+
form = MultipartForm.new
|
|
44
|
+
form.add_file('image', @image, @filename)
|
|
45
|
+
form.add_field('filename', @filename)
|
|
46
|
+
form.add_field('sandbox', @sandbox) unless @sandbox.nil?
|
|
47
|
+
form.add_field('developerPayload', @developer_payload) unless @developer_payload.nil?
|
|
48
|
+
form
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|