Skip to content
Official SDKs

Ruby Quickstart Guide

This guide will walk you through installing the official Ruby SDK and running your first scan. In just a few minutes, you’ll be able to check content for plagiarism, AI-generated text, and more directly from your Ruby application.

🔑 Before you begin

In order to start integrating Copyleaks API, you'll need an account and an API key:

  1. Installation

    First, install the official plagiarism-checker gem from RubyGems into your project.

    Terminal window
    gem install plagiarism-checker
  2. Quick Example: Scan Text

    scan.rb
    require 'copyleaks'
    require 'base64'
    # --- Your Credentials ---
    USER_EMAIL = 'YOUR_EMAIL_ADDRESS'
    USER_API_KEY = 'YOUR_API_KEY'
    WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}'
    # --------------------
    begin
    # Log in to the Copyleaks API
    puts "Authenticating..."
    copyleaks = Copyleaks::API.new
    auth_token = copyleaks.login(USER_EMAIL, USER_API_KEY)
    puts "✅ Logged in successfully!"
    # Prepare your content for scanning
    puts "Submitting text for scanning..."
    scan_id = Time.now.to_i.to_s
    text_to_scan = 'Hello world, this is a test.'
    base64_content = Base64.strict_encode64(text_to_scan)
    # Configure the scan
    webhooks = Copyleaks::SubmissionWebhooks.new(WEBHOOK_URL)
    properties = Copyleaks::SubmissionProperties.new(webhooks)
    properties.sandbox = true # Turn on sandbox mode for testing
    submission = Copyleaks::CopyleaksFileSubmissionModel.new(
    base64_content,
    'test.txt',
    properties
    )
    # Submit the scan to Copyleaks
    copyleaks.submit_file(auth_token, scan_id, submission)
    puts "🚀 Scan submitted successfully! Scan ID: #{scan_id}"
    puts "You will be notified via your webhook when the scan is complete."
    rescue StandardError => e
    puts "🛑 An error occurred: #{e.message}"
    end
  3. Understanding the Code

    The example code performs four main actions to submit a scan:

    1. Login: It authenticates with your email and API key to get a secure login token, which is required for all subsequent requests.
    2. Prepare Content: It takes a simple string of text and encodes it into Base64 format.
    3. Configure Scan: It creates a SubmissionProperties object containing SubmissionWebhooks to define the scan’s behavior. We enable sandbox mode for safe testing and provide the webhook URL.
    4. Submit for Scanning: It creates a CopyleaksFileSubmissionModel with the content and properties, then sends it to the Copyleaks API. The process is asynchronous; Copyleaks will notify your webhook URL once the scan is complete.

Now that you’ve submitted your first scan, here are some recommended steps: