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(options = {}) ⇒ FileUpload

Returns a new instance of FileUpload.



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

def initialize(options = {})
  self.bucket_url = options[:bucket_url]
  self.key = options[:key]

  if options[:policy]
    self.policy = options[:policy]
  end
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

Class Method Details

.enqueue(job_description) ⇒ Object



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

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

.queueObject



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

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

Instance Method Details

#aclObject



32
33
34
# File 'lib/ungulate/file_upload.rb', line 32

def acl
  condition 'acl'
end

#condition(key) ⇒ Object



36
37
38
39
# File 'lib/ungulate/file_upload.rb', line 36

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

#conditionsObject



41
42
43
44
# File 'lib/ungulate/file_upload.rb', line 41

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

#policyObject



46
47
48
49
50
# File 'lib/ungulate/file_upload.rb', line 46

def policy
  Base64.encode64(
    ActiveSupport::JSON.encode(@policy_ruby)
  ).gsub("\n", '')
end

#policy=(new_policy) ⇒ Object



52
53
54
55
56
# File 'lib/ungulate/file_upload.rb', line 52

def policy=(new_policy)
  new_policy['expiration'] = new_policy['expiration'].utc
  @policy_ruby = new_policy
  policy
end

#signatureObject



62
63
64
65
66
67
68
# File 'lib/ungulate/file_upload.rb', line 62

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

#success_action_redirectObject



58
59
60
# File 'lib/ungulate/file_upload.rb', line 58

def success_action_redirect
  condition 'success_action_redirect'
end