filestorage 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d3a09a44d0a6e015dac0c4dd96874752c8fd779
4
- data.tar.gz: 2efd36ab2311060c54a7b26b498329252fb3b9ed
3
+ metadata.gz: 127bdfaa77c8a4487a8d59390e2fefe8896cb929
4
+ data.tar.gz: 2baf8f28f227a1534575d128f89fc72fbdfe8cfa
5
5
  SHA512:
6
- metadata.gz: 05df021049c6e585177447924c3167b28882d68ea779a009e98069bac70dee0f4cc2924a850bf202b5b7c5e8833c56ad1154a5ab599954bf4e53f3536cf004d7
7
- data.tar.gz: 465e41208e173177bdd3dc29ed7dfdf37d8751b6b091b473f9d7e4d88aae906e5e704c722201f174adc40ebc41c814dff2a38e67d1956acc800a7fad49f8af8a
6
+ metadata.gz: 6aed5c1d8f6ce34ae7effffa94cc810b46307119b196652be53d6f7f510372a07ff89e1a14ae7e909b15b7877730b596046c542f9dd938f753c201eea4e835e3
7
+ data.tar.gz: 73573b098183f4a74f1fdf9dff3c18abe7e883d759d7d44e5e242e40279a7243afb9d4ae8f26d867f0b40b05c46e757cf5930b2e5d9450e9f88277e431517eed
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in filestorage.gemspec
4
4
  gemspec
5
+
6
+ gem 'aws-sdk'
@@ -1,5 +1,6 @@
1
1
  require "filestorage/version"
2
2
  require "filestorage/local_filestorage"
3
+ require "filestorage/s3_filestorage"
3
4
 
4
5
  module Filestorage
5
6
  class NotExist < StandardError; end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'aws'
4
+
5
+
6
+ module Filestorage
7
+
8
+ class S3Filestorage
9
+
10
+ def initialize(bucket, access_key_id, secret_access_key)
11
+ @s3 = AWS::S3.new(:access_key_id => access_key_id,
12
+ :secret_access_key => secret_access_key)
13
+ @bucket = @s3.buckets[bucket]
14
+ end
15
+
16
+ def store(path, file)
17
+ obj = @bucket.objects[path]
18
+ raise AlreadyExist.new("Already exist #{path}") if obj.exists?
19
+ content = if file.instance_of?(Pathname)
20
+ File.open(file, "rb"){|f| f.read}
21
+ elsif file.instance_of?(File)
22
+ file.read
23
+ else
24
+ file
25
+ end
26
+ obj.write(content, :acl => :public_read)
27
+ path
28
+ end
29
+
30
+ def get(path)
31
+ obj = @bucket.objects[path]
32
+ raise NotExist.new("Not exist #{path}") unless obj.exists?
33
+ obj
34
+ end
35
+
36
+ def delete(path)
37
+ obj = @bucket.objects[path]
38
+ raise NotExist.new("Not exist #{path}") unless obj.exists?
39
+ obj.delete
40
+ path
41
+ end
42
+
43
+ def exist?(path)
44
+ obj = @bucket.objects[path]
45
+ obj.exists?
46
+ end
47
+
48
+ end # of class S3Filestorage
49
+
50
+ end # of module Filestorag
@@ -1,3 +1,3 @@
1
1
  module Filestorage
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filestorage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - takatoh
@@ -53,6 +53,7 @@ files:
53
53
  - filestorage.gemspec
54
54
  - lib/filestorage.rb
55
55
  - lib/filestorage/local_filestorage.rb
56
+ - lib/filestorage/s3_filestorage.rb
56
57
  - lib/filestorage/version.rb
57
58
  homepage: ''
58
59
  licenses: