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,36 @@
1
+ module Copyleaks
2
+ class ScannedDocument
3
+ attr_reader :scanId, :totalWords, :totalExcluded, :credits, :creationTime, :metadata
4
+
5
+ def initialize(scanId:, totalWords:, totalExcluded:, credits:, creationTime:, metadata:)
6
+ raise 'scanId must be a String' unless scanId.is_a?(String)
7
+ raise 'totalWords must be an Integer' unless totalWords.is_a?(Integer)
8
+ raise 'totalExcluded must be an Integer' unless totalExcluded.is_a?(Integer)
9
+ raise 'credits must be an Integer' unless credits.is_a?(Integer)
10
+ raise 'creationTime must be a String' unless creationTime.is_a?(String)
11
+ raise 'metadata must be a Metadata object' unless metadata.is_a?(Metadata)
12
+
13
+ @scanId = scanId
14
+ @totalWords = totalWords
15
+ @totalExcluded = totalExcluded
16
+ @credits = credits
17
+ @creationTime = creationTime
18
+ @metadata = metadata
19
+ end
20
+
21
+ def as_json(*_args)
22
+ {
23
+ scanId: @scanId,
24
+ totalWords: @totalWords,
25
+ totalExcluded: @totalExcluded,
26
+ credits: @credits,
27
+ creationTime: @creationTime,
28
+ metadata: @metadata
29
+ }.select { |_k, v| !v.nil? }
30
+ end
31
+
32
+ def to_json(*options)
33
+ as_json(*options).to_json(*options)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,49 @@
1
+ module Copyleaks
2
+ class Error
3
+ attr_reader :code, :message, :type, :id, :url, :details
4
+
5
+ # Every field is optional, so an error webhook from any API version can be loaded.
6
+ # @param [String] type For example 'invalid_request_error' or 'payment_error'.
7
+ # @param [String] id Machine-readable, for example 'insufficient_credits'.
8
+ # @param [String] url Documentation page for this error.
9
+ # @param [Array<Hash>] details The parameters that caused the error, each with param and message.
10
+ def initialize(code: nil, message: nil, type: nil, id: nil, url: nil, details: nil, **_extra)
11
+ raise 'Copyleaks::Error - code must be an Integer' unless code.nil? || code.is_a?(Integer)
12
+ raise 'Copyleaks::Error - message must be a String' unless message.nil? || message.is_a?(String)
13
+ raise 'Copyleaks::Error - type must be a String' unless type.nil? || type.is_a?(String)
14
+ raise 'Copyleaks::Error - id must be a String' unless id.nil? || id.is_a?(String)
15
+ raise 'Copyleaks::Error - url must be a String' unless url.nil? || url.is_a?(String)
16
+ raise 'Copyleaks::Error - details must be an Array' unless details.nil? || details.is_a?(Array)
17
+
18
+ @code = code
19
+ @message = message
20
+ @type = type
21
+ @id = id
22
+ @url = url
23
+ @details = details
24
+ end
25
+
26
+ # json_hash is the 'error' object of a parsed webhook body (String or Symbol keys). nil for a non-Hash.
27
+ def self.from_json(json_hash)
28
+ return nil unless json_hash.is_a?(Hash)
29
+
30
+ new(**json_hash.transform_keys(&:to_sym))
31
+ end
32
+
33
+ def as_json(*_args)
34
+ hash = {
35
+ code: @code,
36
+ message: @message
37
+ }
38
+ hash[:type] = @type unless @type.nil?
39
+ hash[:id] = @id unless @id.nil?
40
+ hash[:url] = @url unless @url.nil?
41
+ hash[:details] = @details unless @details.nil?
42
+ hash
43
+ end
44
+
45
+ def to_json(*options)
46
+ as_json(*options).to_json(*options)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ module Copyleaks
2
+ class Task
3
+ attr_reader :endpoint, :isHealthy, :httpStatusCode
4
+
5
+ # @param [Boolean] isHealthy False when the task hit an internal error on the Copyleaks side.
6
+ # @param [Integer] httpStatusCode The status code your server returned; nil when isHealthy is false.
7
+ def initialize(endpoint:, isHealthy:, httpStatusCode:)
8
+ raise 'Copyleaks::Task - endpoint must be a String' unless endpoint.is_a?(String)
9
+ raise 'Copyleaks::Task - isHealthy must be a Boolean' unless [true, false].include?(isHealthy)
10
+ raise 'Copyleaks::Task - httpStatusCode must be an Integer' unless httpStatusCode.is_a?(Integer)
11
+
12
+ @endpoint = endpoint
13
+ @isHealthy = isHealthy
14
+ @httpStatusCode = httpStatusCode
15
+ end
16
+
17
+ def as_json(*_args)
18
+ {
19
+ endpoint: @endpoint,
20
+ isHealthy: @isHealthy,
21
+ httpStatusCode: @httpStatusCode
22
+ }
23
+ end
24
+
25
+ def to_json(*options)
26
+ as_json(*options).to_json(*options)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ module Copyleaks
2
+ class NewResultScore
3
+ attr_reader :aggregatedScore
4
+
5
+ # @param [Float] aggregatedScore Percentage of similar words in all results, excluding quotes, references, etc.
6
+ def initialize(aggregatedScore:)
7
+ raise 'Copyleaks::NewResultScore - aggregatedScore must be a Float' unless aggregatedScore.is_a?(Float) || aggregatedScore.is_a?(Integer)
8
+
9
+ @aggregatedScore = aggregatedScore.to_f
10
+ end
11
+
12
+ def as_json(*_args)
13
+ {
14
+ aggregatedScore: @aggregatedScore
15
+ }
16
+ end
17
+
18
+ def to_json(*options)
19
+ as_json(*options).to_json(*options)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ module Copyleaks
2
+ class NewResultsInternet
3
+ attr_reader :id, :title, :introduction, :matchedWords, :metadata, :url
4
+
5
+ # scanId is accepted for compatibility with earlier versions and is not used: internet results have no scan id.
6
+ def initialize(id:, title:, introduction:, matchedWords:, metadata:, url:, scanId: nil)
7
+ raise 'Copyleaks::NewResultsInternet - id must be a String' unless id.is_a?(String)
8
+ raise 'Copyleaks::NewResultsInternet - title must be a String' unless title.is_a?(String)
9
+ raise 'Copyleaks::NewResultsInternet - introduction must be a String' unless introduction.is_a?(String)
10
+ raise 'Copyleaks::NewResultsInternet - matchedWords must be an Integer' unless matchedWords.is_a?(Integer)
11
+ raise 'Copyleaks::NewResultsInternet - metadata must be a Metadata' unless metadata.is_a?(Metadata)
12
+ raise 'Copyleaks::NewResultsInternet - url must be a String' unless url.is_a?(String)
13
+
14
+ @id = id
15
+ @title = title
16
+ @introduction = introduction
17
+ @matchedWords = matchedWords
18
+ @metadata = metadata
19
+ @url = url
20
+ end
21
+
22
+ def as_json(*_args)
23
+ {
24
+ id: @id,
25
+ title: @title,
26
+ introduction: @introduction,
27
+ matchedWords: @matchedWords,
28
+ metadata: @metadata,
29
+ url: @url
30
+ }
31
+ end
32
+
33
+ def to_json(*options)
34
+ as_json(*options).to_json(*options)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ module Copyleaks
2
+ class NewResultsRepositories < SharedResultsModel
3
+ attr_reader :repositoryId
4
+
5
+ def initialize(repositoryId:, metadata:)
6
+ raise 'Copyleaks::NewResultsRepositories - repositoryId must be a String' unless repositoryId.is_a?(String)
7
+ super(metadata: metadata)
8
+
9
+ @repositoryId = repositoryId
10
+ end
11
+
12
+ # Always a RepositoryMetadata.
13
+ def metadata
14
+ super
15
+ end
16
+
17
+ def as_json(*_args)
18
+ {
19
+ repositoryId: @repositoryId,
20
+ metadata: metadata
21
+ }
22
+ end
23
+
24
+ def to_json(*options)
25
+ as_json(*options).to_json(*options)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,91 @@
1
+ require 'json'
2
+
3
+ module Copyleaks
4
+ class Alerts
5
+ attr_reader :category, :code, :title, :message, :helpLink, :severity, :additionalData
6
+
7
+ # The wire fields of a scan alert, used by Alerts.from_json.
8
+ FIELDS = %i[category code title message helpLink severity additionalData].freeze
9
+
10
+ # Bytes removed from the end of additionalData before it is parsed: NUL, tab, LF, VT, FF, CR and space.
11
+ TRAILING_BYTES = [0x00, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x20].freeze
12
+ private_constant :FIELDS, :TRAILING_BYTES
13
+
14
+ # category and severity (0-4) are Integers; Strings are also accepted for backward compatibility.
15
+ # @param [String] code Unique per alert type; see Copyleaks::CopyleaksAlertCodes.
16
+ # @param [String, nil] additionalData Extra data about the alert, as a JSON string.
17
+ def initialize(category:, code:, severity:, title: nil, message: nil, helpLink: nil, additionalData: nil)
18
+ raise 'Copyleaks::Alerts - category must be an Integer or a String' unless integer_or_string?(category)
19
+ raise 'Copyleaks::Alerts - code must be a String' unless code.is_a?(String)
20
+ raise 'Copyleaks::Alerts - title must be a String' unless title.nil? || title.is_a?(String)
21
+ raise 'Copyleaks::Alerts - message must be a String' unless message.nil? || message.is_a?(String)
22
+ raise 'Copyleaks::Alerts - helpLink must be a String' unless helpLink.nil? || helpLink.is_a?(String)
23
+ raise 'Copyleaks::Alerts - severity must be an Integer or a String' unless integer_or_string?(severity)
24
+ raise 'Copyleaks::Alerts - additionalData must be a String' unless additionalData.nil? || additionalData.is_a?(String)
25
+
26
+ @category = category
27
+ @code = code
28
+ @title = title
29
+ @message = message
30
+ @helpLink = helpLink
31
+ @severity = severity
32
+ @additionalData = additionalData
33
+ end
34
+
35
+ # Builds an alert from an item of JSON.parse(body)['notifications']['alerts'] (String or Symbol keys,
36
+ # unknown keys ignored). Returns nil for nil.
37
+ # @raise [ArgumentError] When category, code or severity is missing.
38
+ # @raise [RuntimeError] When a field has the wrong type.
39
+ def self.from_json(json_hash)
40
+ return nil if json_hash.nil?
41
+
42
+ args = {}
43
+ json_hash.each do |key, value|
44
+ name = key.to_sym
45
+ args[name] = value if FIELDS.include?(name)
46
+ end
47
+ new(**args)
48
+ end
49
+
50
+ # Decodes the AI text detection result that only the 'suspected-ai-text' alert carries, as a JSON string in
51
+ # additionalData. Trailing NUL and ASCII whitespace are removed first; additionalData itself stays raw.
52
+ # @return [CopyleaksAiTextDetectionResponseModel, nil] nil for other alerts, missing data or a non-object.
53
+ # @raise [JSON::ParserError] When additionalData is not valid JSON.
54
+ def ai_detection_result
55
+ return nil unless @code == CopyleaksAlertCodes::SUSPECTED_AI_TEXT
56
+ return nil if @additionalData.nil?
57
+
58
+ data = @additionalData
59
+ length = data.bytesize
60
+ # Linear scan from the end. NUL and ASCII whitespace are single bytes in UTF-8,
61
+ # so they never match inside a multi-byte character.
62
+ length -= 1 while length > 0 && TRAILING_BYTES.include?(data.getbyte(length - 1))
63
+ return nil if length.zero?
64
+
65
+ CopyleaksAiTextDetectionResponseModel.from_json(JSON.parse(data.byteslice(0, length)))
66
+ end
67
+
68
+ def as_json(*_args)
69
+ {
70
+ category: @category,
71
+ code: @code,
72
+ title: @title,
73
+ message: @message,
74
+ helpLink: @helpLink,
75
+ severity: @severity,
76
+ additionalData: @additionalData
77
+ }.compact
78
+ end
79
+
80
+ def to_json(*options)
81
+ as_json(*options).to_json(*options)
82
+ end
83
+
84
+ private
85
+
86
+ # True for an Integer (the wire form) or a String (accepted by earlier versions).
87
+ def integer_or_string?(value)
88
+ value.is_a?(Integer) || value.is_a?(String)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,26 @@
1
+ module Copyleaks
2
+ class Batch < SharedResultsModel
3
+ attr_reader :tags
4
+
5
+ # @param [Array<Tags>] tags
6
+ def initialize(tags:, **options)
7
+ unless tags.is_a?(Array) && tags.all? { |tag| tag.is_a?(Tags) }
8
+ raise 'Copyleaks::Batch - tags must be an Array of Tags'
9
+ end
10
+
11
+ super(**options) # Pass any other options to SharedResultsModel
12
+
13
+ @tags = tags
14
+ end
15
+
16
+ def as_json(*_args)
17
+ {
18
+ tags: @tags
19
+ }
20
+ end
21
+
22
+ def to_json(*options)
23
+ as_json(*options).to_json(*options)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Copyleaks
2
+ class Database < SharedResultsModel
3
+ attr_reader :tags
4
+
5
+ # @param [Array<Tags>] tags
6
+ def initialize(tags:, **options)
7
+ unless tags.is_a?(Array) && tags.all? { |tag| tag.is_a?(Tags) }
8
+ raise 'Copyleaks::Database - tags must be an Array of Tags'
9
+ end
10
+
11
+ super(**options) # Pass any other options to SharedResultsModel
12
+
13
+ @tags = tags
14
+ end
15
+
16
+ def as_json(*_args)
17
+ {
18
+ tags: @tags
19
+ }
20
+ end
21
+
22
+ def to_json(*options)
23
+ as_json(*options).to_json(*options)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ module Copyleaks
2
+ class Internet < NewResultsInternet
3
+ attr_reader :tags
4
+
5
+ # @param [Array<Tags>] tags
6
+ def initialize(tags:, **options)
7
+ unless tags.is_a?(Array) && tags.all? { |tag| tag.is_a?(Tags) }
8
+ raise 'Copyleaks::Internet - tags must be an Array of Tags'
9
+ end
10
+
11
+ super(**options) # Initialize parent class with other params
12
+ @tags = tags
13
+ end
14
+
15
+ def as_json(*_args)
16
+ super.merge(tags: @tags)
17
+ end
18
+
19
+ def to_json(*options)
20
+ as_json(*options).to_json(*options)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ module Copyleaks
2
+ class Repositories < SharedResultsModel
3
+ attr_reader :repositoryId, :tags
4
+
5
+ # @param [Array<Tags>] tags
6
+ def initialize(repositoryId:, tags:, **options)
7
+ unless repositoryId.is_a?(String)
8
+ raise 'Copyleaks::Repositories - repositoryId must be a String'
9
+ end
10
+
11
+ unless tags.is_a?(Array) && tags.all? { |tag| tag.is_a?(Tags) }
12
+ raise 'Copyleaks::Repositories - tags must be an Array of Tags'
13
+ end
14
+
15
+ super(**options)
16
+
17
+ @repositoryId = repositoryId
18
+ @tags = tags
19
+ end
20
+
21
+ def metadata
22
+ super
23
+ end
24
+
25
+ def as_json(*_args)
26
+ {
27
+ repositoryId: @repositoryId,
28
+ tags: @tags
29
+ }
30
+ end
31
+
32
+ def to_json(*options)
33
+ as_json(*options).to_json(*options)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ module Copyleaks
2
+ class RepositoryMetadata < Metadata
3
+ # Email of the user who added this document to the repository.
4
+ attr_reader :submittedBy
5
+
6
+ def initialize(submittedBy: nil, **args)
7
+ super(**args)
8
+ @submittedBy = submittedBy
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ module Copyleaks
2
+ class Score
3
+ attr_reader :identicalWords, :minorChangedWords, :relatedMeaningWords, :aggregatedScore
4
+
5
+ # @param [Integer] minorChangedWords Nearly identical words, like 'slow' and 'slowly'.
6
+ # @param [Integer] relatedMeaningWords Paraphrased words: similar ideas in different words.
7
+ # @param [Float] aggregatedScore Percentage of similar words in all results, excluding quotes, references, etc.
8
+ def initialize(
9
+ identicalWords: nil,
10
+ minorChangedWords: nil,
11
+ relatedMeaningWords: nil,
12
+ aggregatedScore: nil
13
+ )
14
+ @identicalWords = identicalWords
15
+ @minorChangedWords = minorChangedWords
16
+ @relatedMeaningWords = relatedMeaningWords
17
+ @aggregatedScore = aggregatedScore
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module Copyleaks
2
+ class SharedResultsModel
3
+ attr_reader :id, :title, :introduction, :matchedWords, :scanId, :metadata
4
+
5
+ # @param [String, nil] scanId Set only when the result is your own submission in the Copyleaks internal database.
6
+ def initialize(
7
+ id: nil,
8
+ title: nil,
9
+ introduction: nil,
10
+ matchedWords: nil,
11
+ scanId: nil,
12
+ metadata: nil
13
+ )
14
+ @id = id
15
+ @title = title
16
+ @introduction = introduction
17
+ @matchedWords = matchedWords
18
+ @scanId = scanId
19
+ @metadata = metadata
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module Copyleaks
2
+ class Tags
3
+ attr_reader :code, :title, :description
4
+
5
+ # @param [String] code Identifies the tag type.
6
+ def initialize(code: nil, title: nil, description: nil)
7
+ @code = code
8
+ @title = title
9
+ @description = description
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Copyleaks
2
+ class IndexedWebhook < StatusWebhook
3
+ def initialize(status:, developerPayload: nil, **args)
4
+ super(status: status, developerPayload: developerPayload, **args)
5
+ end
6
+
7
+
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ module Copyleaks
2
+ class NewResultWebhook < Webhook
3
+ attr_reader :score, :internet, :database, :batch, :repositories, :internalAIData
4
+
5
+ # @param [Array] internalAIData Internal AI Source Match results.
6
+ def initialize(score: nil, internet: nil, database: nil, batch: nil, repositories: nil, internalAIData: nil, **args)
7
+ super(**args)
8
+ @score = score
9
+ @internet = internet
10
+ @database = database
11
+ @batch = batch
12
+ @repositories = repositories
13
+ @internalAIData = internalAIData
14
+ end
15
+
16
+ def as_json(*_args)
17
+ hash = {
18
+ score: @score,
19
+ internet: @internet,
20
+ database: @database,
21
+ batch: @batch,
22
+ repositories: @repositories
23
+ }
24
+ hash[:internalAIData] = @internalAIData unless @internalAIData.nil?
25
+ hash.merge(super)
26
+ end
27
+
28
+ def to_json(*options)
29
+ as_json.to_json(*options)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ module Copyleaks
2
+ require_relative 'HelperModels/BaseModels/Metadata.rb'
3
+ require_relative 'HelperModels/BaseModels/Webhook.rb'
4
+ require_relative 'HelperModels/BaseModels/StatusWebhook.rb'
5
+
6
+ require_relative 'HelperModels/ResultsModels/SharedResultsModel.rb'
7
+ require_relative 'HelperModels/NewResultsModels/NewResultScore.rb'
8
+ require_relative 'HelperModels/NewResultsModels/NewResultsInternet.rb'
9
+ require_relative 'HelperModels/NewResultsModels/NewResultsRepositories.rb'
10
+
11
+ require_relative 'HelperModels/ResultsModels/Batch.rb'
12
+ require_relative 'HelperModels/ResultsModels/Internet.rb'
13
+ require_relative 'HelperModels/ResultsModels/Database.rb'
14
+ require_relative 'HelperModels/ResultsModels/Repositories.rb'
15
+ require_relative 'HelperModels/ResultsModels/RepositoryMetadata.rb'
16
+ require_relative 'HelperModels/ResultsModels/Score.rb'
17
+ require_relative 'HelperModels/ResultsModels/Tags.rb'
18
+
19
+ require_relative 'HelperModels/CompletedModels/Notifications.rb'
20
+ require_relative 'HelperModels/CompletedModels/Results.rb'
21
+ require_relative 'HelperModels/CompletedModels/ScannedDocument.rb'
22
+
23
+ require_relative 'HelperModels/ErrorModels/Error.rb'
24
+ require_relative 'HelperModels/NotificationsModels/Alerts.rb'
25
+ require_relative 'HelperModels/ExportModels/Task.rb'
26
+
27
+ require_relative 'CompletedWebhook.rb'
28
+ require_relative 'CreditsCheckedWebhook.rb'
29
+ require_relative 'ErrorWebhook.rb'
30
+ require_relative 'IndexedWebhook.rb'
31
+ require_relative 'ExportCompletedWebhook.rb'
32
+
33
+ require_relative 'NewResultWebhook.rb'
34
+ end
@@ -0,0 +1,26 @@
1
+ module Copyleaks
2
+ # Weight of each correction category in the overall score, 0.0 to 1.0.
3
+ class ScoreWeights
4
+ attr_accessor :grammar_score_weight, :mechanics_score_weight, :sentence_structure_score_weight, :word_choice_score_weight
5
+
6
+ def initialize(grammar_score_weight, mechanics_score_weight, sentence_structure_score_weight, word_choice_score_weight)
7
+ @grammar_score_weight = grammar_score_weight
8
+ @mechanics_score_weight = mechanics_score_weight
9
+ @sentence_structure_score_weight = sentence_structure_score_weight
10
+ @word_choice_score_weight = word_choice_score_weight
11
+ end
12
+
13
+ def as_json(*_args)
14
+ {
15
+ grammarScoreWeight: @grammar_score_weight,
16
+ mechanicsScoreWeight: @mechanics_score_weight,
17
+ sentenceStructureScoreWeight: @sentence_structure_score_weight,
18
+ wordChoiceScoreWeight: @word_choice_score_weight
19
+ }.reject { |_k, v| v.nil? }
20
+ end
21
+
22
+ def to_json(*options)
23
+ as_json(*options).to_json(*options)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ module Copyleaks
2
+ class WritingAssistantSubmissionModel
3
+ attr_accessor :text, :sandbox, :language, :score
4
+
5
+ # @param [String] text 1 to 25,000 characters.
6
+ # @param [Boolean] sandbox Test without using credits. nil omits the field (server default: false).
7
+ # @param [String] language Language code; auto-detected when nil.
8
+ # @param [ScoreWeights] score Optional weights of the writing aspects in the overall score.
9
+ def initialize(text, sandbox = nil, language = nil, score = nil)
10
+ unless text.instance_of?(String)
11
+ raise 'Copyleaks::WritingAssistantSubmissionModel - text - text must be of type String'
12
+ end
13
+ @text = text
14
+ @sandbox = sandbox
15
+ @language = language
16
+ @score = score
17
+ end
18
+
19
+ def as_json(*_args)
20
+ {
21
+ text: @text,
22
+ sandbox: @sandbox,
23
+ language: @language,
24
+ score: @score
25
+ }.reject { |_k, v| v.nil? }
26
+ end
27
+
28
+ def to_json(*options)
29
+ as_json(*options).to_json(*options)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+ module Copyleaks
3
+
4
+ class CopyleaksTextModerationLabel
5
+ attr_reader :id
6
+
7
+ def initialize(id)
8
+ @id = id
9
+ end
10
+
11
+ def to_json(*_args)
12
+ { 'id' => @id }.to_json
13
+ end
14
+
15
+ # json is a JSON String or a Hash.
16
+ def self.from_json(json)
17
+ data = json.is_a?(String) ? JSON.parse(json) : json
18
+ new(data['id'] || data[:id])
19
+ end
20
+ end
21
+ end