s3_sign 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 447a0d533f6b48c8ba047c28404ed883505f2433
4
- data.tar.gz: 459ba0f3170e825a39555cfb43bac368c329ee44
3
+ metadata.gz: 96c16aa5ab1087cbc5bc750ddc183f1bda15ba37
4
+ data.tar.gz: 8fd8b1cf944bab603d44e598fabb6a6511561f90
5
5
  SHA512:
6
- metadata.gz: c3cc28ad515aa2542735e63e49e5843aa0ca4ccdd7a15374a073c2b0c2cbee06c28293ff62dcbde7f2ba02cc5c24c90f96104b93e088436dacf9f8f39ac569e8
7
- data.tar.gz: 7672f0e87dc8023452fc00342ec8a5013599cb7f642f7d954e19fb5032dde26371bd9807e505693857d7f8ec6caeb427afa243224b83c51ba7e8f2f30be2a3e5
6
+ metadata.gz: a03766738b4e08e50fade4f2b77ae9d7591c259eb04bbcd8df35846dff2a8eb2159a1cd0c5b8e0cd132ac709a783fef30bad9f96e498ffc8b65c250668a95126
7
+ data.tar.gz: 4bebcb938b7640b0b348c7d22a89c8ed8605b5f25fa381420c6f9c2d9c761166351ba18d59de1ed136124eff769038da84c1519932e42f568adf0ee0baaf26f0
data/README.md CHANGED
@@ -45,7 +45,7 @@ The `S3Sign` module itself provides `.url`:
45
45
 
46
46
  ```ruby
47
47
  # Pass a full s3 url and 1 hour expiration
48
- S3Sign.url "http://s3.amazonaws.com/bucket/foo.png", 3600
48
+ S3Sign.url "http://s3.amazonaws.com/bucket/foo.png", expires: 3600
49
49
  # => "https://bucket.s3.amazonaws.com/foo.png?AWSAccessKeyId=access_key_id&Expires=1427243780&Signature=a3RzDgElxDpSZLgxurZLiw1a6Ny%3D"
50
50
 
51
51
  # Pass a 'key' portion found under the bucket with default expiration
@@ -55,10 +55,10 @@ S3Sign.url "images/foo.png"
55
55
  The gem also provides a `S3Sign::Helper` module, useful to mixin to rails
56
56
  controllers. It will add two helper methods to your controllers and views.
57
57
 
58
- `s3_signed_url_for_key` - Takes a key/url and optional expires
58
+ `s3_signed_url_for_key` - Takes a key/url and options
59
59
 
60
- `stable_s3_signed_url` - Takes a url and optional reference time. Used for
61
- generting signatures that expire in the far future year 2036.
60
+ `stable_s3_signed_url` - Takes a url and options. Used for
61
+ generating signatures that expire in the far future year 2036.
62
62
 
63
63
  ## Contributing
64
64
 
@@ -12,17 +12,27 @@ module S3Sign
12
12
  end
13
13
  end
14
14
 
15
- def self.url(s3_url, expires = SEVEN_DAYS)
15
+ def self.url(s3_url, options = {})
16
16
  s3 = AWS::S3.new
17
17
  bucket = s3.buckets[bucket_name]
18
18
 
19
19
  path = path_from_s3_url(s3_url)
20
20
 
21
- AWS::S3::S3Object.new(bucket, path).url_for(:read, expires: expires).to_s
21
+ AWS::S3::S3Object.new(bucket, path).url_for(:read, build_options(options)).to_s
22
22
  end
23
23
 
24
24
  protected
25
25
 
26
+ def self.build_options(options)
27
+ { expires: options.fetch(:expires, SEVEN_DAYS) }.tap do |o|
28
+ attachment_filename = options[:attachment_filename]
29
+
30
+ if attachment_filename
31
+ o[:response_content_disposition] = "attachment; filename=#{attachment_filename}"
32
+ end
33
+ end
34
+ end
35
+
26
36
  def self.path_from_s3_url(s3_url)
27
37
  s3_url.sub(%r{^.+?/#{bucket_name}/}, '')
28
38
  end
@@ -14,8 +14,9 @@ module S3Sign
14
14
 
15
15
  # A pure "time from now" signed s3 asset url. Good for non-visual elements
16
16
  # like attachments, and not thumbnails, that don't have the same caching concerns
17
- def s3_signed_url_for_key(key, expires_in = 86_400)
18
- S3Sign.url key, expires_in
17
+ def s3_signed_url_for_key(key, options = {})
18
+ options[:expires] ||= 86_400
19
+ S3Sign.url key, options
19
20
  end
20
21
 
21
22
  # Uses a far-future date so that the expires and signature on
@@ -33,10 +34,10 @@ module S3Sign
33
34
  # far future stable year. This is useful to cache-bust the url from
34
35
  # an updated_at timestamp where some browsers/proxies may try to use
35
36
  # the cached asset even though it was updated.
36
- def stable_s3_signed_url(url, reference_time = nil)
37
+ def stable_s3_signed_url(url, options = {})
37
38
  @stable_s3_expire_at ||= Time.parse("2036-1-1 00:00:00 UTC")
38
39
 
39
- if reference_time
40
+ if reference_time = options.delete(:expires)
40
41
  # The time given but in the year 2036
41
42
  year = @stable_s3_expire_at.year
42
43
  expires_at = Time.parse(reference_time.utc.strftime("#{year}-%m-%d %T UTC"))
@@ -44,7 +45,7 @@ module S3Sign
44
45
  expires_at = @stable_s3_expire_at
45
46
  end
46
47
 
47
- s3_signed_url_for_key(url, expires_at)
48
+ s3_signed_url_for_key(url, expires: expires_at)
48
49
  end
49
50
  end
50
51
  end
@@ -1,3 +1,3 @@
1
1
  module S3Sign
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_sign
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
  - Brendon Murphy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk