Class: Ungulate::FileUpload

Inherits:
Object
  • Object
show all
Defined in:
lib/ungulate/file_upload.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ FileUpload

Returns a new instance of FileUpload.



24
25
26
27
28
# File 'lib/ungulate/file_upload.rb', line 24

def initialize(params)
  self.bucket_url = params[:bucket_url]
  self.key = params[:key]
  self.policy = params[:policy]
end

Instance Attribute Details

#bucket_urlObject

Returns the value of attribute bucket_url.



3
4
5
# File 'lib/ungulate/file_upload.rb', line 3

def bucket_url
  @bucket_url
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/ungulate/file_upload.rb', line 3

def key
  @key
end

#policyObject

Returns the value of attribute policy.



3
4
5
# File 'lib/ungulate/file_upload.rb', line 3

def policy
  @policy
end

Class Method Details

.enqueue(job_description) ⇒ Object



15
16
17
# File 'lib/ungulate/file_upload.rb', line 15

def self.enqueue(job_description)
  queue.send_message(job_description.to_yaml)
end

.queueObject



19
20
21
22
# File 'lib/ungulate/file_upload.rb', line 19

def self.queue
  sqs = RightAws::SqsGen2.new(access_key_id, secret_access_key)
  sqs.queue(queue_name)
end

Instance Method Details

#aclObject



30
31
32
# File 'lib/ungulate/file_upload.rb', line 30

def acl
  condition 'acl'
end

#condition(key) ⇒ Object



34
35
36
37
# File 'lib/ungulate/file_upload.rb', line 34

def condition(key)
  found_key, found_value = conditions.find {|condition| condition.first == key}
  found_value if found_value
end

#conditionsObject



39
40
41
42
# File 'lib/ungulate/file_upload.rb', line 39

def conditions
  @conditions ||=
    @policy_ruby['conditions'].map {|condition| condition.to_a.flatten}
end

#signatureObject



55
56
57
58
59
60
61
# File 'lib/ungulate/file_upload.rb', line 55

def signature
  Base64.encode64(
    OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'),
                         secret_access_key, 
                         policy)
  ).gsub("\n", '')
end

#success_action_redirectObject



51
52
53
# File 'lib/ungulate/file_upload.rb', line 51

def success_action_redirect
  condition 'success_action_redirect'
end