Class: URI::S3
- Inherits:
-
Generic
- Object
- Generic
- URI::S3
- Defined in:
- lib/open-uri-s3.rb
Instance Method Summary collapse
-
#open(*args) ⇒ AWS::S3::S3Object
S3 object (quacks like IO).
- #read ⇒ Object
Instance Method Details
#open(*args) ⇒ AWS::S3::S3Object
Returns S3 object (quacks like IO).
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/open-uri-s3.rb', line 9 def open(*args) = {} [:use_ssl] = false if ENV['AWS_USE_SSL'] == 'false' if ENV["AWS_S3_ENDPOINT"] s3_endpoint_uri = URI(ENV['AWS_S3_ENDPOINT']) AWS.config(s3_endpoint: s3_endpoint_uri.host, s3_port: s3_endpoint_uri.port) end s3 = ::AWS::S3.new() bucket = s3.buckets[self.hostname] if !ENV['AWS_S3_ENDPOINT'] && bucket.location_constraint s3_endpoint = "s3-#{bucket.location_constraint}.amazonaws.com" s3 = ::AWS::S3.new(.update(s3_endpoint: s3_endpoint)) bucket = s3.buckets[self.hostname] end path = self.path[1..-1] object = bucket.objects[path] if block_given? yield object else object end end |
#read ⇒ Object
35 36 37 |
# File 'lib/open-uri-s3.rb', line 35 def read open(to_s).read end |