Class: Ccs::Downloader

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

Overview

Downloads and decrypts the document at given URI with given access token. Decryption occurs using given passphrase.

Instance Method Summary collapse

Constructor Details

#initialize(uri, access_token, passphrase) ⇒ Downloader

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

Examples:

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

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

Parameters:

  • uri (String)

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

  • access_token (String)

    Occson access token.

  • passphrase (String)

    Document passphrase, used in encryption and decryption.



19
20
21
22
23
# File 'lib/ccs/downloader.rb', line 19

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

Instance Method Details

#callString|nil

Performs the download and decryption of document.

Returns:

  • (String|nil)

    Decrypted body of the document or ‘nil` in case the server did not respond with a `200` HTTP code.



29
30
31
32
33
34
35
36
# File 'lib/ccs/downloader.rb', line 29

def call
  response = http.request(request)
  body = response.body
  return unless response.code.eql? '200'
  json = JSON.parse body

  Decrypter.new(@passphrase, json['encrypted_content']).call
end