sndacs 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sndacs (0.2.2)
4
+ sndacs (0.2.3)
5
5
  proxies (~> 0.2.0)
6
6
 
7
7
  GEM
data/README.rdoc CHANGED
@@ -101,6 +101,12 @@ set bucket public
101
101
  Get a temporary url to the object that expires on the timestamp given.Defaults to 1hour expire time
102
102
  object.temporary_url( Time.now + 60 )
103
103
 
104
+ === Get url to a public accessible object
105
+
106
+ Get a url to a public accessible object,the url only work when the object is public accessible
107
+
108
+ object.url( public_accessible = true)
109
+
104
110
  === Delete an object
105
111
 
106
112
  object.destroy
@@ -149,7 +149,7 @@ module Sndacs
149
149
  :x_snda_copy_source_if_none_match,
150
150
  :x_snda_copy_source_if_unmodified_since,
151
151
  :x_snda_copy_source_if_modified_since]
152
-
152
+ user_meta_data_prefix = "x-snda-meta-"
153
153
  parsed_headers = {}
154
154
  if headers
155
155
  headers.each do |key, value|
@@ -163,6 +163,12 @@ module Sndacs
163
163
  end
164
164
 
165
165
  parsed_headers[parsed_key] = parsed_value
166
+ else
167
+ parsed_key = key.to_s.gsub("_","-")
168
+ if parsed_key[0,user_meta_data_prefix.length] === user_meta_data_prefix
169
+ parsed_headers[parsed_key] = value
170
+ end
171
+
166
172
  end
167
173
  end
168
174
  end
data/lib/sndacs/object.rb CHANGED
@@ -72,24 +72,25 @@ module Sndacs
72
72
  end
73
73
 
74
74
  # Saves the object, returns true if successfull.
75
- def save
76
- put_object
75
+ # ==== Options
76
+ # request headers
77
77
 
78
+ def save(options = {})
79
+ put_object(options)
78
80
  true
79
81
  end
80
82
 
81
- # Copies the file to another key and/or bucket.
83
+ # copies the file from another key and/or bucket.
82
84
  #
83
85
  # ==== Options
84
- # * <tt>:key</tt> - New key to store object in
85
- # * <tt>:bucket</tt> - New bucket to store object in (instance of
86
- # Sndacs::Bucket)
87
- # * <tt>:acl</tt> - ACL of the copied object (default:
88
- # "public-read")
89
- # * <tt>:content_type</tt> - Content type of the copied object
90
- # (default: "application/octet-stream")
86
+ # * <tt>:key</tt> - key for copy
87
+ # * <tt>:bucket</tt> - bucket's name which the source file stored
88
+ # * <tt>:x_snda_metadata..</tt> - params for copy which is not nessary
89
+ #
91
90
  def copy(options = {})
92
91
  copy_object(options)
92
+ retrieve
93
+ true
93
94
  end
94
95
 
95
96
  # Destroys the file on the server
@@ -155,7 +156,7 @@ module Sndacs
155
156
  headers = {}
156
157
 
157
158
  #headers[:x_snda_acl] = options[:acl] || acl || "public-read"
158
- headers[:content_type] = options[:content_type] || content_type || "application/octet-stream"
159
+ headers[:content_type] = options[:content_type] || content_type || content_type_for_key
159
160
  headers[:content_encoding] = options[:content_encoding] if options[:content_encoding]
160
161
  headers[:content_disposition] = options[:content_disposition] if options[:content_disposition]
161
162
  headers[:cache_control] = options[:cache_control] if options[:cache_control]
@@ -165,9 +166,10 @@ module Sndacs
165
166
  headers[:x_snda_copy_source_if_none_match] = options[:if_none_match] if options[:if_none_match]
166
167
  headers[:x_snda_copy_source_if_unmodified_since] = options[:if_modified_since] if options[:if_modified_since]
167
168
  headers[:x_snda_copy_source_if_modified_since] = options[:if_unmodified_since] if options[:if_unmodified_since]
168
-
169
+ headers = merge_usermetadata_toheader(options,headers)
169
170
  response = object_request(:put,:headers => headers)
170
- response.body
171
+ #response.body
172
+ #true
171
173
  end
172
174
 
173
175
  def get_object(options = {})
@@ -188,10 +190,11 @@ module Sndacs
188
190
  end
189
191
  end
190
192
 
191
- def put_object
192
- response = object_request(:put, :body => content, :headers => dump_headers)
193
+ def put_object(options={})
194
+ response = object_request(:put, :body => content, :headers => dump_headers(options))
193
195
 
194
196
  parse_headers(response)
197
+ retrieve
195
198
  end
196
199
 
197
200
  def delete_object(options = {})
@@ -227,17 +230,37 @@ module Sndacs
227
230
  end
228
231
  end
229
232
 
230
- def dump_headers
233
+ def content_type_for_key
234
+ if mime_type = MIME::Types.type_for(key).first
235
+ mime_type.content_type
236
+ else
237
+ "application/octet-stream"
238
+ end
239
+ end
240
+
241
+ def dump_headers(options={})
231
242
  headers = {}
232
- headers[:x_snda_acl] = @acl || "public-read"
233
- headers[:x_snda_storage_class] = @storage_class || "STANDARD"
234
- headers[:content_type] = @content_type || "application/octet-stream"
235
- headers[:content_encoding] = @content_encoding if @content_encoding
236
- headers[:content_disposition] = @content_disposition if @content_disposition
237
- headers[:cache_control] = @cache_control if @cache_control
243
+ #headers[:x_snda_acl] = @acl || "public-read"
244
+ #headers[:x_snda_storage_class] = @storage_class || "STANDARD"
245
+ headers[:content_type] = options[:content_type] || @content_type || content_type_for_key
246
+ headers[:content_encoding] = options[:content_encoding] || @content_encoding if @content_encoding
247
+ headers[:content_disposition] = options[:content_disposition] || @content_disposition if @content_disposition
248
+ headers[:cache_control] = options[:cache_control] || @cache_control if @cache_control
249
+ headers = merge_usermetadata_toheader(options,headers)
238
250
  headers
239
251
  end
240
-
252
+
253
+ def merge_usermetadata_toheader(options,headers)
254
+ user_meta_data_prefix = "x-snda-meta-"
255
+ options.each do |key,value|
256
+ parse_key = key.to_s.gsub("_","-").downcase
257
+ if parse_key[0,user_meta_data_prefix.length] === user_meta_data_prefix
258
+ headers[parse_key] = value
259
+ end
260
+ end
261
+ headers
262
+ end
263
+
241
264
  def parse_headers(response)
242
265
  @metadata = response.to_hash.select { |k, v| k.to_s.start_with?("x-snda-meta") }
243
266
  self.etag = response["etag"] if response.key?("etag")
@@ -1,3 +1,3 @@
1
1
  module Sndacs
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/sndacs.rb CHANGED
@@ -10,6 +10,7 @@ require "net/https"
10
10
  require "openssl"
11
11
  require "rexml/document"
12
12
  require "time"
13
+ require "mime/types"
13
14
 
14
15
  require "proxies"
15
16
  require "sndacs/objects_extension"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sndacs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - LI Daobing
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-04 00:00:00 Z
18
+ date: 2012-09-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: proxies