plagiarism-checker 2.1.1 → 3.0.3

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -12
  3. data/Gemfile +6 -4
  4. data/LICENSE.txt +21 -21
  5. data/README.md +39 -0
  6. data/Rakefile +4 -2
  7. data/bin/console +10 -2
  8. data/lib/copyleaks.rb +35 -0
  9. data/lib/copyleaks/api.rb +493 -0
  10. data/lib/copyleaks/app.config.rb +47 -0
  11. data/lib/copyleaks/models/auth_token.rb +54 -0
  12. data/lib/copyleaks/models/delete_request_model.rb +64 -0
  13. data/lib/copyleaks/models/exceptions/auth_exipred_exception.rb +32 -0
  14. data/lib/copyleaks/models/exceptions/command_exception.rb +32 -0
  15. data/lib/copyleaks/models/exceptions/index.rb +32 -0
  16. data/lib/copyleaks/models/exceptions/rate_limit_exception.rb +32 -0
  17. data/lib/copyleaks/models/exceptions/under_maintenance_exception.rb +32 -0
  18. data/lib/copyleaks/models/exports/export_crawled_version.rb +54 -0
  19. data/lib/copyleaks/models/exports/export_model.rb +84 -0
  20. data/lib/copyleaks/models/exports/export_pdf_report.rb +54 -0
  21. data/lib/copyleaks/models/exports/export_results.rb +56 -0
  22. data/lib/copyleaks/models/exports/index.rb +32 -0
  23. data/lib/copyleaks/models/id_object.rb +44 -0
  24. data/lib/copyleaks/models/index.rb +35 -0
  25. data/lib/copyleaks/models/start_request_model.rb +63 -0
  26. data/lib/copyleaks/models/submissions/file_ocr_submission_model.rb +61 -0
  27. data/lib/copyleaks/models/submissions/file_submission_model.rb +57 -0
  28. data/lib/copyleaks/models/submissions/index.rb +33 -0
  29. data/lib/copyleaks/models/submissions/properties/actions.rb +33 -0
  30. data/lib/copyleaks/models/submissions/properties/author.rb +41 -0
  31. data/lib/copyleaks/models/submissions/properties/copyleaks_db.rb +44 -0
  32. data/lib/copyleaks/models/submissions/properties/domains_mode.rb +31 -0
  33. data/lib/copyleaks/models/submissions/properties/exclude.rb +59 -0
  34. data/lib/copyleaks/models/submissions/properties/filter.rb +67 -0
  35. data/lib/copyleaks/models/submissions/properties/index.rb +45 -0
  36. data/lib/copyleaks/models/submissions/properties/indexing.rb +41 -0
  37. data/lib/copyleaks/models/submissions/properties/pdf_properties.rb +55 -0
  38. data/lib/copyleaks/models/submissions/properties/repository.rb +41 -0
  39. data/lib/copyleaks/models/submissions/properties/scanning.rb +55 -0
  40. data/lib/copyleaks/models/submissions/properties/scanning_exclude.rb +44 -0
  41. data/lib/copyleaks/models/submissions/properties/scanning_repository.rb +46 -0
  42. data/lib/copyleaks/models/submissions/properties/sensitive_data_protection.rb +71 -0
  43. data/lib/copyleaks/models/submissions/properties/submission_properties.rb +136 -0
  44. data/lib/copyleaks/models/submissions/properties/webhooks.rb +44 -0
  45. data/lib/copyleaks/models/submissions/submission_model.rb +47 -0
  46. data/lib/copyleaks/models/submissions/url_submission_model.rb +51 -0
  47. data/lib/copyleaks/utils/status-code.utils.rb +38 -0
  48. data/lib/copyleaks/version.rb +3 -0
  49. data/lib/index.rb +30 -0
  50. data/plagiarism-checker-3.0.2.gem +0 -0
  51. data/plagiarism-checker.gemspec +29 -0
  52. metadata +52 -108
  53. data/.rubocop.yml +0 -2
  54. data/copyleaks_api.gemspec +0 -29
  55. data/example_asynchronous.rb +0 -51
  56. data/example_synchronous.rb +0 -74
  57. data/lib/copyleaks_api.rb +0 -24
  58. data/lib/copyleaks_api/Models/ResultRecord.rb +0 -60
  59. data/lib/copyleaks_api/access_token.rb +0 -36
  60. data/lib/copyleaks_api/api.rb +0 -216
  61. data/lib/copyleaks_api/config.rb +0 -37
  62. data/lib/copyleaks_api/copyleaks_cloud.rb +0 -116
  63. data/lib/copyleaks_api/copyleaks_process.rb +0 -78
  64. data/lib/copyleaks_api/errors.rb +0 -29
  65. data/lib/copyleaks_api/validators/custom_fields_validator.rb +0 -35
  66. data/lib/copyleaks_api/validators/email_validator.rb +0 -13
  67. data/lib/copyleaks_api/validators/file_validator.rb +0 -56
  68. data/lib/copyleaks_api/validators/language_validator.rb +0 -12
  69. data/lib/copyleaks_api/validators/response_validator.rb +0 -27
  70. data/lib/copyleaks_api/validators/url_validator.rb +0 -12
  71. data/lib/copyleaks_api/version.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d505c3202beab2a3fb6b94e7d1ba33e11563f3ec
4
- data.tar.gz: 650078b90aed95d6fe05b703cb689f3abdeb7d9f
3
+ metadata.gz: 5eeda449435806ae47b6544d1dbaeea4e1ba2c1a
4
+ data.tar.gz: 9113ca6c2a957bc9ea77b78bb0ceacc9d25b5175
5
5
  SHA512:
6
- metadata.gz: 72633294ef59a7cca317fa774608a9e19887a5bf9e608de4499ffa9730ae9efe04a8707d1812b6c8b40407061d28c382b52deeaf70569ebdb5faaba033fd5fd2
7
- data.tar.gz: b548cefb5cf621e19b1593c78fbd14ce525aa50475bdbe682cf0433fa802871bda5325642a49e03facc30e75089f1961456d82d4e43eef71e159e8b373e5c452
6
+ metadata.gz: 9b1eddf67d1cb5e968f9744ec3983d71738338b1cb76daad9372cb9eed4ef60a1deb0b33d684acc8acce64afc9a457103b4c661d5518462fd9b69d89997f6c90
7
+ data.tar.gz: 39186d50e55031ede5d249409030bfc7b2815363bd72c7d9a4b886a4e51bcc197a9dc9286a7b87a7e6735fdbbdc46587fe92155cad536b6286678cb2529971f0
data/.gitignore CHANGED
@@ -1,12 +1,8 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- .idea
11
- /README.md
12
- /examples/test.rb
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in copyleaks_api.gemspec
4
- gemspec
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in plagiarism-checker.gemspec
6
+ gemspec
@@ -1,21 +1,21 @@
1
- The MIT License(MIT)
2
-
3
- Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License(MIT)
2
+
3
+ Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Copyleaks Ruby SDK
2
+
3
+ Copyleaks SDK is a simple framework that allows you to scan text for plagiarism and detect content distribution online, using the Copyleaks plagiarism checker cloud.
4
+
5
+ Using Copyleaks SDK you can check for plagiarism in:
6
+ * Online content and webpages
7
+ * Local and cloud files (see [supported files](https://api.copyleaks.com/documentation/specifications#2-supported-file-types))
8
+ * Free text
9
+ * OCR (Optical Character Recognition) - scanning pictures with textual content (see [supported files](https://api.copyleaks.com/documentation/specifications#6-supported-image-types-ocr))
10
+
11
+ ## Installation
12
+
13
+ Install using [RubyGems](https://rubygems.org/gems/plagiarism-checker)
14
+
15
+ ```bash
16
+ gem install plagiarism-checker
17
+ ```
18
+
19
+ ## Register and Get Your API Key
20
+ To use the Copyleaks API you need to first be a registered user. The registration to Copyleaks takes a minute and is free of charge. [Signup](https://api.copyleaks.com/?register=true) and make sure to confirm your account.
21
+
22
+ As a signed user you can generate your personal API key. Do so on your [dashboard home](https://api.copyleaks.com/dashboard/:product) under 'API Access Credentials'.
23
+
24
+ For more information check out our [API guide](https://api.copyleaks.com/documentation/v3).
25
+
26
+ ## Usage
27
+ ```rb
28
+ require 'copyleaks'
29
+ copyleaks = Copyleaks::API.new
30
+ res = copyleaks.login(<your email>,<your api key>)
31
+ puts res.to_json
32
+ ```
33
+
34
+ ## Demo
35
+ See [demo.rb](./demo/demo.rb) under demo folder for an example.
36
+ ## Read More
37
+ * [API Homepage](https://api.copyleaks.com/)
38
+ * [API Documentation](https://api.copyleaks.com/documentation)
39
+ * [Plagiarism Report](https://github.com/Copyleaks/plagiarism-report)
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: %i[]
@@ -1,7 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
- require 'copyleaks_api'
5
+ require 'copyleaks'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
5
13
 
6
14
  require 'irb'
7
- IRB.start
15
+ IRB.start(__FILE__)
@@ -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,493 @@
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
+ require 'net/http'
25
+ require 'json'
26
+ require 'date'
27
+
28
+ module Copyleaks
29
+ class API
30
+ def initialize
31
+ # copyleaks identity http client
32
+ _identity_server_uri = URI.parse(Config.identity_server_uri)
33
+ @id_client = Net::HTTP.new(_identity_server_uri.host, _identity_server_uri.port)
34
+ @id_client.use_ssl = true
35
+ # copyleaks api http client
36
+ _api_server_uri = URI.parse(Config.api_server_uri)
37
+ @api_client = Net::HTTP.new(_api_server_uri.host, _api_server_uri.port)
38
+ @api_client.use_ssl = true
39
+ end
40
+
41
+ # Login to Copyleaks authentication server.
42
+ # For more info: https://api.copyleaks.com/documentation/v3/account/login.
43
+ # * Exceptions:
44
+ # * * CommandExceptions: Server reject the request. See response status code, headers and content for more info.
45
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance. We recommend to implement exponential backoff algorithm as described here: https://api.copyleaks.com/documentation/v3/exponential-backoff
46
+ # @param [String] email Copyleaks account email address.
47
+ # @param [String] key Copyleaks account secret key.
48
+ # @return A authentication token that being expired after certain amount of time.
49
+ def login(email, key)
50
+ raise 'email is Invalid, must be instance of String' if email.nil? || !email.instance_of?(String)
51
+ raise 'key is Invalid, must be instance of String' if key.nil? || !email.instance_of?(String)
52
+
53
+ path = '/v3/account/login/api'
54
+
55
+ headers = {
56
+ 'Content-Type' => 'application/json',
57
+ 'User-Agent' => Config.user_agent
58
+ }
59
+
60
+ payload = { email: email, key: key }
61
+
62
+ request = Net::HTTP::Post.new(path, headers)
63
+ request.body = payload.to_json
64
+
65
+ res_data = handle_response(@id_client.request(request), 'login')
66
+
67
+ CopyleaksAuthToken.new(res_data['.expires'], res_data['access_token'], res_data['.issued'])
68
+ end
69
+
70
+ # Verify that Copyleaks authentication token is exists and not exipired.
71
+ # * Exceptions:
72
+ # * * AuthExipredException: authentication expired. Need to login again.
73
+ # @param [CopyleaksAuthToken] authToken Copyleaks authentication token
74
+ def verify_auth_token(authToken)
75
+ if authToken.nil? || !authToken.instance_of?(CopyleaksAuthToken)
76
+ raise 'authToken is Invalid, must be instance of CopyleaksAuthToken'
77
+ end
78
+
79
+ _time = DateTime.now
80
+ _expiresTime = DateTime.parse(authToken.expires)
81
+
82
+ if _expiresTime <= _time
83
+ raise AuthExipredException.new.reason # expired
84
+ end
85
+ end
86
+
87
+
88
+ # Starting a new process by providing a file to scan.
89
+ # For more info:
90
+ # https://api.copyleaks.com/documentation/v3/education/submit/file
91
+ # https://api.copyleaks.com/documentation/v3/businesses/submit/file
92
+ # * Exceptions:
93
+ # * * CommandExceptions: Server reject the request. See response status code,
94
+ # headers and content for more info.
95
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
96
+ # We recommend to implement exponential backoff algorithm as described here:
97
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
98
+ # @param [String] product Which product (education or businesses) is being use.
99
+ # @param [CopyleaksAuthToken] authToken Copyleaks authentication token
100
+ # @param [String] scanId Attach your own scan Id
101
+ # @param [CopyleaksFileSubmissionModel] submission Submission properties
102
+ def submit_file(product, authToken, scanId, submission)
103
+ raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String)
104
+ if submission.nil? || !submission.instance_of?(CopyleaksFileSubmissionModel)
105
+ raise 'submission is Invalid, must be instance of type CopyleaksFileSubmissionModel'
106
+ end
107
+
108
+ validate_product(product)
109
+ verify_auth_token(authToken)
110
+
111
+ path = "/v3/#{product}/submit/file/#{scanId}"
112
+
113
+ headers = {
114
+ 'Content-Type' => 'application/json',
115
+ 'User-Agent' => Config.user_agent,
116
+ 'Authorization' => "Bearer #{authToken.accessToken}"
117
+ }
118
+
119
+ request = Net::HTTP::Put.new(path, headers)
120
+ request.body = submission.to_json
121
+
122
+ handle_response(@api_client.request(request), 'submit_file')
123
+ end
124
+
125
+ # Starting a new process by providing a OCR image file to scan.
126
+ # For more info:
127
+ # https://api.copyleaks.com/documentation/v3/education/submit/ocr
128
+ # https://api.copyleaks.com/documentation/v3/businesses/submit/ocr
129
+ # * Exceptions:
130
+ # * * CommandExceptions: Server reject the request. See response status code,
131
+ # headers and content for more info.
132
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
133
+ # We recommend to implement exponential backoff algorithm as described here:
134
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
135
+ # @param [String] product Which product (education or businesses) is being use.
136
+ # @param [CopyleaksAuthToken] authToken Copyleaks authentication token
137
+ # @param [String] scanId Attach your own scan Id
138
+ # @param [CopyleaksFileOcrSubmissionModel] submission Submission properties
139
+ def submit_file_ocr(product, authToken, scanId, submission)
140
+ raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String)
141
+ if submission.nil? || !submission.instance_of?(CopyleaksFileOcrSubmissionModel)
142
+ raise 'submission is Invalid, must be instance of type CopyleaksFileOcrSubmissionModel'
143
+ end
144
+
145
+ validate_product(product)
146
+ verify_auth_token(authToken)
147
+
148
+ path = "/v3/#{product}/submit/ocr/#{scanId}"
149
+
150
+ headers = {
151
+ 'Content-Type' => 'application/json',
152
+ 'User-Agent' => Config.user_agent,
153
+ 'Authorization' => "Bearer #{authToken.accessToken}"
154
+ }
155
+
156
+ request = Net::HTTP::Put.new(path, headers)
157
+ request.body = submission.to_json
158
+
159
+ handle_response(@api_client.request(request), 'submit_file_ocr')
160
+ end
161
+
162
+ # Starting a new process by providing a URL to scan.
163
+ # For more info:
164
+ # https://api.copyleaks.com/documentation/v3/education/submit/url
165
+ # https://api.copyleaks.com/documentation/v3/businesses/submit/url
166
+ # * Exceptions:
167
+ # * * CommandExceptions: Server reject the request. See response status code,
168
+ # headers and content for more info.
169
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
170
+ # We recommend to implement exponential backoff algorithm as described here:
171
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
172
+ # @param [String] product Which product (education or businesses) is being use.
173
+ # @param [CopyleaksAuthToken] authToken Copyleaks authentication token
174
+ # @param [String] scanId Attach your own scan Id
175
+ # @param [CopyleaksURLSubmissionModel] submission Submission properties
176
+ def submit_url(product, authToken, scanId, submission)
177
+ raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String)
178
+ if submission.nil? || !submission.instance_of?(CopyleaksURLSubmissionModel)
179
+ raise 'submission is Invalid, must be instance of CopyleaksURLSubmissionModel'
180
+ end
181
+
182
+ validate_product(product)
183
+ verify_auth_token(authToken)
184
+
185
+ path = "/v3/#{product}/submit/url/#{scanId}"
186
+
187
+ headers = {
188
+ 'Content-Type' => 'application/json',
189
+ 'User-Agent' => Config.user_agent,
190
+ 'Authorization' => "Bearer #{authToken.accessToken}"
191
+ }
192
+
193
+ request = Net::HTTP::Put.new(path, headers)
194
+ request.body = submission.to_json
195
+
196
+ handle_response(@api_client.request(request), 'submit_url')
197
+ end
198
+
199
+ # Exporting scans artifact into your server.
200
+ # For more info:
201
+ # https://api.copyleaks.com/documentation/v3/downloads/export
202
+ # * Exceptions:
203
+ # * * CommandExceptions: Server reject the request. See response status code,
204
+ # headers and content for more info.
205
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
206
+ # We recommend to implement exponential backoff algorithm as described here:
207
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
208
+ # @param [CopyleaksAuthToken] authToken Your login token to Copyleaks server
209
+ # @param [String] scanId The scan ID of the specific scan to export.
210
+ # @param [String] exportId A new Id for the export process.
211
+ # @param [CopyleaksExportModel] model Request of which artifact should be exported.
212
+ def export(authToken, scanId, exportId, model)
213
+ raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String)
214
+ raise 'exportId is Invalid, must be instance of String' if exportId.nil? || !exportId.instance_of?(String)
215
+ if model.nil? || !model.instance_of?(CopyleaksExportModel)
216
+ raise 'model is Invalid, must be instance of type CopyleaksExportModel'
217
+ end
218
+
219
+ verify_auth_token(authToken)
220
+ path = "/v3/downloads/#{scanId}/export/#{exportId}"
221
+
222
+ headers = {
223
+ 'Content-Type' => 'application/json',
224
+ 'User-Agent' => Config.user_agent,
225
+ 'Authorization' => "Bearer #{authToken.accessToken}"
226
+ }
227
+
228
+ request = Net::HTTP::Post.new(path, headers)
229
+ request.body = model.to_json
230
+
231
+ handle_response(@api_client.request(request), 'export')
232
+ end
233
+
234
+ # Start scanning all the files you submitted for a price-check.
235
+ # For more info:
236
+ # https://api.copyleaks.com/documentation/v3/education/start
237
+ # https://api.copyleaks.com/documentation/v3/businesses/start
238
+ # * Exceptions:
239
+ # * * CommandExceptions: Server reject the request. See response status code,
240
+ # headers and content for more info.
241
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
242
+ # We recommend to implement exponential backoff algorithm as described here:
243
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
244
+ # @param [String] product Which product (education or businesses) is being use.
245
+ # @param [CopyleaksAuthToken] authToken Your login token to Copyleaks server.
246
+ # @param [CopyleaksStartRequestModel] data Include information about which scans should be started.
247
+ def start(product, authToken, data)
248
+ if data.nil? || !data.instance_of?(CopyleaksStartRequestModel)
249
+ raise 'data is Invalid, must be instance of type CopyleaksStartRequestModel'
250
+ end
251
+
252
+ validate_product(product)
253
+ verify_auth_token(authToken)
254
+
255
+ path = "/v3/#{product}/start"
256
+
257
+ headers = {
258
+ 'Content-Type' => 'application/json',
259
+ 'User-Agent' => Config.user_agent,
260
+ 'Authorization' => "Bearer #{authToken.accessToken}"
261
+ }
262
+
263
+ request = Net::HTTP::Patch.new(path, headers)
264
+ request.body = data.to_json
265
+
266
+ handle_response(@api_client.request(request), 'start')
267
+ end
268
+
269
+
270
+ # Delete the specific process from the server.
271
+ # For more info:
272
+ # https://api.copyleaks.com/documentation/v3/education/delete
273
+ # https://api.copyleaks.com/documentation/v3/businesses/delete
274
+ # * Exceptions:
275
+ # * * CommandExceptions: Server reject the request. See response status code,
276
+ # headers and content for more info.
277
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
278
+ # We recommend to implement exponential backoff algorithm as described here:
279
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
280
+ # @param [String] product Which product (education or businesses) is being use.
281
+ # @param [CopyleaksAuthToken] authToken Copyleaks authentication token
282
+ # @param [CopyleaksDeleteRequestModel] data
283
+ def delete(product, authToken, data)
284
+ if data.nil? || !data.instance_of?(CopyleaksDeleteRequestModel)
285
+ raise 'data is Invalid, must be instance of CopyleaksDeleteRequestModel'
286
+ end
287
+
288
+ validate_product(product)
289
+ verify_auth_token(authToken)
290
+
291
+ path = "/v3.1/#{product}/delete"
292
+
293
+ headers = {
294
+ 'Content-Type' => 'application/json',
295
+ 'User-Agent' => Config.user_agent,
296
+ 'Authorization' => "Bearer #{authToken.accessToken}"
297
+ }
298
+
299
+ request = Net::HTTP::Patch.new(path, headers)
300
+ request.body = data.to_json
301
+
302
+ handle_response(@api_client.request(request), 'delete')
303
+ end
304
+
305
+ # Resend status webhooks for existing scans.
306
+ # For more info:
307
+ # https://api.copyleaks.com/documentation/v3/education/webhook-resend
308
+ # https://api.copyleaks.com/documentation/v3/businesses/webhook-resend
309
+ # * Exceptions:
310
+ # * * CommandExceptions: Server reject the request. See response status code,
311
+ # headers and content for more info.
312
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
313
+ # We recommend to implement exponential backoff algorithm as described here:
314
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
315
+ # @param [String] product Which product (education or businesses) is being use.
316
+ # @param [CopyleaksAuthToken] authToken Copyleaks authentication token
317
+ # @param [String] scanId Copyleaks scan Id
318
+ def resend_webhook(product, authToken, scanId)
319
+ raise 'scanId is Invalid, must be instance of String' if scanId.nil? || !scanId.instance_of?(String)
320
+
321
+ validate_product(product)
322
+ verify_auth_token(authToken)
323
+
324
+ path = "/v3/#{product}/scans/#{scanId}/webhooks/resend"
325
+
326
+ headers = {
327
+ 'Content-Type' => 'application/json',
328
+ 'User-Agent' => Config.user_agent,
329
+ 'Authorization' => "Bearer #{authToken.accessToken}"
330
+ }
331
+
332
+ request = Net::HTTP::Post.new(path, headers)
333
+ handle_response(@api_client.request(request), 'resend_webhook')
334
+ end
335
+
336
+ # Get current credits balance for the Copyleaks account.
337
+ # For more info:
338
+ # https://api.copyleaks.com/documentation/v3/education/credits
339
+ # https://api.copyleaks.com/documentation/v3/businesses/credits
340
+ # * Exceptions:
341
+ # * * CommandExceptions: Server reject the request. See response status code,
342
+ # headers and content for more info.
343
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
344
+ # We recommend to implement exponential backoff algorithm as described here:
345
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
346
+ # * * RateLimitException: Too many requests. Please wait before calling again.
347
+ # @param [String] product Which product (education or businesses) is being use.
348
+ # @param [CopyleaksAuthToken] authToken Copyleaks authentication token
349
+ def get_credits_balance(product, authToken)
350
+ validate_product(product)
351
+ verify_auth_token(authToken)
352
+
353
+ path = "/v3/#{product}/credits"
354
+
355
+ headers = {
356
+ 'Content-Type' => 'application/json',
357
+ 'User-Agent' => Config.user_agent,
358
+ 'Authorization' => "Bearer #{authToken.accessToken}"
359
+ }
360
+
361
+ request = Net::HTTP::Get.new(path, headers)
362
+ handle_response(@api_client.request(request), 'get_credits_balance')
363
+ end
364
+
365
+ # This endpoint allows you to export your usage history between two dates.
366
+ # The output results will be exported to a csv file and it will be attached to the response.
367
+ # For more info:
368
+ # https://api.copyleaks.com/documentation/v3/education/usages/history
369
+ # https://api.copyleaks.com/documentation/v3/businesses/usages/history
370
+ # * Exceptions:
371
+ # * * CommandExceptions: Server reject the request. See response status code,
372
+ # headers and content for more info.
373
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
374
+ # We recommend to implement exponential backoff algorithm as described here:
375
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
376
+ # * * RateLimitException: Too many requests. Please wait before calling again.
377
+ # @param [String] product Which product (education or businesses) is being use.
378
+ # @param [CopyleaksAuthToken] authToken Copyleaks authentication token.
379
+ # @param [String] startDate The start date to collect usage history from. Date Format: `dd-MM-yyyy`.
380
+ # @param [String] endDate The end date to collect usage history from. Date Format: `dd-MM-yyyy`.
381
+ def get_usages_history_csv(product, authToken, startDate, endDate)
382
+ raise 'startDate is Invalid, must be instance of String' if startDate.nil? || !startDate.instance_of?(String)
383
+ raise 'endDate is Invalid, must be instance of String' if endDate.nil? || !endDate.instance_of?(String)
384
+
385
+ validate_product(product)
386
+ verify_auth_token(authToken)
387
+
388
+ path = "/v3/#{product}/usages/history?start=#{startDate}&end=#{endDate}"
389
+
390
+ headers = {
391
+ 'Content-Type' => 'application/json',
392
+ 'User-Agent' => Config.user_agent,
393
+ 'Authorization' => "Bearer #{authToken.accessToken}"
394
+ }
395
+
396
+ request = Net::HTTP::Get.new(path, headers)
397
+ handle_response(@api_client.request(request), 'get_usages_history_csv')
398
+ end
399
+
400
+ # Get a list of the supported languages for OCR (this is not a list of supported languages for the api, but only for the OCR files scan).
401
+ # For more info: https://api.copyleaks.com/documentation/v3/specifications/ocr-languages/list
402
+ # * Exceptions:
403
+ # * * CommandExceptions: Server reject the request. See response status code,
404
+ # headers and content for more info.
405
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
406
+ # We recommend to implement exponential backoff algorithm as described here:
407
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
408
+ # * * RateLimitException: Too many requests. Please wait before calling again.
409
+ # @return array List of supported OCR languages.
410
+ def get_ocr_supported_languages
411
+ path = '/v3/miscellaneous/ocr-languages-list'
412
+
413
+ headers = {
414
+ 'Content-Type' => 'application/json',
415
+ 'User-Agent' => Config.user_agent
416
+ }
417
+ request = Net::HTTP::Get.new(path, headers)
418
+ handle_response(@api_client.request(request), 'get_ocr_supported_languages')
419
+ end
420
+
421
+ # Get a list of the supported file types.
422
+ # For more info: https://api.copyleaks.com/documentation/v3/specifications/supported-file-types
423
+ # * Exceptions:
424
+ # * * CommandExceptions: Server reject the request. See response status code,
425
+ # headers and content for more info.
426
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
427
+ # We recommend to implement exponential backoff algorithm as described here:
428
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
429
+ # * * RateLimitException: Too many requests. Please wait before calling again.
430
+ # @return mixed List of supported file types.
431
+ def get_supported_file_types
432
+ path = '/v3/miscellaneous/supported-file-types'
433
+
434
+ headers = {
435
+ 'Content-Type' => 'application/json',
436
+ 'User-Agent' => Config.user_agent
437
+ }
438
+
439
+ request = Net::HTTP::Get.new(path, headers)
440
+ handle_response(@api_client.request(request), 'get_supported_file_types')
441
+ end
442
+
443
+ # Get updates about copyleaks api release notes.
444
+ # For more info: https://api.copyleaks.com/documentation/v3/release-notes
445
+ # * Exceptions:
446
+ # * * CommandExceptions: Server reject the request. See response status code,
447
+ # headers and content for more info.
448
+ # * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
449
+ # We recommend to implement exponential backoff algorithm as described here:
450
+ # https://api.copyleaks.com/documentation/v3/exponential-backoff
451
+ # * * RateLimitException: Too many requests. Please wait before calling again.
452
+ # @return mixed List of release notes.
453
+ def get_release_notes
454
+ path = '/v3/release-logs.json'
455
+
456
+ header = {
457
+ 'Content-Type' => 'application/json',
458
+ 'User-Agent' => Config.user_agent
459
+ }
460
+ request = Net::HTTP::Get.new(path, header)
461
+ handle_response(@api_client.request(request), 'get_release_notes')
462
+ end
463
+
464
+ def validate_product(product)
465
+ if product.nil? || (product != 'education' && product != 'businesses')
466
+ raise "Invalid product, product must be set to 'education' or 'businesses'"
467
+ end
468
+ end
469
+
470
+ # this methods is a helper for hanlding reponse data and exceptions.
471
+ def handle_response(response, used_by)
472
+ if Utils.is_success_status_code(response.code)
473
+ if response.body.nil? || response.body == ''
474
+ nil
475
+ else
476
+ JSON.parse(response.body)
477
+ end
478
+ elsif Utils.is_under_maintenance_response(response.code)
479
+ raise UnderMaintenanceException.new.reason
480
+ elsif Utils.is_rate_limit_response(response.code)
481
+ raise RateLimitException.new.reason
482
+ else
483
+ _err_message = '---------Copyleaks SDK Error (' + used_by + ')---------' + "\n\n"
484
+ _err_message += 'status code: ' + response.code + "\n\n"
485
+
486
+ _err_message += 'response body:' + "\n" + response.body.to_json + "\n\n" unless response.body.nil?
487
+
488
+ _err_message += '-------------------------------------'
489
+ raise CommandException.new(_err_message).reason + "\n"
490
+ end
491
+ end
492
+ end
493
+ end