Class: Ccs::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/ccs/uploader.rb

Overview

Encrypts and uploads the document to Occson.

Instance Method Summary collapse

Constructor Details

#initialize(uri, content, access_token, passphrase, force: false) ⇒ Uploader

Constructs an Uploader instance from a given URI, content, access token and passphrase.

Examples:

uri = 'ccs://path/to/file.yml'
content = 'my very secret message'
access_token = 'f30b5450421362c9ca0b'
passphrase = 'my document passphrase'

Ccs::Uploader.new(uri, access_token, passphrase)

Parameters:

  • uri (String)

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

  • content (String)

    Plaintext for encryption and upload.

  • access_token (String)

    Occson access token.

  • passphrase (String)

    Document passphrase, used in encryption and decryption.

  • force (Boolean) (defaults to: false)

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



21
22
23
24
25
26
27
# File 'lib/ccs/uploader.rb', line 21

def initialize(uri, content, access_token, passphrase, force: false)
  @uri = uri
  @content = content
  @access_token = access_token
  @passphrase = passphrase
  @force = force.to_s
end

Instance Method Details

#callBoolean

Performs the actual upload to server.

Returns:

  • (Boolean)

    ‘true` for a successful upload, `false` otherwise



32
33
34
35
# File 'lib/ccs/uploader.rb', line 32

def call
  request.body = { encrypted_content: encrypted_content, force: @force }.to_json
  %w[200 201].include?(http.request(request).code)
end