Class: Crocodoc::Document
- Inherits:
-
Object
- Object
- Crocodoc::Document
- Defined in:
- lib/crocodoc/document.rb
Overview
Provides access to the Crocodoc Document API. The Document API is used for uploading, checking status, and deleting documents.
Constant Summary collapse
- @@path =
The Document API path relative to the base API path
'/document/'
Class Method Summary collapse
-
.delete(uuid) ⇒ Boolean
Delete a file on Crocodoc by UUID.
-
.path ⇒ Object
Get the path.
-
.path=(path) ⇒ Object
Set the path.
-
.status(uuids) ⇒ Array<Hash<String,>>, Hash<String,>
Check the status of a file on Crocodoc by UUID.
-
.upload(url_or_file) ⇒ String
The uuid of the newly-uploaded file.
Class Method Details
.delete(uuid) ⇒ Boolean
Delete a file on Crocodoc by UUID.
24 25 26 27 |
# File 'lib/crocodoc/document.rb', line 24 def self.delete(uuid) post_params = {uuid: uuid} Crocodoc._request(self.path, 'delete', nil, post_params) end |
.path ⇒ Object
Get the path
14 15 16 |
# File 'lib/crocodoc/document.rb', line 14 def self.path @@path end |
.path=(path) ⇒ Object
Set the path
9 10 11 |
# File 'lib/crocodoc/document.rb', line 9 def self.path=(path) @@path = path end |
.status(uuids) ⇒ Array<Hash<String,>>, Hash<String,>
Check the status of a file on Crocodoc by UUID. This method is polymorphic and can take an array of UUIDs and return an array of status hashes about those UUIDs, or can also take a one UUID string and return one status hash for that UUID.
41 42 43 44 45 46 47 |
# File 'lib/crocodoc/document.rb', line 41 def self.status(uuids) is_single_uuid = !(uuids.is_a? Array) uuids = [uuids] if is_single_uuid get_params = {uuids: uuids.join(',')} response = Crocodoc._request(self.path, 'status', get_params, nil) is_single_uuid ? response[0] : response end |
.upload(url_or_file) ⇒ String
Returns The uuid of the newly-uploaded file.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/crocodoc/document.rb', line 55 def self.upload(url_or_file) post_params = {} if url_or_file.is_a? String post_params['url'] = url_or_file elsif url_or_file.respond_to?(:read) && url_or_file.respond_to?(:path) post_params['file'] = url_or_file else return Crocodoc::_error('invalid_url_or_file_param', self.name, __method__, nil) end response = Crocodoc::_request(self.path, 'upload', nil, post_params) unless response.has_key? 'uuid' return Crocodoc::_error('missing_uuid', self.name, __method__, response) end response['uuid'] end |