plagiarism-checker 2.1.0 → 3.0.2
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 +4 -4
- data/.gitignore +8 -12
- data/Gemfile +6 -4
- data/LICENSE.txt +21 -21
- data/README.md +39 -0
- data/Rakefile +4 -2
- data/bin/console +10 -2
- data/lib/copyleaks/api.rb +493 -0
- data/lib/copyleaks/app.config.rb +47 -0
- data/lib/copyleaks/models/auth_token.rb +54 -0
- data/lib/copyleaks/models/delete_request_model.rb +64 -0
- data/lib/copyleaks/models/exceptions/auth_exipred_exception.rb +32 -0
- data/lib/copyleaks/models/exceptions/command_exception.rb +32 -0
- data/lib/copyleaks/models/exceptions/index.rb +32 -0
- data/lib/copyleaks/models/exceptions/rate_limit_exception.rb +32 -0
- data/lib/copyleaks/models/exceptions/under_maintenance_exception.rb +32 -0
- data/lib/copyleaks/models/exports/export_crawled_version.rb +54 -0
- data/lib/copyleaks/models/exports/export_model.rb +84 -0
- data/lib/copyleaks/models/exports/export_pdf_report.rb +54 -0
- data/lib/copyleaks/models/exports/export_results.rb +56 -0
- data/lib/copyleaks/models/exports/index.rb +32 -0
- data/lib/copyleaks/models/id_object.rb +44 -0
- data/lib/copyleaks/models/index.rb +35 -0
- data/lib/copyleaks/models/start_request_model.rb +63 -0
- data/lib/copyleaks/models/submissions/file_ocr_submission_model.rb +61 -0
- data/lib/copyleaks/models/submissions/file_submission_model.rb +57 -0
- data/lib/copyleaks/models/submissions/index.rb +33 -0
- data/lib/copyleaks/models/submissions/properties/actions.rb +33 -0
- data/lib/copyleaks/models/submissions/properties/author.rb +41 -0
- data/lib/copyleaks/models/submissions/properties/copyleaks_db.rb +44 -0
- data/lib/copyleaks/models/submissions/properties/domains_mode.rb +31 -0
- data/lib/copyleaks/models/submissions/properties/exclude.rb +59 -0
- data/lib/copyleaks/models/submissions/properties/filter.rb +67 -0
- data/lib/copyleaks/models/submissions/properties/index.rb +45 -0
- data/lib/copyleaks/models/submissions/properties/indexing.rb +41 -0
- data/lib/copyleaks/models/submissions/properties/pdf_properties.rb +55 -0
- data/lib/copyleaks/models/submissions/properties/repository.rb +41 -0
- data/lib/copyleaks/models/submissions/properties/scanning.rb +55 -0
- data/lib/copyleaks/models/submissions/properties/scanning_exclude.rb +44 -0
- data/lib/copyleaks/models/submissions/properties/scanning_repository.rb +46 -0
- data/lib/copyleaks/models/submissions/properties/sensitive_data_protection.rb +71 -0
- data/lib/copyleaks/models/submissions/properties/submission_properties.rb +136 -0
- data/lib/copyleaks/models/submissions/properties/webhooks.rb +44 -0
- data/lib/copyleaks/models/submissions/submission_model.rb +47 -0
- data/lib/copyleaks/models/submissions/url_submission_model.rb +51 -0
- data/lib/copyleaks/utils/status-code.utils.rb +38 -0
- data/lib/copyleaks/version.rb +3 -0
- data/lib/index.rb +30 -0
- data/plagiarism-checker.gemspec +29 -0
- metadata +50 -108
- data/.rubocop.yml +0 -2
- data/copyleaks_api.gemspec +0 -29
- data/example_async.rb +0 -50
- data/example_syncronized.rb +0 -73
- data/lib/copyleaks_api.rb +0 -24
- data/lib/copyleaks_api/Models/ResultRecord.rb +0 -60
- data/lib/copyleaks_api/access_token.rb +0 -36
- data/lib/copyleaks_api/api.rb +0 -210
- data/lib/copyleaks_api/config.rb +0 -36
- data/lib/copyleaks_api/copyleaks_cloud.rb +0 -116
- data/lib/copyleaks_api/copyleaks_process.rb +0 -78
- data/lib/copyleaks_api/errors.rb +0 -29
- data/lib/copyleaks_api/validators/custom_fields_validator.rb +0 -35
- data/lib/copyleaks_api/validators/email_validator.rb +0 -13
- data/lib/copyleaks_api/validators/file_validator.rb +0 -56
- data/lib/copyleaks_api/validators/language_validator.rb +0 -12
- data/lib/copyleaks_api/validators/response_validator.rb +0 -27
- data/lib/copyleaks_api/validators/url_validator.rb +0 -12
- data/lib/copyleaks_api/version.rb +0 -3
data/lib/copyleaks_api/errors.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module CopyleaksApi
|
2
|
-
BasicError = Class.new(StandardError)
|
3
|
-
BadCustomFieldError = Class.new(BasicError)
|
4
|
-
BadFileError = Class.new(BasicError)
|
5
|
-
BadEmailError = Class.new(BasicError)
|
6
|
-
BadUrlError = Class.new(BasicError)
|
7
|
-
UnknownLanguageError = Class.new(BasicError)
|
8
|
-
|
9
|
-
class BadResponseError < BasicError
|
10
|
-
attr_accessor :code
|
11
|
-
|
12
|
-
# constructor
|
13
|
-
def initialize(code, message)
|
14
|
-
@code = code.to_i
|
15
|
-
@message = message
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_s
|
19
|
-
"Error code: #{code}. #{@message}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class ManagedError < BadResponseError
|
24
|
-
# returns true if this error is internal server error
|
25
|
-
def internal_error?
|
26
|
-
code == 16
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module CopyleaksApi
|
2
|
-
module Validators
|
3
|
-
class CustomFieldsValidator
|
4
|
-
KEY_MAX_LENGTH = 128
|
5
|
-
VALUE_MAX_LENGTH = 512
|
6
|
-
OVERALL_MAX_LENGTH = 8192
|
7
|
-
|
8
|
-
class << self
|
9
|
-
# raises appropriate error if any length is too large
|
10
|
-
def validate!(fields)
|
11
|
-
raise BadCustomFieldError.new('Key is too long') unless keys_valid?(fields)
|
12
|
-
raise BadCustomFieldError.new('Value is too long') unless values_valid?(fields)
|
13
|
-
raise BadCustomFieldError.new('Overall size is too large') unless overall_valid?(fields)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
# checks custom keys for length
|
19
|
-
def keys_valid?(hash)
|
20
|
-
hash.keys.map(&:to_s).all? { |s| s.size <= KEY_MAX_LENGTH }
|
21
|
-
end
|
22
|
-
|
23
|
-
# checks values for length
|
24
|
-
def values_valid?(hash)
|
25
|
-
hash.values.map(&:to_s).all? { |s| s.size <= VALUE_MAX_LENGTH }
|
26
|
-
end
|
27
|
-
|
28
|
-
# checks overall length
|
29
|
-
def overall_valid?(hash)
|
30
|
-
hash.reduce(0) { |a, e| a + e[0].to_s.size + e[1].to_s.size } <= OVERALL_MAX_LENGTH
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module CopyleaksApi
|
2
|
-
module Validators
|
3
|
-
class EmailValidator
|
4
|
-
class << self
|
5
|
-
# raises error if given email is invalid
|
6
|
-
def validate!(email)
|
7
|
-
return if email =~ /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
|
8
|
-
raise BadEmailError.new(email), "Email #{email} is invalid"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module CopyleaksApi
|
2
|
-
module Validators
|
3
|
-
class FileValidator
|
4
|
-
SUPPORTED_FILE_TYPES = [:html, :htm, :txt, :pdf, :doc, :docx, :rtf].freeze
|
5
|
-
SUPPORTED_IMAGE_TYPES = [:gif, :png, :bmp, :jpg, :jpeg].freeze
|
6
|
-
BYTES_IN_MB = 1_024_000.0
|
7
|
-
|
8
|
-
class << self
|
9
|
-
# check file for ocr for correctness
|
10
|
-
def validate_ocr!(path)
|
11
|
-
validate_file(path, SUPPORTED_IMAGE_TYPES)
|
12
|
-
end
|
13
|
-
|
14
|
-
# check text file for correctness
|
15
|
-
def validate_text_file!(path)
|
16
|
-
validate_file(path, SUPPORTED_FILE_TYPES)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
# check given file for correctness to given type
|
22
|
-
def validate_file(path, types)
|
23
|
-
ext = file_extension(path)
|
24
|
-
return if types.include?(ext) && file_size(path) <= allowed_file_size(ext)
|
25
|
-
raise BadFileError, "#{path} file has unsupported extension or to large"
|
26
|
-
end
|
27
|
-
|
28
|
-
# returns good file size in MB for given type
|
29
|
-
def allowed_file_size(type)
|
30
|
-
case type.to_sym
|
31
|
-
when :html, :htm
|
32
|
-
5
|
33
|
-
when :txt
|
34
|
-
3
|
35
|
-
when :pdf, :doc, :docx
|
36
|
-
25
|
37
|
-
when *SUPPORTED_IMAGE_TYPES
|
38
|
-
25
|
39
|
-
else
|
40
|
-
0
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# extract file extension
|
45
|
-
def file_extension(path)
|
46
|
-
path.split('.').last.downcase.to_sym
|
47
|
-
end
|
48
|
-
|
49
|
-
# extract file size in MB
|
50
|
-
def file_size(path)
|
51
|
-
File.size(path) / BYTES_IN_MB
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module CopyleaksApi
|
2
|
-
module Validators
|
3
|
-
class LanguageValidator
|
4
|
-
class << self
|
5
|
-
# raise error if given language is not allowed
|
6
|
-
def validate!(language)
|
7
|
-
raise UnknownLanguageError, "#{language} is unknown" unless Language::ALLOWED.include?(language)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module CopyleaksApi
|
4
|
-
module Validators
|
5
|
-
class ResponseValidator
|
6
|
-
ERROR_HEADER = 'Copyleaks-Error-Code'.freeze
|
7
|
-
GOOD_STATUS_CODE = 200
|
8
|
-
|
9
|
-
class << self
|
10
|
-
# raises error if response has APi error code or bad status code
|
11
|
-
def validate!(response)
|
12
|
-
raise ManagedError.new(response[ERROR_HEADER], extract_message(response.body)) if response[ERROR_HEADER]
|
13
|
-
raise BadResponseError.new(response.code, response.body) if response.code.to_i != GOOD_STATUS_CODE
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
# extract message from body
|
19
|
-
def extract_message(string)
|
20
|
-
JSON.parse(string)['Message']
|
21
|
-
rescue JSON::ParserError
|
22
|
-
string
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module CopyleaksApi
|
2
|
-
module Validators
|
3
|
-
class UrlValidator
|
4
|
-
class << self
|
5
|
-
# raises error if given url for callback is invalid
|
6
|
-
def validate!(url)
|
7
|
-
raise BadUrlError.new(url) unless url =~ %r(^(https?://)?([\da-z\.-]+)\.([a-z\.]{2,6})([/\w \.-]*)*/?$)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|