Class: Opener::Daemons::Uploader

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

Overview

Class for uploading KAF documents to Amazon S3.

Instance Method Summary collapse

Instance Method Details

#bucketAws::S3::Bucket

Returns:

  • (Aws::S3::Bucket)


44
45
46
# File 'lib/opener/daemons/uploader.rb', line 44

def bucket
  @bucket ||= s3.bucket(Daemons.output_bucket)
end

#create(key, body, options = {}) ⇒ Aws::S3::Object

Parameters:

  • key (String)
  • body (String)
  • options (Hash) (defaults to: {})

Returns:

  • (Aws::S3::Object)


34
35
36
# File 'lib/opener/daemons/uploader.rb', line 34

def create(key, body, options = {})
  bucket.put_object(options.merge(:key  => key, :body => body))
end

#s3Aws::S3::Resource

Returns:

  • (Aws::S3::Resource)


39
40
41
# File 'lib/opener/daemons/uploader.rb', line 39

def s3
  @s3 ||= Aws::S3::Resource.new
end

#upload(identifier, document, metadata = {}) ⇒ Aws::S3::Object

Uploads the given KAF document.

Parameters:

  • identifier (String)
  • document (String)
  • metadata (Hash) (defaults to: {})

    description

Returns:

  • (Aws::S3::Object)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/opener/daemons/uploader.rb', line 12

def upload(identifier, document,  = {})
   = {}

  .each do |key, value|
    [key.to_s] = value.to_s
  end

  object = create(
    "#{SecureRandom.hex}/#{identifier}.xml",
    document,
    :metadata     => ,
    :content_type => 'application/xml',
    :acl          => 'public-read'
  )

  return object
end