Class: Ognivo::S3Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ognivo/s3client.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key, bucket) ⇒ S3Client

Returns a new instance of S3Client.



5
6
7
8
9
10
11
12
# File 'lib/ognivo/s3client.rb', line 5

def initialize(access_key_id, secret_access_key, bucket)
  @s3 = AWS::S3.new(
    access_key_id: access_key_id,
    secret_access_key: secret_access_key
  )

  @bucket = @s3.buckets[bucket]
end

Instance Method Details

#bucket_exists?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ognivo/s3client.rb', line 36

def bucket_exists?
  @bucket.exists?
end

#key_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ognivo/s3client.rb', line 28

def key_exists?(name)
  @bucket.objects[name].exists?
end

#public_url(name) ⇒ Object



24
25
26
# File 'lib/ognivo/s3client.rb', line 24

def public_url(name)
  @bucket.objects[name].public_url
end

#read(name) ⇒ Object



32
33
34
# File 'lib/ognivo/s3client.rb', line 32

def read(name)
  @bucket.objects[name].read
end

#upload(io, key) ⇒ Object



20
21
22
# File 'lib/ognivo/s3client.rb', line 20

def upload(io, key)
  @bucket.objects[key].write(io, acl: 'public_read')
end

#upload_file(file_path, key) ⇒ Object



14
15
16
17
18
# File 'lib/ognivo/s3client.rb', line 14

def upload_file(file_path, key)
  File.open(file_path) do |file|
    upload(file, key)
  end
end