aws-sdk-resources 2.0.11.pre → 2.0.12.pre

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: c40fdd4d2650569c8c2c171fc78ff3b028bcca01
4
- data.tar.gz: eaa5e8d378d80948885606de523ab83fa48cd1fa
3
+ metadata.gz: 4ca487789f2a39ff784ba8b39432b8a59d94038c
4
+ data.tar.gz: ddf5b991bd762e79fc62a542e140a06f4fa10e9f
5
5
  SHA512:
6
- metadata.gz: 0b28aff2fd2739d2412ff3b259a63cf283477485fdcaa45b67d10e5b11d19fa732a636f5efbfdb9b6d9f64590c2e5df42bfc31f358e9936638df63f915fdda5f
7
- data.tar.gz: baf2c5ba95436817c23af6caa2bbc5576591ea8e03dbd245479f72612a50514546fd1ff171e52e33990750521728948124df11ce5d5c87c5c64a89a0545caeb5
6
+ metadata.gz: 7ebe4e9108017edfc0d2eac908a5518b3440d584b576f4eec4e53325e60af98390375ef2731e07ced6c065e752effc9ce53fa08f0fdd2452915af063933f0493
7
+ data.tar.gz: 7827a636fbfe52562a591c977f62a0ace65bd148fd7a2871e5676218e3c6c3eea31017c83a1cfb118db53cb6a67a93dcf3ab80a8ecc96a9d4b1f7972b91902bc
@@ -4,6 +4,7 @@ module Aws
4
4
  require 'aws-sdk-resources/services/s3/bucket'
5
5
  require 'aws-sdk-resources/services/s3/object'
6
6
  require 'aws-sdk-resources/services/s3/multipart_upload'
7
+ require 'aws-sdk-resources/services/s3/public_url'
7
8
 
8
9
  autoload :FilePart, 'aws-sdk-resources/services/s3/file_part'
9
10
  autoload :FileUploader, 'aws-sdk-resources/services/s3/file_uploader'
@@ -48,6 +48,21 @@ module Aws
48
48
  ))
49
49
  end
50
50
 
51
+ # Returns the public (un-signed) URL for this object.
52
+ #
53
+ # s3.bucket('bucket-name').object('obj-key').public_url
54
+ # #=> "https://bucket-name.s3.amazonaws.com/obj-key"
55
+ #
56
+ # @return [String]
57
+ def public_url
58
+ PublicUrl.build(
59
+ endpoint: client.config.endpoint,
60
+ bucket_name: bucket_name,
61
+ object_key: key,
62
+ force_path_style: client.config.force_path_style
63
+ )
64
+ end
65
+
51
66
  # Uploads a file from disk to the current object in S3.
52
67
  #
53
68
  # @example
@@ -0,0 +1,71 @@
1
+ module Aws
2
+ module S3
3
+ # @api private
4
+ module PublicUrl
5
+ class << self
6
+
7
+ # @option options [required, URI::HTTP, URI::HTTPS] :endpoint
8
+ # The Amazon S3 endpoint to generate the public URL against.
9
+ #
10
+ # @option options [required, String] :bucket_name Name of the bucket
11
+ # the object is in.
12
+ #
13
+ # @option options [required, String] :object_key Key of the object
14
+ # to generate a URL for.
15
+ #
16
+ # @param [Boolean] :force_path_style (false) When `true`, the bucket
17
+ # name will always be part of the URI path. When `false`, DNS
18
+ # compatible bucket names will be the endpoint host subdomain.
19
+ #
20
+ # # path style
21
+ # "https://s3.amazonaws.com/bucket-name/key"
22
+ #
23
+ # # dns-style
24
+ # "https://bucket-name.s3.amazonaws.com/key"
25
+ #
26
+ # @return [String]
27
+ def build(options = {})
28
+ endpoint = options[:endpoint].dup
29
+ apply_bucket_name(endpoint, options)
30
+ apply_object_key(endpoint, options)
31
+ endpoint.to_s
32
+ end
33
+
34
+ private
35
+
36
+ def apply_bucket_name(endpoint, options)
37
+ if path_style?(endpoint, options)
38
+ endpoint.path += '/' unless endpoint.path[-1] == '/'
39
+ endpoint.path += Seahorse::Util.uri_escape(options[:bucket_name])
40
+ else
41
+ endpoint.host = options[:bucket_name] + '.' + endpoint.host
42
+ end
43
+ end
44
+
45
+ def apply_object_key(endpoint, options)
46
+ key = options[:object_key]
47
+ endpoint.path += '/' unless endpoint.path[-1] == '/'
48
+ endpoint.path += key.split('/').map { |v| escape(v) }.join('/')
49
+ end
50
+
51
+ def path_style?(endpoint, options)
52
+ options[:force_path_style] == true ||
53
+ dns_compat?(endpoint, options) == false
54
+ end
55
+
56
+ def dns_compat?(endpoint, options)
57
+ Aws::Plugins::S3BucketDns.dns_compatible?(
58
+ options[:bucket_name],
59
+ endpoint.scheme == 'https'
60
+ )
61
+ end
62
+
63
+ def escape(string)
64
+ Seahorse::Util.uri_escape(string)
65
+ end
66
+
67
+
68
+ end
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11.pre
4
+ version: 2.0.12.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-26 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.11
19
+ version: 2.0.12
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: 2.0.11
26
+ version: 2.0.12
27
27
  description: Provides resource-oriented abstractions for AWS.
28
28
  email:
29
29
  executables: []
@@ -59,6 +59,7 @@ files:
59
59
  - lib/aws-sdk-resources/services/s3/multipart_upload.rb
60
60
  - lib/aws-sdk-resources/services/s3/multipart_upload_error.rb
61
61
  - lib/aws-sdk-resources/services/s3/object.rb
62
+ - lib/aws-sdk-resources/services/s3/public_url.rb
62
63
  - lib/aws-sdk-resources/services/s3.rb
63
64
  - lib/aws-sdk-resources/services/sqs/queue.rb
64
65
  - lib/aws-sdk-resources/services/sqs.rb