class Occson::Document

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.

Public Class Methods

new(uri, access_token, passphrase) click to toggle source

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

@example

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

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

@param uri [String] Document URI. Accepts ‘occson://` as shorthand for Occson location. @param access_token [String] Occson access token. @param passphrase [String] Document passphrase, used in encryption and decryption.

# File lib/occson/document.rb, line 20
def initialize(uri, access_token, passphrase)
  @uri = build_uri(uri)
  @access_token = access_token
  @passphrase = passphrase
end

Public Instance Methods

download() click to toggle source

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

@example

plaintext = document.download

@return [String] Decrypted document contents

# File lib/occson/document.rb, line 44
def download
  Downloader.new(@uri, @access_token, @passphrase).call
end
upload(content, force: false) click to toggle source

Uploads the given plaintext ‘content` to target URI.

@example

document.upload('My example plaintext.')

@param content [String] Plaintext to be encrypted and uploaded. @param force [Boolean] Whether to overwrite target document in Occson, if any. Default ‘false`.

# File lib/occson/document.rb, line 33
def upload(content, force: false)
  Uploader.new(@uri, content, @access_token, @passphrase, force: force).call
end

Private Instance Methods

build_uri(uri) click to toggle source
# File lib/occson/document.rb, line 50
def build_uri(uri)
  URI uri.sub('occson://', 'https://api.occson.com/')
end