plagiarism-checker 1.0.0 → 3.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 +4 -4
- data/.gitignore +8 -12
- data/Gemfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +39 -0
- data/Rakefile +4 -2
- data/bin/console +15 -7
- data/bin/setup +8 -8
- 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 +35 -0
- data/plagiarism-checker.gemspec +29 -0
- metadata +50 -107
- data/.rubocop.yml +0 -2
- data/copyleaks_api.gemspec +0 -29
- data/examples/main.rb +0 -60
- data/lib/copyleaks_api.rb +0 -23
- data/lib/copyleaks_api/access_token.rb +0 -36
- data/lib/copyleaks_api/api.rb +0 -153
- data/lib/copyleaks_api/config.rb +0 -34
- data/lib/copyleaks_api/copyleaks_cloud.rb +0 -92
- data/lib/copyleaks_api/copyleaks_process.rb +0 -82
- data/lib/copyleaks_api/errors.rb +0 -29
- data/lib/copyleaks_api/language.rb +0 -61
- 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/index.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License(MIT)
|
3
|
+
#
|
4
|
+
# Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
# =
|
24
|
+
|
25
|
+
$LOAD_PATH.unshift(__dir__) unless $LOAD_PATH.include?(__dir__)
|
26
|
+
|
27
|
+
require 'copyleaks/version'
|
28
|
+
|
29
|
+
require 'copyleaks/models/index'
|
30
|
+
require 'copyleaks/utils/status-code.utils'
|
31
|
+
require 'copyleaks/app.config'
|
32
|
+
require 'copyleaks/api'
|
33
|
+
|
34
|
+
module Copyleaks
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib = File.expand_path('lib', __dir__)
|
4
|
+
# $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require_relative 'lib/copyleaks/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'plagiarism-checker'
|
10
|
+
spec.version = Copyleaks::VERSION
|
11
|
+
spec.authors = ['Copyleaks ltd']
|
12
|
+
spec.email = ['sales@copyleaks.com']
|
13
|
+
|
14
|
+
spec.summary = 'Detects plagiarism and checks content distribution online.'
|
15
|
+
spec.description = 'Copyleaks detects plagiarism and checks content distribution online. Use Copyleaks to find out if textual content is original and if it has been used before. With Copyleaks cloud publishers, academics, and more can scan files (pdf, doc, docx, ocr...), URLs and free text for plagiarism check.'
|
16
|
+
spec.homepage = 'https://api.copyleaks.com'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/Copyleaks/Ruby-Plagiarism-Checker'
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/Copyleaks/Ruby-Plagiarism-Checker/releases'
|
22
|
+
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:demo|test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
end
|
metadata
CHANGED
@@ -1,99 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plagiarism-checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Copyleaks ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: webmock
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pry
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: bundler
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.7'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.7'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '10.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '10.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: mimemagic
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
11
|
+
date: 2021-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
97
13
|
description: Copyleaks detects plagiarism and checks content distribution online.
|
98
14
|
Use Copyleaks to find out if textual content is original and if it has been used
|
99
15
|
before. With Copyleaks cloud publishers, academics, and more can scan files (pdf,
|
@@ -105,34 +21,61 @@ extensions: []
|
|
105
21
|
extra_rdoc_files: []
|
106
22
|
files:
|
107
23
|
- ".gitignore"
|
108
|
-
- ".rubocop.yml"
|
109
24
|
- Gemfile
|
110
25
|
- LICENSE.txt
|
111
26
|
- README.md
|
112
27
|
- Rakefile
|
113
28
|
- bin/console
|
114
29
|
- bin/setup
|
115
|
-
-
|
116
|
-
-
|
117
|
-
- lib/
|
118
|
-
- lib/
|
119
|
-
- lib/
|
120
|
-
- lib/
|
121
|
-
- lib/
|
122
|
-
- lib/
|
123
|
-
- lib/
|
124
|
-
- lib/
|
125
|
-
- lib/
|
126
|
-
- lib/
|
127
|
-
- lib/
|
128
|
-
- lib/
|
129
|
-
- lib/
|
130
|
-
- lib/
|
131
|
-
- lib/
|
30
|
+
- lib/copyleaks/api.rb
|
31
|
+
- lib/copyleaks/app.config.rb
|
32
|
+
- lib/copyleaks/models/auth_token.rb
|
33
|
+
- lib/copyleaks/models/delete_request_model.rb
|
34
|
+
- lib/copyleaks/models/exceptions/auth_exipred_exception.rb
|
35
|
+
- lib/copyleaks/models/exceptions/command_exception.rb
|
36
|
+
- lib/copyleaks/models/exceptions/index.rb
|
37
|
+
- lib/copyleaks/models/exceptions/rate_limit_exception.rb
|
38
|
+
- lib/copyleaks/models/exceptions/under_maintenance_exception.rb
|
39
|
+
- lib/copyleaks/models/exports/export_crawled_version.rb
|
40
|
+
- lib/copyleaks/models/exports/export_model.rb
|
41
|
+
- lib/copyleaks/models/exports/export_pdf_report.rb
|
42
|
+
- lib/copyleaks/models/exports/export_results.rb
|
43
|
+
- lib/copyleaks/models/exports/index.rb
|
44
|
+
- lib/copyleaks/models/id_object.rb
|
45
|
+
- lib/copyleaks/models/index.rb
|
46
|
+
- lib/copyleaks/models/start_request_model.rb
|
47
|
+
- lib/copyleaks/models/submissions/file_ocr_submission_model.rb
|
48
|
+
- lib/copyleaks/models/submissions/file_submission_model.rb
|
49
|
+
- lib/copyleaks/models/submissions/index.rb
|
50
|
+
- lib/copyleaks/models/submissions/properties/actions.rb
|
51
|
+
- lib/copyleaks/models/submissions/properties/author.rb
|
52
|
+
- lib/copyleaks/models/submissions/properties/copyleaks_db.rb
|
53
|
+
- lib/copyleaks/models/submissions/properties/domains_mode.rb
|
54
|
+
- lib/copyleaks/models/submissions/properties/exclude.rb
|
55
|
+
- lib/copyleaks/models/submissions/properties/filter.rb
|
56
|
+
- lib/copyleaks/models/submissions/properties/index.rb
|
57
|
+
- lib/copyleaks/models/submissions/properties/indexing.rb
|
58
|
+
- lib/copyleaks/models/submissions/properties/pdf_properties.rb
|
59
|
+
- lib/copyleaks/models/submissions/properties/repository.rb
|
60
|
+
- lib/copyleaks/models/submissions/properties/scanning.rb
|
61
|
+
- lib/copyleaks/models/submissions/properties/scanning_exclude.rb
|
62
|
+
- lib/copyleaks/models/submissions/properties/scanning_repository.rb
|
63
|
+
- lib/copyleaks/models/submissions/properties/sensitive_data_protection.rb
|
64
|
+
- lib/copyleaks/models/submissions/properties/submission_properties.rb
|
65
|
+
- lib/copyleaks/models/submissions/properties/webhooks.rb
|
66
|
+
- lib/copyleaks/models/submissions/submission_model.rb
|
67
|
+
- lib/copyleaks/models/submissions/url_submission_model.rb
|
68
|
+
- lib/copyleaks/utils/status-code.utils.rb
|
69
|
+
- lib/copyleaks/version.rb
|
70
|
+
- lib/index.rb
|
71
|
+
- plagiarism-checker.gemspec
|
132
72
|
homepage: https://api.copyleaks.com
|
133
73
|
licenses:
|
134
74
|
- MIT
|
135
|
-
metadata:
|
75
|
+
metadata:
|
76
|
+
homepage_uri: https://api.copyleaks.com
|
77
|
+
source_code_uri: https://github.com/Copyleaks/Ruby-Plagiarism-Checker
|
78
|
+
changelog_uri: https://github.com/Copyleaks/Ruby-Plagiarism-Checker/releases
|
136
79
|
post_install_message:
|
137
80
|
rdoc_options: []
|
138
81
|
require_paths:
|
@@ -149,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
92
|
version: '0'
|
150
93
|
requirements: []
|
151
94
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.6.4
|
95
|
+
rubygems_version: 2.6.14.4
|
153
96
|
signing_key:
|
154
97
|
specification_version: 4
|
155
98
|
summary: Detects plagiarism and checks content distribution online.
|
data/.rubocop.yml
DELETED
data/copyleaks_api.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'copyleaks_api/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "plagiarism-checker"
|
8
|
-
spec.version = CopyleaksApi::VERSION
|
9
|
-
spec.authors = ["Copyleaks ltd"]
|
10
|
-
spec.email = ["sales@copyleaks.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Detects plagiarism and checks content distribution online.}
|
13
|
-
spec.description = %q{Copyleaks detects plagiarism and checks content distribution online. Use Copyleaks to find out if textual content is original and if it has been used before. With Copyleaks cloud publishers, academics, and more can scan files (pdf, doc, docx, ocr...), URLs and free text for plagiarism check.}
|
14
|
-
spec.homepage = "https://api.copyleaks.com"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = "exe"
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_development_dependency 'webmock'
|
23
|
-
spec.add_development_dependency 'pry'
|
24
|
-
spec.add_development_dependency 'rspec'
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
-
|
28
|
-
spec.add_runtime_dependency 'mimemagic'
|
29
|
-
end
|
data/examples/main.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'copyleaks_api'
|
3
|
-
|
4
|
-
# firstly we need to create new Cloud entity
|
5
|
-
email = '<YOUR-EMAIL>'
|
6
|
-
api_key = '<YOUR-API-KEY>'
|
7
|
-
cloud = CopyleaksApi::CopyleaksCloud.new(email, api_key, :publisher)
|
8
|
-
|
9
|
-
# to check your balance just call balance
|
10
|
-
|
11
|
-
puts "Your balance is #{cloud.balance} credits"
|
12
|
-
|
13
|
-
# firstly we need to change work mode to sandbox
|
14
|
-
|
15
|
-
CopyleaksApi::Config.sandbox_mode = true
|
16
|
-
|
17
|
-
# now we can create new process by some url and custom callback
|
18
|
-
process = cloud.create_by_url('http://exmaple.com', http_callback: 'http://requestb.in/')
|
19
|
-
|
20
|
-
# Other scanning options
|
21
|
-
# Text scan:
|
22
|
-
#process = cloud.create_by_text("-Your text here-")
|
23
|
-
|
24
|
-
# Textual file scan:
|
25
|
-
#path = File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'files', 'lorem.txt')
|
26
|
-
#process = cloud.create_by_file(path)
|
27
|
-
|
28
|
-
# Ocr scan:
|
29
|
-
#path = File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'files', 'lorem.jpg')
|
30
|
-
#process = cloud.create_by_ocr(path, language: CopyleaksApi::Language.latin)
|
31
|
-
|
32
|
-
puts "Now process has state '#{process.status}'"
|
33
|
-
|
34
|
-
# to update process information we can just do this
|
35
|
-
|
36
|
-
# process.reload
|
37
|
-
|
38
|
-
# and it automatically call cloud.status with his id
|
39
|
-
# it need some time to process your request so we need to wait
|
40
|
-
|
41
|
-
while process.processing?
|
42
|
-
sleep(1)
|
43
|
-
process.reload
|
44
|
-
end
|
45
|
-
|
46
|
-
puts "And after sleep - #{process.status}"
|
47
|
-
# to get our results from processing we can just call correspond method
|
48
|
-
|
49
|
-
puts 'And its results are:'
|
50
|
-
puts process.result.inspect
|
51
|
-
|
52
|
-
# all results will be in array ow hashes with keys like Copyleaks API provides
|
53
|
-
# to get list of all existing processes we can call list method
|
54
|
-
|
55
|
-
processes = cloud.list
|
56
|
-
puts "Overall you have #{processes.size} processes"
|
57
|
-
|
58
|
-
# Delete finished process by PID:
|
59
|
-
#PID = '00000000-0000-0000-0000-000000000000'
|
60
|
-
#cloud.delete(PID)
|
data/lib/copyleaks_api.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
2
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
end
|
4
|
-
require 'copyleaks_api/version'
|
5
|
-
|
6
|
-
require 'copyleaks_api/language'
|
7
|
-
require 'copyleaks_api/errors'
|
8
|
-
|
9
|
-
require 'copyleaks_api/validators/custom_fields_validator'
|
10
|
-
require 'copyleaks_api/validators/email_validator'
|
11
|
-
require 'copyleaks_api/validators/file_validator'
|
12
|
-
require 'copyleaks_api/validators/response_validator'
|
13
|
-
require 'copyleaks_api/validators/url_validator'
|
14
|
-
require 'copyleaks_api/validators/language_validator'
|
15
|
-
|
16
|
-
require 'copyleaks_api/copyleaks_cloud'
|
17
|
-
require 'copyleaks_api/access_token'
|
18
|
-
require 'copyleaks_api/api'
|
19
|
-
require 'copyleaks_api/config'
|
20
|
-
require 'copyleaks_api/copyleaks_process'
|
21
|
-
|
22
|
-
module CopyleaksApi
|
23
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'time'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module CopyleaksApi
|
5
|
-
class AccessToken
|
6
|
-
attr_reader :created_at, :expire_at
|
7
|
-
|
8
|
-
# constructor
|
9
|
-
def initialize(cloud, email, api_key)
|
10
|
-
@cloud = cloud
|
11
|
-
@email = email
|
12
|
-
@api_key = api_key
|
13
|
-
login
|
14
|
-
end
|
15
|
-
|
16
|
-
# predicate method to check if token is not expired
|
17
|
-
def fresh?
|
18
|
-
DateTime.now.new_offset(0) < @expire_at
|
19
|
-
end
|
20
|
-
|
21
|
-
# return token string
|
22
|
-
def token
|
23
|
-
return @token if fresh?
|
24
|
-
login
|
25
|
-
end
|
26
|
-
|
27
|
-
# get token for given email and api_key pair
|
28
|
-
def login
|
29
|
-
res = @cloud.api.post('account/login-api', { Email: @email, ApiKey: @api_key }.to_json)
|
30
|
-
@token = res['access_token']
|
31
|
-
@created_at = DateTime.parse(res['.issued'])
|
32
|
-
@expire_at = DateTime.parse(res['.expires'])
|
33
|
-
@token
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/copyleaks_api/api.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'net/http'
|
3
|
-
require 'mimemagic'
|
4
|
-
require 'mimemagic/overlay'
|
5
|
-
require 'openssl'
|
6
|
-
|
7
|
-
module CopyleaksApi
|
8
|
-
class Api
|
9
|
-
BASE_URL = 'https://api.copyleaks.com'.freeze
|
10
|
-
API_VERSION = 'v1'.freeze
|
11
|
-
|
12
|
-
# constructor
|
13
|
-
def initialize
|
14
|
-
uri = URI(BASE_URL)
|
15
|
-
@http = Net::HTTP.new(uri.host, uri.port)
|
16
|
-
@http.use_ssl = true
|
17
|
-
@http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
|
18
|
-
end
|
19
|
-
|
20
|
-
# make get request without any callback header
|
21
|
-
def get(path, options = {})
|
22
|
-
request = Net::HTTP::Get.new(request_uri(path))
|
23
|
-
make_request(request, options.merge(no_callbacks: true))
|
24
|
-
end
|
25
|
-
|
26
|
-
# make post request with given options
|
27
|
-
def post(path, body = nil, options = {})
|
28
|
-
request = Net::HTTP::Post.new(request_uri(path))
|
29
|
-
request.body = body
|
30
|
-
make_request(request, options)
|
31
|
-
end
|
32
|
-
|
33
|
-
# makes delete request without callbacks
|
34
|
-
def delete(path, options = {})
|
35
|
-
request = Net::HTTP::Delete.new(request_uri(path))
|
36
|
-
make_request(request, options.merge(no_callbacks: true))
|
37
|
-
end
|
38
|
-
|
39
|
-
# makes post request with file inside
|
40
|
-
def post_file(path, file_path, options = {})
|
41
|
-
request = Net::HTTP::Post.new(request_uri(path))
|
42
|
-
options[:partial_scan] ||= CopyleaksApi::Config.allow_partial_scan
|
43
|
-
boundary = "copyleaks_sdk_#{SecureRandom.hex(4)}"
|
44
|
-
request.body = file_body(file_path, boundary)
|
45
|
-
make_request(request, options.merge(boundary: boundary))
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
# extracts mime type of given file
|
51
|
-
def extract_mime_type(path)
|
52
|
-
mime = MimeMagic.by_magic(File.open(path))
|
53
|
-
mime ? mime.type : 'text/plain'
|
54
|
-
end
|
55
|
-
|
56
|
-
# prepares post body with file inside
|
57
|
-
def file_body(path, boundary)
|
58
|
-
[
|
59
|
-
"\r\n--#{boundary}\r\n",
|
60
|
-
"content-disposition: form-data; name=\"file\"",
|
61
|
-
"; filename=\"#{File.basename(path)}\"\r\n",
|
62
|
-
"Content-Type: #{extract_mime_type(path)}\r\n",
|
63
|
-
"Content-Transfer-Encoding: binary\r\n",
|
64
|
-
"\r\n",
|
65
|
-
File.open(path, 'rb') { |io| io.read },
|
66
|
-
"\r\n--#{boundary}--\r\n"
|
67
|
-
].join('')
|
68
|
-
end
|
69
|
-
|
70
|
-
# gather all API path
|
71
|
-
def request_uri(path)
|
72
|
-
"/#{API_VERSION}/#{path}"
|
73
|
-
end
|
74
|
-
|
75
|
-
# gather headers, makes request and do validation
|
76
|
-
def make_request(request, options)
|
77
|
-
gather_headers(request, options)
|
78
|
-
response = @http.request(request)
|
79
|
-
Validators::ResponseValidator.validate!(response)
|
80
|
-
JSON.parse(response.body)
|
81
|
-
end
|
82
|
-
|
83
|
-
# gather all headers
|
84
|
-
def gather_headers(request, options)
|
85
|
-
[
|
86
|
-
http_callbacks_header(options),
|
87
|
-
email_callback_header(options),
|
88
|
-
authentication_header(options),
|
89
|
-
sandbox_header,
|
90
|
-
content_type_header(options),
|
91
|
-
partial_scan_header(options),
|
92
|
-
'User-Agent' => "RUBYSDK/#{CopyleaksApi::VERSION}"
|
93
|
-
].reduce({}, :merge).each do |header, value|
|
94
|
-
request[header] = value
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# prepares header for sandbox mode
|
99
|
-
def sandbox_header
|
100
|
-
return {} unless Config.sandbox_mode
|
101
|
-
{ 'copyleaks-sandbox-mode' => '' }
|
102
|
-
end
|
103
|
-
|
104
|
-
# prepares header for content type
|
105
|
-
def content_type_header(options)
|
106
|
-
{ 'Content-Type' => options[:boundary] ? "multipart/form-data; boundary=\"#{options[:boundary]}\"" :
|
107
|
-
'application/json' }
|
108
|
-
end
|
109
|
-
|
110
|
-
# prepares header for partial scan
|
111
|
-
def partial_scan_header(options)
|
112
|
-
return {} unless !options[:allow_partial_scan].nil? && options[:allow_partial_scan] || Config.allow_partial_scan
|
113
|
-
{ 'copyleaks-allow-partial-scan' => '' }
|
114
|
-
end
|
115
|
-
|
116
|
-
# prepares authentication header
|
117
|
-
def authentication_header(options)
|
118
|
-
return {} unless options[:token]
|
119
|
-
{ 'Authorization' => "Bearer #{options[:token]}" }
|
120
|
-
end
|
121
|
-
|
122
|
-
# prepare header for http callback
|
123
|
-
def http_callbacks_header(options)
|
124
|
-
return {} if options[:no_http_callback] || options[:no_callbacks]
|
125
|
-
value = options[:http_callback] || CopyleaksApi::Config.http_callback
|
126
|
-
return {} unless value
|
127
|
-
Validators::UrlValidator.validate!(value)
|
128
|
-
{ 'copyleaks-http-callback' => value }
|
129
|
-
end
|
130
|
-
|
131
|
-
# prepares header for email callback
|
132
|
-
def email_callback_header(options)
|
133
|
-
return {} if options[:no_email_callback] || options[:no_callbacks]
|
134
|
-
value = options[:email_callback] || CopyleaksApi::Config.email_callback
|
135
|
-
return {} unless value
|
136
|
-
Validators::EmailValidator.validate!(value)
|
137
|
-
{ 'copyleaks-email-callback' => value }
|
138
|
-
end
|
139
|
-
|
140
|
-
# prepares headers with custom fields
|
141
|
-
def custom_field_headers(options)
|
142
|
-
return {} if options[:no_custom_fields]
|
143
|
-
value = CopyleaksApi::Config.custom_fields.merge(options[:custom_fields] || {})
|
144
|
-
Validators::CustomFieldsValidator.validate!(value)
|
145
|
-
prepare_custom_fields(value)
|
146
|
-
end
|
147
|
-
|
148
|
-
# prepares custom fields before transformation into headers
|
149
|
-
def prepare_custom_fields(fields)
|
150
|
-
fields.each_with_object({}) { |e, o| o["copyleaks-client-custom-#{e[0]}"] = e[1] }
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|