star 1.1.0 → 1.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: 6b29105c837f42831693f510c4afbc907bfd8edc
4
- data.tar.gz: 49b8120b3cf3d9ec80157ac318bacbfdda9de00a
3
+ metadata.gz: 89914a09838e130825c2db61502c74f713b473e7
4
+ data.tar.gz: f2a04a96579ae2512a5162ddf771047be89da6f4
5
5
  SHA512:
6
- metadata.gz: f4ee6b51e48ebe1ccf021ecb52b56d8d46c7fe005fe9175dfa6d619877cb22826be78fe41d03146a7f53a7fe8c5f51e2d75c46391e3ee6d9c40a05115f06ced3
7
- data.tar.gz: 6ddbadb07b009d6c539d98a2be2226b2b462bf04a079fbc987358796327bd374123fb1c80e4f7d048bd39ce94011719760be40ceea7376f467a4a0c355484539
6
+ metadata.gz: f633d688af692ccfa96bdbe6fe462d4271c47ad115528731caa3c4423fd54112506aa7b04bdb4ce1bc80990020465cb36553bc8d2c69e7e614247d9e857cad12
7
+ data.tar.gz: e5baa3c1eaa12a1810d3be5af46b95e2a4cf27ccdd3ff40cabb3cba2fed012acea8c5176ccc48beb58227f2c6fb582cfebee566b94b693e7b594138d6dcfc00f
@@ -4,4 +4,4 @@ rvm:
4
4
  before_install: gem install bundler -v 1.10.6
5
5
  env:
6
6
  matrix:
7
- - secure: ZqWedYLyWoAdrXIOfQfP7XXk1iwhM4BOql1tufimM/K8KELAhQHILKLiCodnBeFptUoBQgkIaGKLRxSD+g7epzeCzLZoUV1H9DbGf0wR6dJI0ZJKFJMMKu2GVl13+CLkO2zvGciEXmvL1Vj/kvHtyBRddeeCVZgq5f65YU5rpS+pzl5v1rWia24ikK+uUKxvYxyN+owIN+GpvHAFrJ5vMpppmrlSU5OGO1S2KtaX09OxgTxM7Jo0s1Zls0eAtZMdKqdg8hW8u3I8M4Jyu7DRYdalwgZX5BEnjIpr2xBMwHOskVfuUMOnaH5FMCxUSDKHW5j7priRFayN0m+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  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 1.2.0 - 2015.01.25
10
+
11
+ * [FEATURE] Add `Star::File#copy_from` to duplicate files
12
+
9
13
  ## 1.1.0 - 2015.10.26
10
14
 
11
15
  * [FEATURE] Add `Star::File#delete` to delete files
data/README.md CHANGED
@@ -87,6 +87,8 @@ from sharing the URL and having other (unauthenticated) users download it.
87
87
 
88
88
  To delete the file from S3, simply call `file.delete`.
89
89
 
90
+ To duplicate the file to a different location, simply call `other.copy_from(file)`.
91
+
90
92
  Options
91
93
  -------
92
94
 
@@ -38,6 +38,14 @@ module Star
38
38
  Star.remote? ? delete_remote : delete_local
39
39
  end
40
40
 
41
+ def copy_from(source)
42
+ Star.remote? ? copy_from_remote(source) : copy_from_local(source)
43
+ end
44
+
45
+ def remote_path
46
+ URI.escape path
47
+ end
48
+
41
49
  private
42
50
 
43
51
  def store_remote(tmp_file)
@@ -75,10 +83,36 @@ module Star
75
83
  end
76
84
  end
77
85
 
86
+ def copy_from_remote(source)
87
+ timestamp = Time.now.utc.strftime "%a, %d %b %Y %H:%M:%S UTC"
88
+ extra = "x-amz-copy-source:/#{bucket}#{source.remote_path}"
89
+ signature = sign "PUT\n\n#{@content_type}\n#{timestamp}\n#{extra}"
90
+ request = copy_file signature, timestamp, source
91
+ response = Net::HTTP.start(host, 443, use_ssl: true) do |http|
92
+ http.request request
93
+ end
94
+ response.error! unless response.is_a? Net::HTTPSuccess
95
+ sleep 3 # See https://forums.aws.amazon.com/message.jspa?messageID=370480
96
+ end
97
+
98
+ def copy_file(signature, timestamp, source)
99
+ Net::HTTP::Put.new("/#{bucket}#{remote_path}").tap do |request|
100
+ request.add_field 'Date', timestamp
101
+ request.add_field 'Content-Type', @content_type
102
+ request.add_field 'x-amz-copy-source', "/#{bucket}#{source.remote_path}"
103
+ request.add_field 'Authorization', "AWS #{key}:#{signature}"
104
+ end
105
+ end
106
+
78
107
  def delete_local
79
108
  FileUtils.rm_f path
80
109
  end
81
110
 
111
+ def copy_from_local(source)
112
+ FileUtils.mkdir_p ::File.dirname(path)
113
+ FileUtils.cp source.path, path
114
+ end
115
+
82
116
  def url_params
83
117
  expires_at = Time.now.to_i + Star.configuration.duration
84
118
  digest = OpenSSL::Digest.new 'sha1'
@@ -117,10 +151,6 @@ module Star
117
151
  "s3.amazonaws.com"
118
152
  end
119
153
 
120
- def remote_path
121
- URI.escape path
122
- end
123
-
124
154
  def key
125
155
  Star.configuration.access_key_id
126
156
  end
@@ -1,3 +1,3 @@
1
1
  module Star
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: star
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - claudiob
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-01-08 00:00:00.000000000 Z
12
+ date: 2016-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler