Class: Occson::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/occson/document.rb

Overview

An abstraction for the Document concept. Simplifies building URLs, uploading and downloading contents. Abstracts away workspaces due to the use of access tokens in constructions.

Instance Method Summary collapse

Constructor Details

#initialize(uri, access_token, passphrase) ⇒ Document

Constructs a Document instance from a given URI, access token and passphrase.

Examples:

uri = 'occson://path/to/file.yml'
access_token = 'f30b5450421362c9ca0b'
passphrase = 'my document passphrase'

Occson::Document.new(uri, access_token, passphrase)

Parameters:

  • uri (String)

    Document URI. Accepts ‘occson://` as shorthand for Occson location.

  • access_token (String)

    Occson access token.

  • passphrase (String)

    Document passphrase, used in encryption and decryption.



20
21
22
23
24
# File 'lib/occson/document.rb', line 20

def initialize(uri, access_token, passphrase)
  @uri = build_uri(uri)
  @access_token = access_token
  @passphrase = passphrase
end

Instance Method Details

#downloadString

Downloads the encrypted document at ‘@uri` and returns the plaintext contents (given that `@passphrase` matches).

Examples:

plaintext = document.download

Returns:

  • (String)

    Decrypted document contents



44
45
46
# File 'lib/occson/document.rb', line 44

def download
  Downloader.new(@uri, @access_token, @passphrase).call
end

#upload(content, force: false) ⇒ Object

Uploads the given plaintext ‘content` to target URI.

Examples:

document.upload('My example plaintext.')

Parameters:

  • content (String)

    Plaintext to be encrypted and uploaded.

  • force (Boolean) (defaults to: false)

    Whether to overwrite target document in Occson, if any. Default ‘false`.



33
34
35
# File 'lib/occson/document.rb', line 33

def upload(content, force: false)
  Uploader.new(@uri, content, @access_token, @passphrase, force: force).call
end