Class: Aws::S3Generator::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/s3/right_s3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, name, meta_headers = {}) ⇒ Key

Returns a new instance of Key.



1056
1057
1058
1059
1060
1061
# File 'lib/s3/right_s3.rb', line 1056

def initialize(bucket, name, meta_headers={})
  @bucket       = bucket
  @name         = name.to_s
  @meta_headers = meta_headers
  raise 'Key name can not be empty.' if @name.blank?
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



1033
1034
1035
# File 'lib/s3/right_s3.rb', line 1033

def bucket
  @bucket
end

#nameObject (readonly)

Returns the value of attribute name.



1033
1034
1035
# File 'lib/s3/right_s3.rb', line 1033

def name
  @name
end

Instance Method Details

#delete(expires = nil, headers = {}) ⇒ Object

Generate link to delete key.

bucket.delete(2.hour) #=> https://s3.amazonaws.com:443/my_awesome_bucket/logs%2Ftoday%2F1.log?Signature=4...D&Expires=1180820032&AWSAccessKeyId=1...2


1083
1084
1085
# File 'lib/s3/right_s3.rb', line 1083

def delete(expires=nil,  headers={})
  @bucket.s3.interface.delete_link(@bucket.to_s, @name, expires,  headers)
end

#full_name(separator = '/') ⇒ Object

Return a full S# name (bucket/key).

key.full_name #=> 'my_awesome_bucket/cool_key'


1043
1044
1045
# File 'lib/s3/right_s3.rb', line 1043

def full_name(separator='/')
  "#{@bucket.to_s}#{separator}#{@name}"
end

#get(expires = nil, headers = {}) ⇒ Object

Generate link to GET key data.

bucket.get('logs/today/1.log', 1.hour) #=> https://s3.amazonaws.com:443/my_awesome_bucket/logs%2Ftoday%2F1.log?Signature=h...M%3D&Expires=1180820032&AWSAccessKeyId=1...2


1075
1076
1077
# File 'lib/s3/right_s3.rb', line 1075

def get(expires=nil, headers={})
  @bucket.s3.interface.get_link(@bucket.to_s, @name, expires, headers)
end

#head(expires = nil, headers = {}) ⇒ Object

Generate link to head key.

bucket.head(2.hour) #=> https://s3.amazonaws.com:443/my_awesome_bucket/logs%2Ftoday%2F1.log?Signature=4...D&Expires=1180820032&AWSAccessKeyId=1...2


1091
1092
1093
# File 'lib/s3/right_s3.rb', line 1091

def head(expires=nil,  headers={})
  @bucket.s3.interface.head_link(@bucket.to_s, @name, expires,  headers)
end

Return a public link to key.

key.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket/cool_key'


1051
1052
1053
1054
# File 'lib/s3/right_s3.rb', line 1051

def public_link
  params = @bucket.s3.interface.params
  "#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name('/')}"
end

#put(expires = nil, headers = {}) ⇒ Object

Generate link to PUT key data.

puts bucket.put('logs/today/1.log', '123', 2.hour) #=> https://s3.amazonaws.com:443/my_awesome_bucket/logs%2Ftoday%2F1.log?Signature=B...D&Expires=1180820032&AWSAccessKeyId=1...2


1067
1068
1069
# File 'lib/s3/right_s3.rb', line 1067

def put(expires=nil, headers={})
  @bucket.put(@name.to_s, @meta_headers, expires, headers)
end

#to_sObject



1035
1036
1037
# File 'lib/s3/right_s3.rb', line 1035

def to_s
  @name
end