Class: Plagscan::Documents

Inherits:
Object
  • Object
show all
Defined in:
lib/plagscan/documents.rb

Overview

PlagScan documents API

Class Method Summary collapse

Class Method Details

.check(access_token:, document_id:) ⇒ Null

Document create REST API For more details, see api.plagscan.com/v3docs/#api-Document-CheckDocument

Parameters:

  • access_token (String)

    Access token from Token.fetch

  • document_id (Integer)

    Document ID as returned from create action

Returns:

  • (Null)

Raises:

  • (DocumentError)

    Various reasons generally based around invalid document state.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/plagscan/documents.rb', line 43

def self.check(access_token:, document_id:)
  response =
    Plagscan::Request.request(
      "documents/#{document_id}/check",
      method: :put, access_token: access_token
    )

  return if response.is_a? Net::HTTPNoContent

  error_message =
    begin
      JSON.parse(response.body)&.dig('error', 'message')
    rescue JSON::ParserError
      nil
    end
  raise DocumentError, error_message || response.body
end

.create(access_token:, file: nil, text: nil, **options) ⇒ Hash

Document create REST API Note. you should provide fileUpload OR textdata For more details, see api.plagscan.com/v3docs/#api-Document-SubmitDocument

Parameters:

  • access_token (String)

    Access token from Token.fetch

  • file (File) (defaults to: nil)

    Document file

  • text (String) (defaults to: nil)

    Text from a document in plain text

  • userID, (named options)

    textname, toRepository, saveOrig

Returns:

  • (Hash)

    containing document ID and URI location for created resource



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/plagscan/documents.rb', line 19

def self.create(access_token:, file: nil, text: nil, **options)
  raise 'must specify file or text' if file.nil? && text.nil?

  create_props = options.delete_if do |k, _|
    !%i[userID textname toRepository saveOrig].include? k
  end

  Plagscan::Request.json_request(
    'documents',
    method: :post, access_token: access_token, expected_result: Net::HTTPCreated,
    body: create_props.merge(file ? { fileUpload: file } : { textdata: text }),
    read_timeout: 120
  )
end

.retrieve(access_token:, document_id:, mode:, user_id: nil) ⇒ Hash

Document retrieve REST API For more details, see api.plagscan.com/v3docs/#api-Document-RetrieveDocumentReport

Parameters:

  • access_token (String)

    Access token from Token.fetch

  • document_id (Integer)

    Document ID as returned from create action

  • mode (Integer)

    The retrieve mode of the report

  • user_id (Integer) (defaults to: nil)

    Identify the user who is accessing to the report (Only mandatory for mode 10). If not set it will get the user ID associated with the access token or the organization admin ID.

Returns:

  • (Hash)

    Various different values depending on the mode specified



73
74
75
76
77
78
79
80
81
# File 'lib/plagscan/documents.rb', line 73

def self.retrieve(access_token:, document_id:, mode:, user_id: nil)
  params = { mode: mode }
  params[:userID] = user_id if user_id

  Plagscan::Request.json_request(
    "documents/#{document_id}/retrieve",
    access_token: access_token, body: params
  )
end