class Ccs::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
Constructs a Document
instance from a given URI, access token and passphrase.
@example
uri = 'ccs://path/to/file.yml' access_token = 'f30b5450421362c9ca0b' passphrase = 'my document passphrase' Ccs::Document.new(uri, access_token, passphrase)
@param uri [String] Document
URI. Accepts `ccs://` as shorthand for Occson location. @param access_token [String] Occson access token. @param passphrase [String] Document
passphrase, used in encryption and decryption.
# File lib/ccs/document.rb, line 20 def initialize(uri, access_token, passphrase) @uri = build_uri(uri) @access_token = access_token @passphrase = passphrase end
Public Instance Methods
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/ccs/document.rb, line 44 def download Downloader.new(@uri, @access_token, @passphrase).call end
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/ccs/document.rb, line 33 def upload(content, force: false) Uploader.new(@uri, content, @access_token, @passphrase, force: force).call end
Private Instance Methods
# File lib/ccs/document.rb, line 50 def build_uri(uri) URI uri.sub('ccs://', 'https://api.occson.com/') end