Class: DataDuck::S3Object
- Inherits:
-
Object
- Object
- DataDuck::S3Object
- Defined in:
- lib/dataduck/s3_object.rb
Class Method Summary collapse
Instance Method Summary collapse
- #full_path ⇒ Object
-
#initialize(path, contents, aws_key, aws_secret, bucket, region, options = {}) ⇒ S3Object
constructor
A new instance of S3Object.
- #s3_path ⇒ Object
- #upload! ⇒ Object
Constructor Details
#initialize(path, contents, aws_key, aws_secret, bucket, region, options = {}) ⇒ S3Object
Returns a new instance of S3Object.
5 6 7 8 9 10 11 12 13 |
# File 'lib/dataduck/s3_object.rb', line 5 def initialize(path, contents, aws_key, aws_secret, bucket, region, ={}) @path = path @contents = contents = @aws_key = aws_key @aws_secret = aws_secret @bucket = bucket @region = region end |
Class Method Details
.max_retries ⇒ Object
53 54 55 |
# File 'lib/dataduck/s3_object.rb', line 53 def self.max_retries 3 end |
.regions ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dataduck/s3_object.rb', line 57 def self.regions [ { name: 'US Standard - N. Virginia', region: 'us-east-1' }, { name: 'US West - N. California', region: 'us-west-1' }, { name: 'US West - Oregon', region: 'us-west-2' }, { name: 'EU - Ireland', region: 'eu-west-1' }, { name: 'EU - Frankfurt', region: 'eu-central-1' }, { name: 'Asia Pacific - Singapore', region: 'ap-southeast-1' }, { name: 'Asia Pacific - Sydney', region: 'ap-southeast-2' }, { name: 'Asia Pacific - Tokyo', region: 'ap-northeast-1' }, { name: 'South America - Sao Paulo', region: 'sa-east-1' }, ] end |
Instance Method Details
#full_path ⇒ Object
45 46 47 |
# File 'lib/dataduck/s3_object.rb', line 45 def full_path 'dataduck/' + @path end |
#s3_path ⇒ Object
49 50 51 |
# File 'lib/dataduck/s3_object.rb', line 49 def s3_path "s3://#{ @bucket }/#{ full_path }" end |
#upload! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dataduck/s3_object.rb', line 15 def upload! s3 = Aws::S3::Client.new( region: @region, access_key_id: @aws_key, secret_access_key: @aws_secret, ) attempts = 0 while attempts <= S3Object.max_retries attempts += 1 put_hash = .merge({ acl: 'private', bucket: @bucket, body: @contents, key: self.full_path, server_side_encryption: 'AES256', }) begin response = s3.put_object(put_hash) rescue Exception => e if attempts == S3Object.max_retries throw e end end end response end |