refile-s3 0.1.0 → 0.2.0

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: 99dbc8a79977f2f3ab2ec3d0baf5559378621850
4
- data.tar.gz: 04db099371048f327bc1bb44c23339a44ecc8bee
3
+ metadata.gz: 822143e5d96eb9f5fc74a4dae07315653638ca6e
4
+ data.tar.gz: 9553b9b162b1f2e84a344d04bd410e8630d069db
5
5
  SHA512:
6
- metadata.gz: 104de7b88e8b1a79f628154452ad25ca4668a6e92090376b7f4a8dde10cf24b6fe9bd64831b2955b34d6a428386618e4b9debbc41c874bc24546727a797a1740
7
- data.tar.gz: 0dece4b7f10e3d501e70bd18e45285514bbacc5b9966b0db06d8c90a8038d791882ad1deabc89c7fc76cd99abe2f48fc3fd573048d858f8c36e592eb8fd24524
6
+ metadata.gz: a70d66594a6ef78755df7b919b4c9dd79a74ae5e708dabf7d4a11b1a464b4881332addd9a6f3cda3463f88937b0ca67ca7bff7d1a5b8647f90d1f2f785031ccd
7
+ data.tar.gz: f30b55c40c6d95dc2b09da73bb091617f3d1bb142bebbd8b9fddbc900668c792cf3a57dd8bd4c7227504de9631e395de429036f77e8009364c88ff76d427cfb5
@@ -4,12 +4,21 @@ require "refile"
4
4
  require "refile/s3/version"
5
5
 
6
6
  module Refile
7
+
8
+ # @api private
9
+ class S3BackendError < StandardError; end
10
+
11
+ # @api private
12
+ class S3CredentialsError < S3BackendError
13
+ def message
14
+ "Credentials not found"
15
+ end
16
+ end
17
+
7
18
  # A refile backend which stores files in Amazon S3
8
19
  #
9
20
  # @example
10
21
  # backend = Refile::Backend::S3.new(
11
- # access_key_id: "xyz",
12
- # secret_access_key: "abcd1234",
13
22
  # region: "sa-east-1",
14
23
  # bucket: "my-bucket",
15
24
  # prefix: "files"
@@ -21,10 +30,8 @@ module Refile
21
30
 
22
31
  attr_reader :access_key_id, :max_size
23
32
 
24
- # Sets up an S3 backend with the given credentials.
33
+ # Sets up an S3 backend
25
34
  #
26
- # @param [String] access_key_id
27
- # @param [String] secret_access_key
28
35
  # @param [String] region The AWS region to connect to
29
36
  # @param [String] bucket The name of the bucket where files will be stored
30
37
  # @param [String] prefix A prefix to add to all files. Prefixes on S3 are kind of like folders.
@@ -33,11 +40,12 @@ module Refile
33
40
  # @param [Hash] s3_options Additional options to initialize S3 with
34
41
  # @see http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Core/Configuration.html
35
42
  # @see http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3.html
36
- def initialize(access_key_id:, secret_access_key:, region:, bucket:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, **s3_options)
37
- @access_key_id = access_key_id
38
- @secret_access_key = secret_access_key
39
- @s3_options = { access_key_id: access_key_id, secret_access_key: secret_access_key, region: region }.merge s3_options
43
+ def initialize(region:, bucket:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, **s3_options)
44
+ @s3_options = { region: region }.merge s3_options
40
45
  @s3 = Aws::S3::Resource.new @s3_options
46
+ credentials = @s3.client.config.credentials
47
+ raise S3CredentialsError unless credentials
48
+ @access_key_id = credentials.access_key_id
41
49
  @bucket_name = bucket
42
50
  @bucket = @s3.bucket @bucket_name
43
51
  @hasher = hasher
@@ -67,7 +75,7 @@ module Refile
67
75
  # if a file with the given id does not exist in this backend. Use
68
76
  # {FileSystem#exists?} to check if the file actually exists.
69
77
  #
70
- # @param [Sring] id The id of the file
78
+ # @param [String] id The id of the file
71
79
  # @return [Refile::File] The retrieved file
72
80
  verify_id def get(id)
73
81
  Refile::File.new(self, id)
@@ -75,7 +83,7 @@ module Refile
75
83
 
76
84
  # Delete a file from this backend
77
85
  #
78
- # @param [Sring] id The id of the file
86
+ # @param [String] id The id of the file
79
87
  # @return [void]
80
88
  verify_id def delete(id)
81
89
  object(id).delete
@@ -84,7 +92,7 @@ module Refile
84
92
  # Return an IO object for the uploaded file which can be used to read its
85
93
  # content.
86
94
  #
87
- # @param [Sring] id The id of the file
95
+ # @param [String] id The id of the file
88
96
  # @return [IO] An IO object containing the file contents
89
97
  verify_id def open(id)
90
98
  Kernel.open(object(id).presigned_url(:get))
@@ -102,7 +110,7 @@ module Refile
102
110
 
103
111
  # Return the size in bytes of the uploaded file.
104
112
  #
105
- # @param [Sring] id The id of the file
113
+ # @param [String] id The id of the file
106
114
  # @return [Integer] The file's size
107
115
  verify_id def size(id)
108
116
  object(id).get.content_length
@@ -112,7 +120,7 @@ module Refile
112
120
 
113
121
  # Return whether the file with the given id exists in this backend.
114
122
  #
115
- # @param [Sring] id The id of the file
123
+ # @param [String] id The id of the file
116
124
  # @return [Boolean]
117
125
  verify_id def exists?(id)
118
126
  object(id).exists?
@@ -1,5 +1,5 @@
1
1
  module Refile
2
2
  class S3
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "refile", "~> 0.5.0"
20
+ spec.add_dependency "refile", "~> 0.6.0"
21
21
  spec.add_dependency "aws-sdk", "~> 2.0"
22
22
  spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refile-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-23 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: refile
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0
19
+ version: 0.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.0
26
+ version: 0.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: aws-sdk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -130,9 +130,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project:
133
- rubygems_version: 2.4.5
133
+ rubygems_version: 2.4.5.1
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Amazon S3 backend for the Refile gem
137
137
  test_files:
138
138
  - spec/refile/s3_spec.rb
139
+ has_rdoc: