Class: Crocodoc::Download

Inherits:
Object
  • Object
show all
Defined in:
lib/crocodoc/download.rb

Overview

Provides access to the Crocodoc Download API. The Download API is used for downloading an original of a document, a PDF of a document, a thumbnail of a document, and text extracted from a document.

Constant Summary collapse

@@path =

The Download API path relative to the base API path

'/download/'

Class Method Summary collapse

Class Method Details

.document(uuid, is_pdf = false, is_annotated = false, filter = nil) ⇒ String

Download a document’s original file from Crocodoc. The file can optionally be downloaded as a PDF, as another filename, with annotations, and with filtered annotations.

Parameters:

  • uuid (String)

    The uuid of the file to download

  • is_pdf (Boolean) (defaults to: false)

    Should the file be downloaded as a PDF?

  • is_annotated (Boolean) (defaults to: false)

    Should the file be downloaded with annotations?

  • filter (String, Array<String>) (defaults to: nil)

    Which annotations should be included if any - this is usually a string, but could also be an array if it’s a comma-separated list of user IDs as the filter

Returns:

  • (String)

    The downloaded file contents as a string

Raises:

  • CrocodocError



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/crocodoc/download.rb', line 32

def self.document(uuid, is_pdf=false, is_annotated=false, filter=nil)
  get_params = {uuid: uuid}
  get_params['pdf'] = 'true' if is_pdf
  get_params['annotated'] = 'true' if is_annotated
  
  if filter
    filter = filter.join(',') if filter.is_a? Array
    get_params['filter'] = filter
  end
  
  Crocodoc._request(self.path, 'document', get_params, nil, false)
end

.pathObject

Get the path



15
16
17
# File 'lib/crocodoc/download.rb', line 15

def self.path
  @@path
end

.path=(path) ⇒ Object

Set the path



10
11
12
# File 'lib/crocodoc/download.rb', line 10

def self.path=(path)
  @@path = path
end

.text(uuid) ⇒ String

Download a document’s extracted text from Crocodoc.

Parameters:

  • uuid (String)

    The uuid of the file to extract text from

Returns:

  • (String)

    The file’s extracted text

Raises:

  • CrocodocError



51
52
53
54
# File 'lib/crocodoc/download.rb', line 51

def self.text(uuid)
  get_params = {uuid: uuid}
  Crocodoc._request(self.path, 'text', get_params, nil, false)
end

.thumbnail(uuid, width = nil, height = nil) ⇒ String

Download a document’s thumbnail from Crocodoc with an optional size.

Parameters:

  • uuid (String)

    The uuid of the file to download the thumbnail from

  • width (Integer) (defaults to: nil)

    The width you want the thumbnail to be

  • height (Integer) (defaults to: nil)

    The height you want the thumbnail to be

Returns:

  • (String)

    The downloaded thumbnail contents

Raises:

  • CrocodocError



64
65
66
67
68
69
70
71
72
# File 'lib/crocodoc/download.rb', line 64

def self.thumbnail(uuid, width=nil, height=nil)
  get_params = {uuid: uuid}

  if width != nil and height != nil
    get_params['size'] = String(width) + 'x' + String(height)
  end

  Crocodoc._request(self.path, 'thumbnail', get_params, nil, false)
end