Module: Easys3
- Defined in:
- lib/easys3.rb,
lib/easys3/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"1.0.1"
Class Method Summary collapse
- .get(bucket_name, file_name) ⇒ Object
- .get_without_rescue(bucket_name, file_name, ignore_keys = false) ⇒ Object
- .put(bucket_name, file_name, file, acl = nil) ⇒ Object
- .put_without_rescue(bucket_name, file_name, file, acl = nil, ignore_keys = false) ⇒ Object
Class Method Details
.get(bucket_name, file_name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/easys3.rb', line 10 def self.get(bucket_name, file_name) begin Easys3.get_without_rescue(bucket_name, file_name, ignore_keys=true) rescue begin Easys3.get_without_rescue(bucket_name, file_name, ignore_keys=false) rescue Exception => e return Response.error(e) end end end |
.get_without_rescue(bucket_name, file_name, ignore_keys = false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/easys3.rb', line 23 def self.get_without_rescue(bucket_name, file_name, ignore_keys=false) bucket = S3Handler.get_bucket(bucket_name, ignore_keys=ignore_keys) if !S3Handler.file_exists?(bucket, file_name) return Response.missing("Could not find file: " + file_name + " in the bucket: " + bucket.name) end data = bucket.object(file_name).get.body.read() return Response.success(data) end |
.put(bucket_name, file_name, file, acl = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/easys3.rb', line 35 def self.put(bucket_name, file_name, file, acl=nil) # bucket.object(file_name).put(body: file, acl: 'public-read') begin return Easys3.put_without_rescue(bucket_name, file_name, file, ignore_keys=true) rescue begin return Easys3.put_without_rescue(bucket_name, file_name, file, ignore_keys=false) rescue Exception => e return Response.error(e) end end end |
.put_without_rescue(bucket_name, file_name, file, acl = nil, ignore_keys = false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/easys3.rb', line 51 def self.put_without_rescue(bucket_name, file_name, file, acl=nil, ignore_keys=false) bucket = S3Handler.get_bucket(bucket_name, ignore_keys=ignore_keys) if acl response = bucket.object(file_name).put(body: file, acl: acl) else response = bucket.object(file_name).put(body: file) end return Response.success(response, status=201) end |