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
 
| 
         @@ -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,210 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'json'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'net/http'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'mimemagic'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'mimemagic/overlay'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'openssl'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'securerandom'
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            module CopyleaksApi
         
     | 
| 
       10 
     | 
    
         
            -
              class Api
         
     | 
| 
       11 
     | 
    
         
            -
                BASE_URL = 'https://api.copyleaks.com'.freeze
         
     | 
| 
       12 
     | 
    
         
            -
                API_VERSION_V1 = 'v1'.freeze
         
     | 
| 
       13 
     | 
    
         
            -
                API_VERSION_V2 = 'v2'.freeze
         
     | 
| 
       14 
     | 
    
         
            -
              
         
     | 
| 
       15 
     | 
    
         
            -
                # constructor
         
     | 
| 
       16 
     | 
    
         
            -
                def initialize
         
     | 
| 
       17 
     | 
    
         
            -
                  uri = URI(BASE_URL)
         
     | 
| 
       18 
     | 
    
         
            -
                  @http = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
       19 
     | 
    
         
            -
                  @http.use_ssl = true
         
     | 
| 
       20 
     | 
    
         
            -
                  @http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                # make get request without any callback header
         
     | 
| 
       24 
     | 
    
         
            -
                def get(path, options = {})
         
     | 
| 
       25 
     | 
    
         
            -
                  request = Net::HTTP::Get.new(request_uri(path))
         
     | 
| 
       26 
     | 
    
         
            -
                  make_request(request, options.merge(no_callbacks: true))
         
     | 
| 
       27 
     | 
    
         
            -
                end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                # make get request without any callback header
         
     | 
| 
       30 
     | 
    
         
            -
                def get_with_final_path(path, options = {})
         
     | 
| 
       31 
     | 
    
         
            -
                  request = Net::HTTP::Get.new(path)
         
     | 
| 
       32 
     | 
    
         
            -
                  make_request(request, options.merge(no_callbacks: true))
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                # make post request with given options
         
     | 
| 
       36 
     | 
    
         
            -
                def post(path, body = nil, options = {})
         
     | 
| 
       37 
     | 
    
         
            -
                  request = Net::HTTP::Post.new(request_uri(path))
         
     | 
| 
       38 
     | 
    
         
            -
                  request.body = body
         
     | 
| 
       39 
     | 
    
         
            -
                  make_request(request, options)
         
     | 
| 
       40 
     | 
    
         
            -
                end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                # makes delete request without callbacks
         
     | 
| 
       43 
     | 
    
         
            -
                def delete(path, options = {})
         
     | 
| 
       44 
     | 
    
         
            -
                  request = Net::HTTP::Delete.new(request_uri(path))
         
     | 
| 
       45 
     | 
    
         
            -
                  make_request(request, options.merge(no_callbacks: true))
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                # makes post request with file inside
         
     | 
| 
       49 
     | 
    
         
            -
                def post_file(path, file_path, options = {})
         
     | 
| 
       50 
     | 
    
         
            -
                  request = Net::HTTP::Post.new(request_uri(path))
         
     | 
| 
       51 
     | 
    
         
            -
                  options[:partial_scan] ||= CopyleaksApi::Config.allow_partial_scan
         
     | 
| 
       52 
     | 
    
         
            -
                  boundary = "copyleaks_sdk_#{SecureRandom.hex(4)}"
         
     | 
| 
       53 
     | 
    
         
            -
                  request.body = file_body(file_path, boundary)
         
     | 
| 
       54 
     | 
    
         
            -
                  make_request(request, options.merge(boundary: boundary))
         
     | 
| 
       55 
     | 
    
         
            -
                end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                # makes post request with file inside
         
     | 
| 
       58 
     | 
    
         
            -
                def post_files(path, files_paths, options = {})
         
     | 
| 
       59 
     | 
    
         
            -
                  request = Net::HTTP::Post.new(request_uri(path, api_version: API_VERSION_V2))
         
     | 
| 
       60 
     | 
    
         
            -
                  options[:partial_scan] ||= CopyleaksApi::Config.allow_partial_scan
         
     | 
| 
       61 
     | 
    
         
            -
                  options[:compare_only] ||= CopyleaksApi::Config.compare_only
         
     | 
| 
       62 
     | 
    
         
            -
                  boundary = "copyleaks_sdk_#{SecureRandom.hex(4)}"
         
     | 
| 
       63 
     | 
    
         
            -
                  request.body = files_body(files_paths, boundary)
         
     | 
| 
       64 
     | 
    
         
            -
                  make_request(request, options.merge(boundary: boundary))
         
     | 
| 
       65 
     | 
    
         
            -
                end
         
     | 
| 
       66 
     | 
    
         
            -
                private
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                # extracts mime type of given file
         
     | 
| 
       69 
     | 
    
         
            -
                def extract_mime_type(path)
         
     | 
| 
       70 
     | 
    
         
            -
                  mime = MimeMagic.by_magic(File.open(path))
         
     | 
| 
       71 
     | 
    
         
            -
                  mime ? mime.type : 'text/plain'
         
     | 
| 
       72 
     | 
    
         
            -
                end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                # prepares post body with file inside
         
     | 
| 
       75 
     | 
    
         
            -
                def file_body(path, boundary)
         
     | 
| 
       76 
     | 
    
         
            -
                  [
         
     | 
| 
       77 
     | 
    
         
            -
                    "\r\n--#{boundary}\r\n",
         
     | 
| 
       78 
     | 
    
         
            -
                    "content-disposition: form-data; name=\"file\"",
         
     | 
| 
       79 
     | 
    
         
            -
                    "; filename=\"#{File.basename(path)}\"\r\n",
         
     | 
| 
       80 
     | 
    
         
            -
                    "Content-Type: #{extract_mime_type(path)}\r\n",
         
     | 
| 
       81 
     | 
    
         
            -
                    "Content-Transfer-Encoding: binary\r\n",
         
     | 
| 
       82 
     | 
    
         
            -
                    "\r\n",
         
     | 
| 
       83 
     | 
    
         
            -
                    File.open(path, 'rb') { |io| io.read },
         
     | 
| 
       84 
     | 
    
         
            -
                    "\r\n--#{boundary}--\r\n"
         
     | 
| 
       85 
     | 
    
         
            -
                  ].join('')
         
     | 
| 
       86 
     | 
    
         
            -
                end
         
     | 
| 
       87 
     | 
    
         
            -
                
         
     | 
| 
       88 
     | 
    
         
            -
                    # prepares post body with file inside
         
     | 
| 
       89 
     | 
    
         
            -
                def files_body(paths, boundary)
         
     | 
| 
       90 
     | 
    
         
            -
                  body = "\r\n--#{boundary}\r\n"
         
     | 
| 
       91 
     | 
    
         
            -
                  counter = 1
         
     | 
| 
       92 
     | 
    
         
            -
                  paths.each do |path|
         
     | 
| 
       93 
     | 
    
         
            -
                    body += "content-disposition: form-data; name=\"file_#{counter}\"" +
         
     | 
| 
       94 
     | 
    
         
            -
                            "; filename=\"#{File.basename(path)}\"\r\n" +
         
     | 
| 
       95 
     | 
    
         
            -
                            "Content-Type: #{extract_mime_type(path)}\r\n" +
         
     | 
| 
       96 
     | 
    
         
            -
                            "Content-Transfer-Encoding: binary\r\n" +
         
     | 
| 
       97 
     | 
    
         
            -
                            "\r\n" +
         
     | 
| 
       98 
     | 
    
         
            -
                            File.open(path, 'rb') { |io| io.read } +
         
     | 
| 
       99 
     | 
    
         
            -
                            "\r\n--#{boundary}\r\n"
         
     | 
| 
       100 
     | 
    
         
            -
                    counter += 1
         
     | 
| 
       101 
     | 
    
         
            -
                  end
         
     | 
| 
       102 
     | 
    
         
            -
                  body += "\r\n--#{boundary}--\r\n"
         
     | 
| 
       103 
     | 
    
         
            -
                  body
         
     | 
| 
       104 
     | 
    
         
            -
                end
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                # gather all API path
         
     | 
| 
       107 
     | 
    
         
            -
                def request_uri(path, api_version: API_VERSION_V1)
         
     | 
| 
       108 
     | 
    
         
            -
                  "/#{api_version}/#{path}"
         
     | 
| 
       109 
     | 
    
         
            -
                end
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
                # gather headers, makes request and do validation
         
     | 
| 
       112 
     | 
    
         
            -
                def make_request(request, options)
         
     | 
| 
       113 
     | 
    
         
            -
                  gather_headers(request, options)
         
     | 
| 
       114 
     | 
    
         
            -
                  response = @http.request(request)
         
     | 
| 
       115 
     | 
    
         
            -
                  Validators::ResponseValidator.validate!(response)
         
     | 
| 
       116 
     | 
    
         
            -
                  if not options.key?(:parse_json) or options[:parse_json]
         
     | 
| 
       117 
     | 
    
         
            -
                    JSON.parse(response.body)
         
     | 
| 
       118 
     | 
    
         
            -
                  else
         
     | 
| 
       119 
     | 
    
         
            -
                    response.body
         
     | 
| 
       120 
     | 
    
         
            -
                  end
         
     | 
| 
       121 
     | 
    
         
            -
                end
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                # gather all headers
         
     | 
| 
       124 
     | 
    
         
            -
                def gather_headers(request, options)
         
     | 
| 
       125 
     | 
    
         
            -
                  [
         
     | 
| 
       126 
     | 
    
         
            -
                    http_callbacks_header(options),
         
     | 
| 
       127 
     | 
    
         
            -
                    email_callback_header(options),
         
     | 
| 
       128 
     | 
    
         
            -
                    authentication_header(options),
         
     | 
| 
       129 
     | 
    
         
            -
                    sandbox_header,
         
     | 
| 
       130 
     | 
    
         
            -
                    compare_only_header,
         
     | 
| 
       131 
     | 
    
         
            -
                    in_progress_result(options),
         
     | 
| 
       132 
     | 
    
         
            -
                    content_type_header(options),
         
     | 
| 
       133 
     | 
    
         
            -
                    partial_scan_header(options),
         
     | 
| 
       134 
     | 
    
         
            -
                    'User-Agent' => "RUBYSDK/#{CopyleaksApi::VERSION}"
         
     | 
| 
       135 
     | 
    
         
            -
                  ].reduce({}, :merge).each do |header, value|
         
     | 
| 
       136 
     | 
    
         
            -
                    request[header] = value
         
     | 
| 
       137 
     | 
    
         
            -
                  end
         
     | 
| 
       138 
     | 
    
         
            -
                end
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
                # prepares header for sandbox mode
         
     | 
| 
       141 
     | 
    
         
            -
                def sandbox_header
         
     | 
| 
       142 
     | 
    
         
            -
                  return {} unless Config.sandbox_mode
         
     | 
| 
       143 
     | 
    
         
            -
                  { 'copyleaks-sandbox-mode' => '' }
         
     | 
| 
       144 
     | 
    
         
            -
                end
         
     | 
| 
       145 
     | 
    
         
            -
                
         
     | 
| 
       146 
     | 
    
         
            -
                # Compare your files against each other only
         
     | 
| 
       147 
     | 
    
         
            -
                def compare_only_header
         
     | 
| 
       148 
     | 
    
         
            -
                  return {} unless Config.compare_only
         
     | 
| 
       149 
     | 
    
         
            -
                  { 'copyleaks-compare-documents-for-similarity' => '' }
         
     | 
| 
       150 
     | 
    
         
            -
                end
         
     | 
| 
       151 
     | 
    
         
            -
                
         
     | 
| 
       152 
     | 
    
         
            -
                # Receive callback every time we find a new result without waiting for completion
         
     | 
| 
       153 
     | 
    
         
            -
                def in_progress_result(options)
         
     | 
| 
       154 
     | 
    
         
            -
                  return {} if options[:no_http_callback] || options[:no_callbacks]
         
     | 
| 
       155 
     | 
    
         
            -
                  value = options[:in_progress_result] || CopyleaksApi::Config.in_progress_result
         
     | 
| 
       156 
     | 
    
         
            -
                  return {} unless value
         
     | 
| 
       157 
     | 
    
         
            -
                  Validators::UrlValidator.validate!(value)
         
     | 
| 
       158 
     | 
    
         
            -
                  { 'copyleaks-in-progress-new-result' => value }
         
     | 
| 
       159 
     | 
    
         
            -
                end
         
     | 
| 
       160 
     | 
    
         
            -
                # prepares header for content type
         
     | 
| 
       161 
     | 
    
         
            -
                def content_type_header(options)
         
     | 
| 
       162 
     | 
    
         
            -
                  { 'Content-Type' => options[:boundary] ? "multipart/form-data; boundary=\"#{options[:boundary]}\"" :
         
     | 
| 
       163 
     | 
    
         
            -
                                                           'application/json' }
         
     | 
| 
       164 
     | 
    
         
            -
                end
         
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
                # prepares header for partial scan
         
     | 
| 
       167 
     | 
    
         
            -
                def partial_scan_header(options)
         
     | 
| 
       168 
     | 
    
         
            -
                  return {} unless !options[:allow_partial_scan].nil? && options[:allow_partial_scan] || Config.allow_partial_scan
         
     | 
| 
       169 
     | 
    
         
            -
                  { 'copyleaks-allow-partial-scan' => '' }
         
     | 
| 
       170 
     | 
    
         
            -
                end
         
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
     | 
    
         
            -
                # prepares authentication header
         
     | 
| 
       173 
     | 
    
         
            -
                def authentication_header(options)
         
     | 
| 
       174 
     | 
    
         
            -
                  return {} unless options[:token]
         
     | 
| 
       175 
     | 
    
         
            -
                  { 'Authorization' => "Bearer #{options[:token]}" }
         
     | 
| 
       176 
     | 
    
         
            -
                end
         
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
                # prepare header for http callback
         
     | 
| 
       179 
     | 
    
         
            -
                def http_callbacks_header(options)
         
     | 
| 
       180 
     | 
    
         
            -
                  return {} if options[:no_http_callback] || options[:no_callbacks]
         
     | 
| 
       181 
     | 
    
         
            -
                  value = options[:http_callback] || CopyleaksApi::Config.http_callback
         
     | 
| 
       182 
     | 
    
         
            -
                  return {} unless value
         
     | 
| 
       183 
     | 
    
         
            -
                  Validators::UrlValidator.validate!(value)
         
     | 
| 
       184 
     | 
    
         
            -
                  { 'copyleaks-http-completion-callback' => value }
         
     | 
| 
       185 
     | 
    
         
            -
                end
         
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
                # prepares header for email callback
         
     | 
| 
       188 
     | 
    
         
            -
                def email_callback_header(options)
         
     | 
| 
       189 
     | 
    
         
            -
                  return {} if options[:no_email_callback] || options[:no_callbacks]
         
     | 
| 
       190 
     | 
    
         
            -
                  value = options[:email_callback] || CopyleaksApi::Config.email_callback
         
     | 
| 
       191 
     | 
    
         
            -
                  return {} unless value
         
     | 
| 
       192 
     | 
    
         
            -
                  Validators::EmailValidator.validate!(value)
         
     | 
| 
       193 
     | 
    
         
            -
                  { 'copyleaks-email-callback' => value }
         
     | 
| 
       194 
     | 
    
         
            -
                end
         
     | 
| 
       195 
     | 
    
         
            -
             
     | 
| 
       196 
     | 
    
         
            -
                
         
     | 
| 
       197 
     | 
    
         
            -
                # prepares headers with custom fields
         
     | 
| 
       198 
     | 
    
         
            -
                def custom_field_headers(options)
         
     | 
| 
       199 
     | 
    
         
            -
                  return {} if options[:no_custom_fields]
         
     | 
| 
       200 
     | 
    
         
            -
                  value = CopyleaksApi::Config.custom_fields.merge(options[:custom_fields] || {})
         
     | 
| 
       201 
     | 
    
         
            -
                  Validators::CustomFieldsValidator.validate!(value)
         
     | 
| 
       202 
     | 
    
         
            -
                  prepare_custom_fields(value)
         
     | 
| 
       203 
     | 
    
         
            -
                end
         
     | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
                # prepares custom fields before transformation into headers
         
     | 
| 
       206 
     | 
    
         
            -
                def prepare_custom_fields(fields)
         
     | 
| 
       207 
     | 
    
         
            -
                  fields.each_with_object({}) { |e, o| o["copyleaks-client-custom-#{e[0]}"] = e[1] }
         
     | 
| 
       208 
     | 
    
         
            -
                end
         
     | 
| 
       209 
     | 
    
         
            -
              end
         
     | 
| 
       210 
     | 
    
         
            -
            end
         
     | 
    
        data/lib/copyleaks_api/config.rb
    DELETED
    
    | 
         @@ -1,36 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module CopyleaksApi
         
     | 
| 
       2 
     | 
    
         
            -
              class Config
         
     | 
| 
       3 
     | 
    
         
            -
                DEFAULTS = {
         
     | 
| 
       4 
     | 
    
         
            -
                  sandbox_mode: false,
         
     | 
| 
       5 
     | 
    
         
            -
                  allow_partial_scan: false,
         
     | 
| 
       6 
     | 
    
         
            -
                  http_callback: nil,
         
     | 
| 
       7 
     | 
    
         
            -
                  email_callback: nil,
         
     | 
| 
       8 
     | 
    
         
            -
                  custom_fields: {},
         
     | 
| 
       9 
     | 
    
         
            -
                  compare_only: false,
         
     | 
| 
       10 
     | 
    
         
            -
                  in_progress_result: nil,
         
     | 
| 
       11 
     | 
    
         
            -
                }.freeze
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                class << self
         
     | 
| 
       14 
     | 
    
         
            -
                  attr_writer :sandbox_mode, :compare_only, :http_callback, :email_callback, :custom_fields, :allow_partial_scan, :in_progress_result
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                  DEFAULTS.each do |attr, value|
         
     | 
| 
       17 
     | 
    
         
            -
                    # getters for all options
         
     | 
| 
       18 
     | 
    
         
            -
                    define_method(attr) do
         
     | 
| 
       19 
     | 
    
         
            -
                      var = instance_variable_get("@#{attr}")
         
     | 
| 
       20 
     | 
    
         
            -
                      return var if var
         
     | 
| 
       21 
     | 
    
         
            -
                      instance_variable_set("@#{attr}", value)
         
     | 
| 
       22 
     | 
    
         
            -
                    end
         
     | 
| 
       23 
     | 
    
         
            -
                  end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                  # provide block syntax possibility for setting options
         
     | 
| 
       26 
     | 
    
         
            -
                  def config
         
     | 
| 
       27 
     | 
    
         
            -
                    yield(self)
         
     | 
| 
       28 
     | 
    
         
            -
                  end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                  # reset all options to default
         
     | 
| 
       31 
     | 
    
         
            -
                  def reset
         
     | 
| 
       32 
     | 
    
         
            -
                    DEFAULTS.each { |attr, value| instance_variable_set("@#{attr}", value) }
         
     | 
| 
       33 
     | 
    
         
            -
                  end
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
     | 
    
         
            -
              end
         
     | 
| 
       36 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,116 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'copyleaks_api/errors'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'copyleaks_api/api'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            module CopyleaksApi
         
     | 
| 
       6 
     | 
    
         
            -
              class CopyleaksCloud
         
     | 
| 
       7 
     | 
    
         
            -
                ALLOWED_ENDPOINTS = [:businesses, :education, :websites]
         
     | 
| 
       8 
     | 
    
         
            -
                attr_accessor :access_token
         
     | 
| 
       9 
     | 
    
         
            -
                attr_reader :endpoint_type
         
     | 
| 
       10 
     | 
    
         
            -
                
         
     | 
| 
       11 
     | 
    
         
            -
                # constructor
         
     | 
| 
       12 
     | 
    
         
            -
                def initialize(email, api_key, type)
         
     | 
| 
       13 
     | 
    
         
            -
                  raise ArgumentError, "Endpoint type '#{type}' is invalid" unless ALLOWED_ENDPOINTS.include?(type.to_sym)
         
     | 
| 
       14 
     | 
    
         
            -
                  @access_token = AccessToken.new(self, email, api_key)
         
     | 
| 
       15 
     | 
    
         
            -
                  @endpoint_type = type
         
     | 
| 
       16 
     | 
    
         
            -
                end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                def api
         
     | 
| 
       19 
     | 
    
         
            -
                  @api ||= CopyleaksApi::Api.new
         
     | 
| 
       20 
     | 
    
         
            -
                end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                # returns account balance from endpoint
         
     | 
| 
       23 
     | 
    
         
            -
                def get_credits_balance
         
     | 
| 
       24 
     | 
    
         
            -
            	    api.get(url('count-credits'), token: @access_token.token)['Amount'].to_i
         
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                # uses create-by-url endpoint to create process
         
     | 
| 
       28 
     | 
    
         
            -
                def create_by_url(url, options = {})
         
     | 
| 
       29 
     | 
    
         
            -
                  response = api.post(url('create-by-url'), { 'Url' => url }.to_json, options.merge(token: @access_token.token))
         
     | 
| 
       30 
     | 
    
         
            -
                  CopyleaksProcess.create(self, api, response)
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                # uses create-by-file endpoint to create process
         
     | 
| 
       34 
     | 
    
         
            -
                def create_by_file(file_path, options = {})
         
     | 
| 
       35 
     | 
    
         
            -
                  response = api.post_file(url('create-by-file'), file_path, options.merge(token: @access_token.token))
         
     | 
| 
       36 
     | 
    
         
            -
                  CopyleaksProcess.create(self, api, response)
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                # uses create-by-file endpoint to create process
         
     | 
| 
       40 
     | 
    
         
            -
                def create_by_files(files_paths, options = {})
         
     | 
| 
       41 
     | 
    
         
            -
                  response = api.post_files(url('create-by-file'), files_paths, options.merge(token: @access_token.token))
         
     | 
| 
       42 
     | 
    
         
            -
                  success_uploads = response['Success']
         
     | 
| 
       43 
     | 
    
         
            -
                  processes = []
         
     | 
| 
       44 
     | 
    
         
            -
                  success_uploads.each do |upload|
         
     | 
| 
       45 
     | 
    
         
            -
                    processes.push(CopyleaksProcess.create(self, api, upload))
         
     | 
| 
       46 
     | 
    
         
            -
                  end
         
     | 
| 
       47 
     | 
    
         
            -
                  processes
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                # uses create-by-file-ocr endpoint to create process
         
     | 
| 
       51 
     | 
    
         
            -
                def create_by_ocr(ocr_file_path, options = {})
         
     | 
| 
       52 
     | 
    
         
            -
                  response = api.post_file(url_with_language('create-by-file-ocr', options), ocr_file_path,
         
     | 
| 
       53 
     | 
    
         
            -
                                           options.merge(token: @access_token.token))
         
     | 
| 
       54 
     | 
    
         
            -
                  CopyleaksProcess.create(self, api, response)
         
     | 
| 
       55 
     | 
    
         
            -
                end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                # uses create-by-text endpoint to create process
         
     | 
| 
       58 
     | 
    
         
            -
                def create_by_text(text, options = {})
         
     | 
| 
       59 
     | 
    
         
            -
                  response = api.post(url('create-by-text'), text, options.merge(token: @access_token.token))
         
     | 
| 
       60 
     | 
    
         
            -
                  CopyleaksProcess.create(self, api, response)
         
     | 
| 
       61 
     | 
    
         
            -
                end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                # Returns a list of your past processes
         
     | 
| 
       64 
     | 
    
         
            -
                def get_processes
         
     | 
| 
       65 
     | 
    
         
            -
                  response = api.get(url(:list), token: @access_token.token)
         
     | 
| 
       66 
     | 
    
         
            -
                  response.map { |hash| CopyleaksProcess.create_from_list(self, @api, hash) }
         
     | 
| 
       67 
     | 
    
         
            -
                end
         
     | 
| 
       68 
     | 
    
         
            -
                
         
     | 
| 
       69 
     | 
    
         
            -
                # Returns the raw text of a given result
         
     | 
| 
       70 
     | 
    
         
            -
                def get_raw_text(result)
         
     | 
| 
       71 
     | 
    
         
            -
                  response = api.get_with_final_path(result.get_cached_version, parse_json: false, token: @access_token.token)
         
     | 
| 
       72 
     | 
    
         
            -
                  response
         
     | 
| 
       73 
     | 
    
         
            -
                end
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                # Returns the raw text of a given result
         
     | 
| 
       76 
     | 
    
         
            -
                def get_comparison_report(result)
         
     | 
| 
       77 
     | 
    
         
            -
                  response = api.get_with_final_path(result.get_comparison_report, token: @access_token.token)
         
     | 
| 
       78 
     | 
    
         
            -
                  response
         
     | 
| 
       79 
     | 
    
         
            -
                end
         
     | 
| 
       80 
     | 
    
         
            -
                
         
     | 
| 
       81 
     | 
    
         
            -
                # Returns a list of currently supported languages for ocr 
         
     | 
| 
       82 
     | 
    
         
            -
                def get_ocr_languages
         
     | 
| 
       83 
     | 
    
         
            -
                  response = api.get(url_misc('ocr-languages-list'))
         
     | 
| 
       84 
     | 
    
         
            -
                  response
         
     | 
| 
       85 
     | 
    
         
            -
                end
         
     | 
| 
       86 
     | 
    
         
            -
                
         
     | 
| 
       87 
     | 
    
         
            -
                # Returns a list of currently supported file types
         
     | 
| 
       88 
     | 
    
         
            -
                def get_supported_file_types
         
     | 
| 
       89 
     | 
    
         
            -
                  response = api.get(url_misc('supported-file-types'))
         
     | 
| 
       90 
     | 
    
         
            -
                  response
         
     | 
| 
       91 
     | 
    
         
            -
                end
         
     | 
| 
       92 
     | 
    
         
            -
                
         
     | 
| 
       93 
     | 
    
         
            -
                # gather url for endpoints which need language in get parameters
         
     | 
| 
       94 
     | 
    
         
            -
                def url_with_language(action, options)
         
     | 
| 
       95 
     | 
    
         
            -
                  language = options[:language] || Language.english
         
     | 
| 
       96 
     | 
    
         
            -
                  Validators::LanguageValidator.validate!(language)
         
     | 
| 
       97 
     | 
    
         
            -
                  url("#{action}?language=#{language}")
         
     | 
| 
       98 
     | 
    
         
            -
                end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                # gather path for endpoints
         
     | 
| 
       101 
     | 
    
         
            -
                def url(action, id = nil)
         
     | 
| 
       102 
     | 
    
         
            -
                  return "#{@endpoint_type}/#{action}" if id.nil?
         
     | 
| 
       103 
     | 
    
         
            -
                  "#{@endpoint_type}/#{id}/#{action}"
         
     | 
| 
       104 
     | 
    
         
            -
                end
         
     | 
| 
       105 
     | 
    
         
            -
                
         
     | 
| 
       106 
     | 
    
         
            -
                # gather path for download endpoint
         
     | 
| 
       107 
     | 
    
         
            -
                def url_downloads(action, id = nil)
         
     | 
| 
       108 
     | 
    
         
            -
                  return "downloads/#{action}"
         
     | 
| 
       109 
     | 
    
         
            -
                end
         
     | 
| 
       110 
     | 
    
         
            -
                
         
     | 
| 
       111 
     | 
    
         
            -
                # gather path for download endpoint
         
     | 
| 
       112 
     | 
    
         
            -
                def url_misc(action, id = nil)
         
     | 
| 
       113 
     | 
    
         
            -
                  return "miscellaneous/#{action}"
         
     | 
| 
       114 
     | 
    
         
            -
                end
         
     | 
| 
       115 
     | 
    
         
            -
              end
         
     | 
| 
       116 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,78 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'time'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'copyleaks_api/Models/ResultRecord'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            module CopyleaksApi
         
     | 
| 
       6 
     | 
    
         
            -
              class CopyleaksProcess
         
     | 
| 
       7 
     | 
    
         
            -
                attr_accessor :process_id, :progress, :custom_fields, :created_at
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                # constructor
         
     | 
| 
       10 
     | 
    
         
            -
                def initialize(options)
         
     | 
| 
       11 
     | 
    
         
            -
                  @cloud = options[:cloud]
         
     | 
| 
       12 
     | 
    
         
            -
                  [:cloud, :api, :process_id, :custom_fields, :result, :progress].each do |attr|
         
     | 
| 
       13 
     | 
    
         
            -
                    instance_variable_set("@#{attr}", options[attr]) if options[attr]
         
     | 
| 
       14 
     | 
    
         
            -
                  end
         
     | 
| 
       15 
     | 
    
         
            -
                  @created_at = DateTime.parse(options[:created_at]) if options[:created_at]
         
     | 
| 
       16 
     | 
    
         
            -
                end
         
     | 
| 
       17 
     | 
    
         
            -
                
         
     | 
| 
       18 
     | 
    
         
            -
                def to_s
         
     | 
| 
       19 
     | 
    
         
            -
                  return "Created at: #{@created_at}"
         
     | 
| 
       20 
     | 
    
         
            -
                end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                # returns true if still processing data on server side
         
     | 
| 
       23 
     | 
    
         
            -
                def processing?
         
     | 
| 
       24 
     | 
    
         
            -
                  if @progress == 100
         
     | 
| 
       25 
     | 
    
         
            -
                    false
         
     | 
| 
       26 
     | 
    
         
            -
                  else
         
     | 
| 
       27 
     | 
    
         
            -
                    true
         
     | 
| 
       28 
     | 
    
         
            -
                  end
         
     | 
| 
       29 
     | 
    
         
            -
                end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                # return result data or retrieves from result endpoint if nothing specified
         
     | 
| 
       32 
     | 
    
         
            -
                # retries result information of process with given id
         
     | 
| 
       33 
     | 
    
         
            -
                def get_results
         
     | 
| 
       34 
     | 
    
         
            -
                  response = @api.get(@cloud.url(:result, @process_id), no_callbacks: true, token: @cloud.access_token.token)
         
     | 
| 
       35 
     | 
    
         
            -
                  @results = []
         
     | 
| 
       36 
     | 
    
         
            -
                  response.each do |res|
         
     | 
| 
       37 
     | 
    
         
            -
                    @results.push(CopyleaksApi::ResultRecord.new(res))
         
     | 
| 
       38 
     | 
    
         
            -
                  end
         
     | 
| 
       39 
     | 
    
         
            -
                  @results
         
     | 
| 
       40 
     | 
    
         
            -
                end
         
     | 
| 
       41 
     | 
    
         
            -
                
         
     | 
| 
       42 
     | 
    
         
            -
                # retries status information of process with given id
         
     | 
| 
       43 
     | 
    
         
            -
                def update_status
         
     | 
| 
       44 
     | 
    
         
            -
                  response = @api.get(@cloud.url(:status, @process_id), no_callbacks: true, token: @cloud.access_token.token)
         
     | 
| 
       45 
     | 
    
         
            -
                  @progress = response['ProgressPercents'].to_i
         
     | 
| 
       46 
     | 
    
         
            -
                  @progress
         
     | 
| 
       47 
     | 
    
         
            -
                end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                # Returns the source text of this process
         
     | 
| 
       50 
     | 
    
         
            -
                def get_source_text
         
     | 
| 
       51 
     | 
    
         
            -
                  response = @api.get(@cloud.url_downloads("source-text?pid=#{@process_id}"), parse_json: false, no_callbacks: true, token: @cloud.access_token.token)
         
     | 
| 
       52 
     | 
    
         
            -
                  response
         
     | 
| 
       53 
     | 
    
         
            -
                end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                # deletes process from API
         
     | 
| 
       56 
     | 
    
         
            -
                def delete
         
     | 
| 
       57 
     | 
    
         
            -
                  response = @api.delete(@cloud.url(:delete, @process_id), token: @cloud.access_token.token)
         
     | 
| 
       58 
     | 
    
         
            -
                  if response['StatusCode'] == 200
         
     | 
| 
       59 
     | 
    
         
            -
                    true
         
     | 
| 
       60 
     | 
    
         
            -
                  else
         
     | 
| 
       61 
     | 
    
         
            -
                    false
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                class << self
         
     | 
| 
       66 
     | 
    
         
            -
                  # create CopyleaksProcess based on data got from any create endpoint
         
     | 
| 
       67 
     | 
    
         
            -
                  def create(cloud, api, hash)
         
     | 
| 
       68 
     | 
    
         
            -
                    new(cloud: cloud, api: api, process_id: hash['ProcessId'], created_at: hash['CreationTimeUTC'])
         
     | 
| 
       69 
     | 
    
         
            -
                  end
         
     | 
| 
       70 
     | 
    
         
            -
                
         
     | 
| 
       71 
     | 
    
         
            -
                  # creates CopyleaksProcess based on data got from list endpoint
         
     | 
| 
       72 
     | 
    
         
            -
                  def create_from_list(cloud, api, hash)
         
     | 
| 
       73 
     | 
    
         
            -
                    new(cloud: cloud, api: api, process_id: hash['ProcessId'], created_at: hash['CreationTimeUTC'],
         
     | 
| 
       74 
     | 
    
         
            -
                        status_code: hash['Status'].downcase, custom_fields: hash['CustomFields'])
         
     | 
| 
       75 
     | 
    
         
            -
                  end
         
     | 
| 
       76 
     | 
    
         
            -
                end
         
     | 
| 
       77 
     | 
    
         
            -
              end
         
     | 
| 
       78 
     | 
    
         
            -
            end
         
     |