Copyleaks Ruby SDK
Copyleaks SDK is a simple framework that allows you to scan textual content for plagiarism and trace content distribution online, using the Copyleaks plagiarism checker cloud.
Detect plagiarism using Copyleaks SDK in:
- Online content and webpages
- Local and cloud files (see supported files
- Free text
- OCR (Optical Character Recognition) - scanning pictures with textual content (see supported files)
Installation
Add this line to your application's Gemfile:
gem 'copyleaks_api'
And then execute:
$ bundle
Or jsut using command:
$ gem install copyleaks_api
Requirements
This gem tested on ruby-1.9.3-p551, jruby-9.0.5.0 and ruby-2.3.0.
Usage
Firstly you need to crate connection with your api-key and email:
cloud = CopyleaksApi::CopyleaksCloud.new(my_email, my_api_key)
After this you can scan you image:
process = cloud.create_by_ocr(path_to_image, language: Copyleaks::Language.english)
Methods create_by_url, create_by_file, create_by_text, status, result and list returns CopyleaksApi::CopyleaksProcess objects. When you want to check changes of it's status you can just reload it:
process.reload
process.finished?
This firstly get new data from Copyleaks and return true if this process now has status Finished.
Configuration
You can specify all necessary configuration in one place just using:
CopyleaksApi::Config do |config|
config.sanbox_mode = true
config.allow_partial_scan = true
config.http_callback = 'http://yoursite.here'
config.email_callback = '[email protected]'
config.custom_fields = { some_field: 'and its value' }
end
Or just call methods:
CopyleaksApi::Config.sandbox_mode = true
Also some parameters can be specified in method arguments.
If you want to disable all callbacks you can pass no_callbak: true optoin to any create method (no_http_callback or no_email_callback to disable only one). no_custom_fields works the same way.
Errors
| Class | Description |
|---|---|
| BasicError | Superclass error for all gem errors |
| BadCustomFieldError | Given custom fields didnt pass validation (key/value/overall size is to large) |
| BadFileError | Given file is too large |
| BadEmailError | Given email for callback is invalid |
| BadUrlError | Given callback url is invalid |
| UnknownLanguageError | Given language for OCR is invalid |
| BadResponseError | Reponse fro API has not 200 code |
| ManagedError | Reponse contains manages Copyleaks error code (all list are given here) |
Examples
For fast test you could launch examples/main.rb script. It has a lot of comments so there is no need in additional descriptions. You just need to change email and api_key values.