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.
Files changed (157) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/CHANGELOG.md +102 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +487 -0
  7. data/Rakefile +13 -0
  8. data/bin/console +11 -0
  9. data/bin/setup +8 -0
  10. data/lib/copyleaks/ai_detection_client.rb +27 -0
  11. data/lib/copyleaks/ai_image_detection_client.rb +35 -0
  12. data/lib/copyleaks/ai_video_detection_client.rb +20 -0
  13. data/lib/copyleaks/api.rb +247 -0
  14. data/lib/copyleaks/app.config.rb +36 -0
  15. data/lib/copyleaks/image_plagiarism_client.rb +19 -0
  16. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionExplainModel.rb +26 -0
  17. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionMatchModel.rb +33 -0
  18. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionMatchTextModel.rb +31 -0
  19. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionPatternMatchModel.rb +32 -0
  20. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionPatternStatisticsModel.rb +46 -0
  21. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionPatternsModel.rb +38 -0
  22. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionPositionsModel.rb +39 -0
  23. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionResponseModel.rb +68 -0
  24. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionResultModel.rb +41 -0
  25. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionScannedDocumentModel.rb +21 -0
  26. data/lib/copyleaks/models/aiDetection/responses/CopyleaksAiTextDetectionSummaryModel.rb +34 -0
  27. data/lib/copyleaks/models/auth_token.rb +46 -0
  28. data/lib/copyleaks/models/constants/CopyleaksAiImageDetectionModels.rb +5 -0
  29. data/lib/copyleaks/models/constants/CopyleaksAiImageMaskTypes.rb +11 -0
  30. data/lib/copyleaks/models/constants/CopyleaksAiVideoDetectionModels.rb +5 -0
  31. data/lib/copyleaks/models/constants/CopyleaksAlertCodes.rb +7 -0
  32. data/lib/copyleaks/models/constants/CopyleaksTextModerationConstants.rb +15 -0
  33. data/lib/copyleaks/models/constants/CopyleaksTextModerationLanguages.rb +6 -0
  34. data/lib/copyleaks/models/constants/index.rb +10 -0
  35. data/lib/copyleaks/models/delete_request_model.rb +50 -0
  36. data/lib/copyleaks/models/exceptions/auth_expired_exception.rb +7 -0
  37. data/lib/copyleaks/models/exceptions/command_exception.rb +13 -0
  38. data/lib/copyleaks/models/exceptions/copyleaks_api_exception.rb +18 -0
  39. data/lib/copyleaks/models/exceptions/index.rb +8 -0
  40. data/lib/copyleaks/models/exceptions/rate_limit_exception.rb +8 -0
  41. data/lib/copyleaks/models/exceptions/under_maintenance_exception.rb +8 -0
  42. data/lib/copyleaks/models/exports/export_crawled_version.rb +6 -0
  43. data/lib/copyleaks/models/exports/export_model.rb +87 -0
  44. data/lib/copyleaks/models/exports/export_pdf_report.rb +6 -0
  45. data/lib/copyleaks/models/exports/export_results.rb +30 -0
  46. data/lib/copyleaks/models/exports/export_target.rb +42 -0
  47. data/lib/copyleaks/models/exports/index.rb +8 -0
  48. data/lib/copyleaks/models/id_object.rb +22 -0
  49. data/lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionAsyncRequestModel.rb +63 -0
  50. data/lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb +135 -0
  51. data/lib/copyleaks/models/imageDetection/requests/CopyleaksAsyncWebhooksModel.rb +37 -0
  52. data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectedObjectModel.rb +31 -0
  53. data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionImageInfoModel.rb +31 -0
  54. data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionResponseModel.rb +79 -0
  55. data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionResultModel.rb +40 -0
  56. data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionScannedDocumentModel.rb +46 -0
  57. data/lib/copyleaks/models/imageDetection/responses/CopyleaksAiImageDetectionSummaryModel.rb +33 -0
  58. data/lib/copyleaks/models/imageDetection/responses/CopyleaksImageMetadataModel.rb +45 -0
  59. data/lib/copyleaks/models/imageDetection/responses/CopyleaksImageShapeModel.rb +31 -0
  60. data/lib/copyleaks/models/imagePlagiarism/requests/CopyleaksImagePlagiarismRequestModel.rb +51 -0
  61. data/lib/copyleaks/models/imagePlagiarism/responses/CopyleaksImagePlagiarismResponseModel.rb +187 -0
  62. data/lib/copyleaks/models/index.rb +51 -0
  63. data/lib/copyleaks/models/start_request_model.rb +40 -0
  64. data/lib/copyleaks/models/submissions/ai_detection/ai_detection_submission_model.rb +25 -0
  65. data/lib/copyleaks/models/submissions/ai_detection/natural_language_submission_model.rb +41 -0
  66. data/lib/copyleaks/models/submissions/file_ocr_submission_model.rb +36 -0
  67. data/lib/copyleaks/models/submissions/file_submission_model.rb +35 -0
  68. data/lib/copyleaks/models/submissions/index.rb +16 -0
  69. data/lib/copyleaks/models/submissions/properties/actions.rb +10 -0
  70. data/lib/copyleaks/models/submissions/properties/ai_generated_text.rb +40 -0
  71. data/lib/copyleaks/models/submissions/properties/ai_generated_text_explain.rb +6 -0
  72. data/lib/copyleaks/models/submissions/properties/ai_source_match.rb +6 -0
  73. data/lib/copyleaks/models/submissions/properties/assignment.rb +6 -0
  74. data/lib/copyleaks/models/submissions/properties/author.rb +18 -0
  75. data/lib/copyleaks/models/submissions/properties/copyleaks_db.rb +22 -0
  76. data/lib/copyleaks/models/submissions/properties/course.rb +6 -0
  77. data/lib/copyleaks/models/submissions/properties/cross_languages.rb +21 -0
  78. data/lib/copyleaks/models/submissions/properties/custom_metadata.rb +19 -0
  79. data/lib/copyleaks/models/submissions/properties/domains_mode.rb +8 -0
  80. data/lib/copyleaks/models/submissions/properties/enable_flag.rb +26 -0
  81. data/lib/copyleaks/models/submissions/properties/exclude.rb +57 -0
  82. data/lib/copyleaks/models/submissions/properties/exclude_code.rb +19 -0
  83. data/lib/copyleaks/models/submissions/properties/filter.rb +49 -0
  84. data/lib/copyleaks/models/submissions/properties/index.rb +43 -0
  85. data/lib/copyleaks/models/submissions/properties/indexing.rb +25 -0
  86. data/lib/copyleaks/models/submissions/properties/indexing_repository.rb +26 -0
  87. data/lib/copyleaks/models/submissions/properties/institution.rb +6 -0
  88. data/lib/copyleaks/models/submissions/properties/internal_ai_source_match.rb +7 -0
  89. data/lib/copyleaks/models/submissions/properties/language.rb +18 -0
  90. data/lib/copyleaks/models/submissions/properties/masking_policy.rb +11 -0
  91. data/lib/copyleaks/models/submissions/properties/overview.rb +42 -0
  92. data/lib/copyleaks/models/submissions/properties/pdf_colors.rb +48 -0
  93. data/lib/copyleaks/models/submissions/properties/pdf_properties.rb +51 -0
  94. data/lib/copyleaks/models/submissions/properties/pdf_report_version.rb +9 -0
  95. data/lib/copyleaks/models/submissions/properties/pdf_version.rb +10 -0
  96. data/lib/copyleaks/models/submissions/properties/references.rb +26 -0
  97. data/lib/copyleaks/models/submissions/properties/repository.rb +18 -0
  98. data/lib/copyleaks/models/submissions/properties/scan_method_algorithm.rb +8 -0
  99. data/lib/copyleaks/models/submissions/properties/scanning.rb +44 -0
  100. data/lib/copyleaks/models/submissions/properties/scanning_exclude.rb +47 -0
  101. data/lib/copyleaks/models/submissions/properties/scanning_include.rb +25 -0
  102. data/lib/copyleaks/models/submissions/properties/scanning_repository.rb +23 -0
  103. data/lib/copyleaks/models/submissions/properties/sensitive_data_protection.rb +42 -0
  104. data/lib/copyleaks/models/submissions/properties/submission_properties.rb +179 -0
  105. data/lib/copyleaks/models/submissions/properties/webhooks.rb +42 -0
  106. data/lib/copyleaks/models/submissions/properties/writing_feedback.rb +30 -0
  107. data/lib/copyleaks/models/submissions/submission_model.rb +24 -0
  108. data/lib/copyleaks/models/submissions/url_submission_model.rb +41 -0
  109. data/lib/copyleaks/models/submissions/webhooks/CompletedWebhook.rb +67 -0
  110. data/lib/copyleaks/models/submissions/webhooks/CreditsCheckedWebhook.rb +24 -0
  111. data/lib/copyleaks/models/submissions/webhooks/ErrorWebhook.rb +22 -0
  112. data/lib/copyleaks/models/submissions/webhooks/ExportCompletedWebhook.rb +25 -0
  113. data/lib/copyleaks/models/submissions/webhooks/HelperModels/BaseModels/Metadata.rb +61 -0
  114. data/lib/copyleaks/models/submissions/webhooks/HelperModels/BaseModels/StatusWebhook.rb +23 -0
  115. data/lib/copyleaks/models/submissions/webhooks/HelperModels/BaseModels/Webhook.rb +25 -0
  116. data/lib/copyleaks/models/submissions/webhooks/HelperModels/CompletedModels/Notifications.rb +24 -0
  117. data/lib/copyleaks/models/submissions/webhooks/HelperModels/CompletedModels/Results.rb +54 -0
  118. data/lib/copyleaks/models/submissions/webhooks/HelperModels/CompletedModels/ScannedDocument.rb +36 -0
  119. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ErrorModels/Error.rb +49 -0
  120. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ExportModels/Task.rb +29 -0
  121. data/lib/copyleaks/models/submissions/webhooks/HelperModels/NewResultsModels/NewResultScore.rb +22 -0
  122. data/lib/copyleaks/models/submissions/webhooks/HelperModels/NewResultsModels/NewResultsInternet.rb +37 -0
  123. data/lib/copyleaks/models/submissions/webhooks/HelperModels/NewResultsModels/NewResultsRepositories.rb +28 -0
  124. data/lib/copyleaks/models/submissions/webhooks/HelperModels/NotificationsModels/Alerts.rb +91 -0
  125. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Batch.rb +26 -0
  126. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Database.rb +26 -0
  127. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Internet.rb +23 -0
  128. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Repositories.rb +36 -0
  129. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/RepositoryMetadata.rb +11 -0
  130. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Score.rb +20 -0
  131. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/SharedResultsModel.rb +22 -0
  132. data/lib/copyleaks/models/submissions/webhooks/HelperModels/ResultsModels/Tags.rb +12 -0
  133. data/lib/copyleaks/models/submissions/webhooks/IndexedWebhook.rb +9 -0
  134. data/lib/copyleaks/models/submissions/webhooks/NewResultWebhook.rb +32 -0
  135. data/lib/copyleaks/models/submissions/webhooks/index.rb +34 -0
  136. data/lib/copyleaks/models/submissions/writing_assistant/score_weights.rb +26 -0
  137. data/lib/copyleaks/models/submissions/writing_assistant/writing_assistant_submission_model.rb +32 -0
  138. data/lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationLabel.rb +21 -0
  139. data/lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb +45 -0
  140. data/lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb +55 -0
  141. data/lib/copyleaks/models/textModeration/responses/submodules/ModerationsModel.rb +27 -0
  142. data/lib/copyleaks/models/textModeration/responses/submodules/Text.rb +27 -0
  143. data/lib/copyleaks/models/textModeration/responses/submodules/TextModerationChars.rb +32 -0
  144. data/lib/copyleaks/models/textModeration/responses/submodules/TextModerationScannedDocument.rb +55 -0
  145. data/lib/copyleaks/models/textModeration/responses/submodules/TextModerationsLegend.rb +29 -0
  146. data/lib/copyleaks/models/videoDetection/requests/CopyleaksAiVideoDetectionRequestModel.rb +61 -0
  147. data/lib/copyleaks/models/videoDetection/responses/CopyleaksAiVideoDetectionResponseModel.rb +177 -0
  148. data/lib/copyleaks/text_moderation_client.rb +18 -0
  149. data/lib/copyleaks/utils/copyleaks_client.utils.rb +101 -0
  150. data/lib/copyleaks/utils/http_client.rb +164 -0
  151. data/lib/copyleaks/utils/multipart.rb +86 -0
  152. data/lib/copyleaks/utils/status-code.utils.rb +23 -0
  153. data/lib/copyleaks/version.rb +3 -0
  154. data/lib/copyleaks/writing_assistant_client.rb +26 -0
  155. data/lib/copyleaks.rb +11 -0
  156. data/lib/index.rb +4 -0
  157. metadata +248 -0
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Copyleaks
4
+ # Start positions and lengths of text segments.
5
+ class CopyleaksAiTextDetectionPositionsModel
6
+ attr_accessor :starts
7
+
8
+ # Aligned with starts.
9
+ attr_accessor :lengths
10
+
11
+ # Present only for HTML positions.
12
+ attr_accessor :group_ids
13
+
14
+ def initialize(starts: nil, lengths: nil, group_ids: nil)
15
+ @starts = starts
16
+ @lengths = lengths
17
+ @group_ids = group_ids
18
+ end
19
+
20
+ # Accepts camelCase and PascalCase keys; sandbox scans send PascalCase.
21
+ def self.from_json(json_hash)
22
+ return nil unless json_hash.is_a?(Hash)
23
+
24
+ new(
25
+ starts: json_hash.key?('starts') ? json_hash['starts'] : json_hash['Starts'],
26
+ lengths: json_hash.key?('lengths') ? json_hash['lengths'] : json_hash['Lengths'],
27
+ group_ids: json_hash.key?('groupIds') ? json_hash['groupIds'] : json_hash['GroupIds']
28
+ )
29
+ end
30
+
31
+ def to_json(*args)
32
+ {
33
+ 'starts' => @starts,
34
+ 'lengths' => @lengths,
35
+ 'groupIds' => @group_ids
36
+ }.compact.to_json(*args)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Copyleaks
4
+ # AI text detection result.
5
+ # This is the object carried, as a JSON string, in the additionalData of the
6
+ # 'suspected-ai-text' alert of the completed webhook.
7
+ class CopyleaksAiTextDetectionResponseModel
8
+ attr_accessor :model_version
9
+
10
+ # The classified sections of the text.
11
+ attr_accessor :results
12
+
13
+ attr_accessor :summary
14
+
15
+ # Machine translation to English: 0 = none, 1 = Google Translate, 2 = Helsinki, 3 = Azure.
16
+ attr_accessor :translation_provider
17
+
18
+ # The full English translation. Present only when the text was machine-translated.
19
+ attr_accessor :translation
20
+
21
+ # AI Logic explanation. Present only when AI Logic (explain) was enabled.
22
+ attr_accessor :explain
23
+
24
+ attr_accessor :scanned_document
25
+
26
+ def initialize(model_version: nil, results: nil, summary: nil, translation_provider: nil, translation: nil, explain: nil,
27
+ scanned_document: nil)
28
+ @model_version = model_version
29
+ @results = results
30
+ @summary = summary
31
+ @translation_provider = translation_provider
32
+ @translation = translation
33
+ @explain = explain
34
+ @scanned_document = scanned_document
35
+ end
36
+
37
+ # Unknown fields are ignored; missing fields are left nil.
38
+ def self.from_json(json_hash)
39
+ return nil unless json_hash.is_a?(Hash)
40
+
41
+ results = json_hash['results'].map { |r| CopyleaksAiTextDetectionResultModel.from_json(r) } if json_hash['results'].is_a?(Array)
42
+ summary = CopyleaksAiTextDetectionSummaryModel.from_json(json_hash['summary']) if json_hash['summary']
43
+ explain = CopyleaksAiTextDetectionExplainModel.from_json(json_hash['explain']) if json_hash['explain']
44
+
45
+ new(
46
+ model_version: json_hash['modelVersion'],
47
+ results: results,
48
+ summary: summary,
49
+ translation_provider: json_hash['translationProvider'],
50
+ translation: json_hash['translation'],
51
+ explain: explain,
52
+ scanned_document: CopyleaksAiTextDetectionScannedDocumentModel.from_json(json_hash['scannedDocument'])
53
+ )
54
+ end
55
+
56
+ def to_json(*args)
57
+ {
58
+ 'modelVersion' => @model_version,
59
+ 'results' => @results,
60
+ 'summary' => @summary,
61
+ 'translationProvider' => @translation_provider,
62
+ 'translation' => @translation,
63
+ 'explain' => @explain,
64
+ 'scannedDocument' => @scanned_document
65
+ }.compact.to_json(*args)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Copyleaks
4
+ # A classified section of the text.
5
+ class CopyleaksAiTextDetectionResultModel
6
+ # 1 = human-written, 2 = AI-generated.
7
+ attr_accessor :classification
8
+
9
+ # Deprecated by the server; planned for removal.
10
+ attr_accessor :probability
11
+
12
+ # Positions of the text in this section.
13
+ attr_accessor :matches
14
+
15
+ def initialize(classification: nil, probability: nil, matches: nil)
16
+ @classification = classification
17
+ @probability = probability
18
+ @matches = matches
19
+ end
20
+
21
+ def self.from_json(json_hash)
22
+ return nil unless json_hash.is_a?(Hash)
23
+
24
+ matches = json_hash['matches'].map { |m| CopyleaksAiTextDetectionMatchModel.from_json(m) } if json_hash['matches'].is_a?(Array)
25
+
26
+ new(
27
+ classification: json_hash['classification'],
28
+ probability: json_hash['probability'],
29
+ matches: matches
30
+ )
31
+ end
32
+
33
+ def to_json(*args)
34
+ {
35
+ 'classification' => @classification,
36
+ 'probability' => @probability,
37
+ 'matches' => @matches
38
+ }.compact.to_json(*args)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../textModeration/responses/submodules/TextModerationScannedDocument.rb'
2
+
3
+ module Copyleaks
4
+ # Metadata about an AI Text Detection scan. Unlike the base class, fields default to nil, creation_time stays
5
+ # the ISO 8601 String, and unset fields are left out of the JSON.
6
+ class CopyleaksAiTextDetectionScannedDocumentModel < TextModerationScannedDocument
7
+ def initialize(scan_id: nil, total_words: nil, total_excluded: nil, actual_credits: nil, expected_credits: nil,
8
+ creation_time: nil)
9
+ super
10
+ end
11
+
12
+ def self.parse_creation_time(value)
13
+ value
14
+ end
15
+ private_class_method :parse_creation_time
16
+
17
+ def as_json(*_args)
18
+ super.compact
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Copyleaks
4
+ # Summary of the AI text detection analysis.
5
+ class CopyleaksAiTextDetectionSummaryModel
6
+ # Share of the text classified as human-written, 0.0-1.0.
7
+ attr_accessor :human
8
+
9
+ # Share of the text classified as 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
+ # Accepts camelCase and PascalCase keys; sandbox scans send PascalCase.
18
+ def self.from_json(json_hash)
19
+ return nil unless json_hash.is_a?(Hash)
20
+
21
+ new(
22
+ human: json_hash.key?('human') ? json_hash['human'] : json_hash['Human'],
23
+ ai: json_hash.key?('ai') ? json_hash['ai'] : json_hash['Ai']
24
+ )
25
+ end
26
+
27
+ def to_json(*args)
28
+ {
29
+ 'human' => @human,
30
+ 'ai' => @ai
31
+ }.compact.to_json(*args)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ require 'date'
2
+
3
+ module Copyleaks
4
+ class CopyleaksAuthToken
5
+ # A token this close to its expiry time is treated as expired, so it cannot expire mid-request.
6
+ EXPIRY_MARGIN_SECONDS = 5 * 60
7
+
8
+ attr_reader :expires, :accessToken, :issued
9
+
10
+ def initialize(expires, accessToken, issued)
11
+ unless expires.instance_of?(String)
12
+ raise 'Copyleaks::CopyleaksAuthToken - expires - expires must be of type String'
13
+ end
14
+ unless accessToken.instance_of?(String)
15
+ raise 'Copyleaks::CopyleaksAuthToken - accessToken - accessToken must be of type String'
16
+ end
17
+ raise 'Copyleaks::CopyleaksAuthToken - issued - issued must be of type String' unless issued.instance_of?(String)
18
+
19
+ @expires = expires
20
+ @accessToken = accessToken
21
+ @issued = issued
22
+ end
23
+
24
+ # The expiry time as a Time. Parsed once and cached.
25
+ def expires_at
26
+ @expires_at ||= DateTime.parse(@expires).to_time
27
+ end
28
+
29
+ # True when the token has expired, or expires within margin_seconds.
30
+ def expired?(margin_seconds = EXPIRY_MARGIN_SECONDS)
31
+ expires_at - margin_seconds <= Time.now
32
+ end
33
+
34
+ def as_json(*_args)
35
+ {
36
+ expires: @expires,
37
+ issued: @issued,
38
+ accessToken: @accessToken
39
+ }.select { |_k, v| !v.nil? }
40
+ end
41
+
42
+ def to_json(*options)
43
+ as_json(*options).to_json(*options)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Copyleaks
2
+ class CopyleaksAiImageDetectionModels
3
+ AI_IMAGE_1_ULTRA = "ai-image-1-ultra"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Copyleaks
2
+ # Values of maskType for AI image detection.
3
+ class CopyleaksAiImageMaskTypes
4
+ # Run-length encoded mask of the regions flagged as AI-generated (server default).
5
+ BINARY = "binary"
6
+ # Like BINARY, plus result.labels: one confidence band (0-4) per segment.
7
+ HEATMAP = "heatmap"
8
+ # No mask: the response has no result object. Synchronous check only.
9
+ NONE = "none"
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Copyleaks
2
+ class CopyleaksAiVideoDetectionModels
3
+ AI_VIDEO_1_PRO = "ai-video-1-pro"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Copyleaks
2
+ # Case-sensitive scan alert codes of the completed webhook (notifications.alerts[].code).
3
+ class CopyleaksAlertCodes
4
+ # AI-generated text was detected (category 2, severity 4). Read additionalData with Alerts#ai_detection_result.
5
+ SUSPECTED_AI_TEXT = "suspected-ai-text"
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module Copyleaks
2
+ # Text moderation categories.
3
+ class CopyleaksTextModerationConstants
4
+ ADULT_V1 = "adult-v1"
5
+ TOXIC_V1 = "toxic-v1"
6
+ VIOLENT_V1 = "violent-v1"
7
+ PROFANITY_V1 = "profanity-v1"
8
+ SELF_HARM_V1 = "self-harm-v1"
9
+ HARASSMENT_V1 = "harassment-v1"
10
+ HATE_SPEECH_V1 = "hate-speech-v1"
11
+ DRUGS_V1 = "drugs-v1"
12
+ FIREARMS_V1 = "firearms-v1"
13
+ CYBERSECURITY_V1 = "cybersecurity-v1"
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Copyleaks
2
+ # Languages supported by text moderation.
3
+ class CopyleaksTextModerationLanguages
4
+ ENGLISH = "en"
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'CopyleaksTextModerationConstants.rb'
2
+ require_relative 'CopyleaksTextModerationLanguages.rb'
3
+ require_relative 'CopyleaksAiImageDetectionModels.rb'
4
+ require_relative 'CopyleaksAiImageMaskTypes.rb'
5
+ require_relative 'CopyleaksAiVideoDetectionModels.rb'
6
+ require_relative 'CopyleaksAlertCodes.rb'
7
+
8
+
9
+ module Copyleaks
10
+ end
@@ -0,0 +1,50 @@
1
+ require 'json'
2
+ module Copyleaks
3
+ class CopyleaksDeleteRequestModel
4
+ attr_reader :scans, :purge, :completionWebhook, :headers
5
+
6
+ # @param [Array] scans IdObject items.
7
+ # @param [Boolean] purge Remove every trace of the scans, including from the internal database, so they are no
8
+ # longer found as results of other scans. Server default: false.
9
+ # @param [String] completionWebhook Called with a POST and no body once the deletion is complete.
10
+ # @param [Array<Array<String>>] headers For the completion webhook, e.g. [['Authorization', 'Bearer my-token']].
11
+ def initialize(scans, purge = nil, completionWebhook = nil, headers: nil)
12
+ scans.each do |object_id|
13
+ unless object_id.instance_of?(IdObject)
14
+ raise 'Copyleaks::CopyleaksDeleteRequestModel - scans - entity must be of type Copyleaks::IdObject'
15
+ end
16
+ end
17
+
18
+ unless purge.nil? || [true, false].include?(purge)
19
+ raise 'Copyleaks::CopyleaksDeleteRequestModel - purge - purge must be of type Boolean'
20
+ end
21
+
22
+ unless completionWebhook.nil? || completionWebhook.instance_of?(String)
23
+ raise 'Copyleaks::CopyleaksDeleteRequestModel - completionWebhook - completionWebhook must be of type String'
24
+ end
25
+
26
+ unless Utils.headers_valid?(headers)
27
+ raise 'Copyleaks::CopyleaksDeleteRequestModel - headers - headers must be an Array of String Array pairs'
28
+ end
29
+
30
+ @scans = scans
31
+ @purge = purge
32
+ # An empty webhook URL means "no webhook": leave it out of the request.
33
+ @completionWebhook = completionWebhook == '' ? nil : completionWebhook
34
+ @headers = headers
35
+ end
36
+
37
+ def as_json(*_args)
38
+ {
39
+ scans: @scans.map { |object_id| object_id.as_json },
40
+ purge: @purge,
41
+ completionWebhook: @completionWebhook,
42
+ headers: @headers
43
+ }.select { |_k, v| !v.nil? }
44
+ end
45
+
46
+ def to_json(*options)
47
+ as_json(*options).to_json(*options)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ module Copyleaks
2
+ class AuthExpiredException < RuntimeError
3
+ def initialize
4
+ super 'Authentication Expired. Need to login again'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module Copyleaks
2
+ class CommandException < CopyleaksApiException
3
+ def initialize(response:, used_by:)
4
+ @used_by = used_by
5
+
6
+ message = "---------Copyleaks SDK Error (#{used_by})---------\n\n"
7
+ message += "status code: #{response.code}\n\n"
8
+ message += "response body:\n#{response.body.to_json}\n\n" unless response.body.nil?
9
+ message += "-------------------------------------\n"
10
+ super(message, response)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module Copyleaks
2
+ # An error response from the Copyleaks API. Rescue it to handle CommandException, RateLimitException and
3
+ # UnderMaintenanceException together.
4
+ class CopyleaksApiException < RuntimeError
5
+ # The HTTP response, or nil when the exception was raised without one.
6
+ attr_reader :response
7
+
8
+ def initialize(message, response = nil)
9
+ @response = response
10
+ super(message)
11
+ end
12
+
13
+ # The value of the Retry-After response header, or nil when the server did not send one.
14
+ def retry_after
15
+ @response.nil? ? nil : @response['Retry-After']
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'copyleaks_api_exception.rb'
2
+ require_relative 'auth_expired_exception.rb'
3
+ require_relative 'command_exception.rb'
4
+ require_relative 'rate_limit_exception.rb'
5
+ require_relative 'under_maintenance_exception.rb'
6
+
7
+ module Copyleaks
8
+ end
@@ -0,0 +1,8 @@
1
+ module Copyleaks
2
+ # HTTP 429 Too Many Requests.
3
+ class RateLimitException < CopyleaksApiException
4
+ def initialize(response = nil)
5
+ super('Too many requests. Please wait before calling again.', response)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Copyleaks
2
+ # HTTP 503 Service Unavailable.
3
+ class UnderMaintenanceException < CopyleaksApiException
4
+ def initialize(response = nil)
5
+ super('Copyleaks is Under Maintenance, please visit https://status.copyleaks.com', response)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'export_target.rb'
2
+
3
+ module Copyleaks
4
+ # Export the crawled version of the submitted document.
5
+ class ExportCrawledVersion < ExportTarget; end
6
+ end
@@ -0,0 +1,87 @@
1
+ module Copyleaks
2
+ class CopyleaksExportModel
3
+ attr_reader :completionWebhook, :completionWebhookHeaders, :results, :crawledVersion, :pdfReport, :maxRetries,
4
+ :developerPayload, :aiDetection, :writingFeedback, :overview
5
+
6
+ # Only completionWebhook is required. Request at least one artifact to export.
7
+ # @param [String] completionWebhook Called once the export is completed.
8
+ # @param [ExportPdfReport] pdfReport Allowed only when properties.pdf.create was true on the scan.
9
+ # @param [Integer] maxRetries Upload retries before giving up. A high value (12) can delay the completion
10
+ # webhook; a low value (1) can fail while your service has a temporary problem.
11
+ # @param [String] developerPayload Echoed in the Export-Completed webhook.
12
+ # @param [Array] completionWebhookHeaders Headers added to the completion webhook.
13
+ def initialize(completionWebhook, results = nil, crawledVersion = nil, pdfReport = nil, maxRetries = nil,
14
+ developerPayload = nil, completionWebhookHeaders = nil,
15
+ aiDetection: nil, writingFeedback: nil, overview: nil)
16
+ unless completionWebhook.instance_of?(String)
17
+ raise 'Copyleaks::CopyleaksExportModel - completionWebhook - completionWebhook must be of type String'
18
+ end
19
+
20
+ unless Utils.headers_valid?(completionWebhookHeaders)
21
+ raise 'Copyleaks::CopyleaksExportModel - completionWebhookHeaders - completionWebhookHeaders must be an Array of String Array pairs'
22
+ end
23
+
24
+ unless results.nil? || (results.is_a?(Array) && results.all? { |item| item.instance_of?(ExportResults) })
25
+ raise 'Copyleaks::CopyleaksExportModel - results - entity must be of type Copyleaks::ExportResults'
26
+ end
27
+
28
+ if !crawledVersion.nil? && !crawledVersion.instance_of?(ExportCrawledVersion)
29
+ raise 'Copyleaks::CopyleaksExportModel - crawledVersion - crawledVersion must be of type Copyleaks::ExportCrawledVersion'
30
+ end
31
+
32
+ if !pdfReport.nil? && !pdfReport.instance_of?(ExportPdfReport)
33
+ raise 'Copyleaks::CopyleaksExportModel - pdfReport - pdfReport must be of type Copyleaks::ExportPdfReport'
34
+ end
35
+
36
+ if !maxRetries.nil? && !maxRetries.instance_of?(Integer)
37
+ raise 'Copyleaks::CopyleaksExportModel - maxRetries - maxRetries must be of type Integer'
38
+ end
39
+
40
+ if !developerPayload.nil? && !developerPayload.instance_of?(String)
41
+ raise 'Copyleaks::CopyleaksExportModel - developerPayload - developerPayload must be of type String'
42
+ end
43
+
44
+ if !aiDetection.nil? && !aiDetection.instance_of?(ExportAiDetection)
45
+ raise 'Copyleaks::CopyleaksExportModel - aiDetection - aiDetection must be of type Copyleaks::ExportAiDetection'
46
+ end
47
+
48
+ if !writingFeedback.nil? && !writingFeedback.instance_of?(ExportWritingFeedback)
49
+ raise 'Copyleaks::CopyleaksExportModel - writingFeedback - writingFeedback must be of type Copyleaks::ExportWritingFeedback'
50
+ end
51
+
52
+ if !overview.nil? && !overview.instance_of?(ExportOverview)
53
+ raise 'Copyleaks::CopyleaksExportModel - overview - overview must be of type Copyleaks::ExportOverview'
54
+ end
55
+
56
+ @completionWebhook = completionWebhook
57
+ @completionWebhookHeaders = completionWebhookHeaders
58
+ @results = results
59
+ @crawledVersion = crawledVersion
60
+ @pdfReport = pdfReport
61
+ @maxRetries = maxRetries
62
+ @developerPayload = developerPayload
63
+ @aiDetection = aiDetection
64
+ @writingFeedback = writingFeedback
65
+ @overview = overview
66
+ end
67
+
68
+ def as_json(*_args)
69
+ {
70
+ completionWebhook: @completionWebhook,
71
+ completionWebhookHeaders: @completionWebhookHeaders,
72
+ results: @results,
73
+ crawledVersion: @crawledVersion,
74
+ pdfReport: @pdfReport,
75
+ aiDetection: @aiDetection,
76
+ writingFeedback: @writingFeedback,
77
+ overview: @overview,
78
+ maxRetries: @maxRetries,
79
+ developerPayload: @developerPayload
80
+ }.select { |_k, v| !v.nil? }
81
+ end
82
+
83
+ def to_json(*options)
84
+ as_json(*options).to_json(*options)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'export_target.rb'
2
+
3
+ module Copyleaks
4
+ # Export the PDF report.
5
+ class ExportPdfReport < ExportTarget; end
6
+ end
@@ -0,0 +1,30 @@
1
+ module Copyleaks
2
+ class ExportResults
3
+ attr_reader :id, :endpoint, :verb, :headers
4
+
5
+ # @param [String] id Result id, from the completed webhook. The other arguments are as in ExportTarget.
6
+ def initialize(id, endpoint, verb, headers = nil)
7
+ raise 'Copyleaks::ExportResults - id - id must be of type String' unless id.instance_of?(String)
8
+ raise 'Copyleaks::ExportResults - endpoint - endpoint must be of type String' unless endpoint.instance_of?(String)
9
+ raise 'Copyleaks::ExportResults - verb - verb must be of type String' unless verb.instance_of?(String)
10
+
11
+ @id = id
12
+ @endpoint = endpoint
13
+ @verb = verb
14
+ @headers = headers
15
+ end
16
+
17
+ def as_json(*_args)
18
+ {
19
+ id: @id,
20
+ endpoint: @endpoint,
21
+ verb: @verb,
22
+ headers: @headers
23
+ }.select { |_k, v| !v.nil? }
24
+ end
25
+
26
+ def to_json(*options)
27
+ as_json(*options).to_json(*options)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ module Copyleaks
2
+ # Where Copyleaks uploads one exported artifact: an HTTP endpoint, a verb and optional headers.
3
+ # Base of ExportPdfReport, ExportCrawledVersion, ExportAiDetection, ExportWritingFeedback and ExportOverview.
4
+ class ExportTarget
5
+ attr_reader :endpoint, :verb, :headers
6
+
7
+ # @param [String] verb For example 'POST'.
8
+ # @param [Array<Array<String>>] headers Extra upload request headers, e.g. [['Authorization', 'Bearer my-token']].
9
+ def initialize(endpoint, verb, headers = nil)
10
+ raise "Copyleaks::#{self.class.name.split('::').last} - endpoint - endpoint must be of type String" unless endpoint.instance_of?(String)
11
+ raise "Copyleaks::#{self.class.name.split('::').last} - verb - verb must be of type String" unless verb.instance_of?(String)
12
+ unless Utils.headers_valid?(headers)
13
+ raise "Copyleaks::#{self.class.name.split('::').last} - headers - headers must be an Array of String Array pairs"
14
+ end
15
+
16
+ @endpoint = endpoint
17
+ @verb = verb
18
+ @headers = headers
19
+ end
20
+
21
+ def as_json(*_args)
22
+ {
23
+ endpoint: @endpoint,
24
+ verb: @verb,
25
+ headers: @headers
26
+ }.select { |_k, v| !v.nil? }
27
+ end
28
+
29
+ def to_json(*options)
30
+ as_json(*options).to_json(*options)
31
+ end
32
+ end
33
+
34
+ # Export the AI Content Detection report. Allowed only when properties.aiGeneratedText.detect was true on the scan.
35
+ class ExportAiDetection < ExportTarget; end
36
+
37
+ # Export the Grammar Checker report. Allowed only when properties.writingFeedback.enable was true on the scan.
38
+ class ExportWritingFeedback < ExportTarget; end
39
+
40
+ # Export the Gen-AI Overview report. Allowed only when properties.overview.enable was true on the scan.
41
+ class ExportOverview < ExportTarget; end
42
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'export_target.rb'
2
+ require_relative 'export_model.rb'
3
+ require_relative 'export_crawled_version.rb'
4
+ require_relative 'export_pdf_report.rb'
5
+ require_relative 'export_results.rb'
6
+
7
+ module Copyleaks
8
+ end
@@ -0,0 +1,22 @@
1
+ module Copyleaks
2
+ # An object with a String id. Base of SubmissionCourse, SubmissionAssignment and SubmissionInstitution.
3
+ class IdObject
4
+ attr_reader :id
5
+
6
+ def initialize(id)
7
+ raise "Copyleaks::#{self.class.name.split('::').last} - id - id must be of type String" unless id.instance_of?(String)
8
+
9
+ @id = id
10
+ end
11
+
12
+ def as_json(*_args)
13
+ {
14
+ id: @id
15
+ }.select { |_k, v| !v.nil? }
16
+ end
17
+
18
+ def to_json(*options)
19
+ as_json(*options).to_json(*options)
20
+ end
21
+ end
22
+ end