qiniu-rs 1.0.4 → 1.1.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.
data/lib/qiniu/rs.rb CHANGED
@@ -31,8 +31,15 @@ module Qiniu
31
31
  code == StatusOK ? data["url"] : false
32
32
  end
33
33
 
34
- def upload(url, local_file, bucket = '', key = '', mime_type = '', custom_meta = '', callback_params = {})
35
- code, data = IO.put_file(url, local_file, bucket, key, mime_type, custom_meta, callback_params)
34
+ def upload opts = {}
35
+ code, data = IO.put_file(opts[:url],
36
+ opts[:file],
37
+ opts[:bucket],
38
+ opts[:key],
39
+ opts[:mime_type],
40
+ opts[:note],
41
+ opts[:callback_params],
42
+ opts[:enable_crc32_check])
36
43
  code == StatusOK
37
44
  end
38
45
 
@@ -21,9 +21,9 @@ module Qiniu
21
21
  :content_type => 'application/x-www-form-urlencoded',
22
22
  :auth_url => "https://acc.qbox.me/oauth2/token",
23
23
  :rs_host => "http://rs.qbox.me:10100",
24
- :io_host => "http://io.qbox.me",
25
- :client_id => "<YOUR_APP_CLIENT_ID>",
26
- :client_secret => "<YOUR_APP_CLIENT_SECRET>",
24
+ :io_host => "http://iovip.qbox.me",
25
+ :client_id => "",
26
+ :client_secret => "",
27
27
  :auto_reconnect => true,
28
28
  :max_retry_times => 5
29
29
  }
data/lib/qiniu/rs/io.rb CHANGED
@@ -20,17 +20,18 @@ module Qiniu
20
20
  Auth.request(url)
21
21
  end
22
22
 
23
- def put_file(url, local_file, bucket = '', key = '', mime_type = '', custom_meta = '', callback_params = '')
23
+ def put_file(url, local_file, bucket = nil, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false)
24
24
  raise NoSuchFileError unless File.exist?(local_file)
25
- key = Digest::SHA1.hexdigest(local_file + Time.now.to_s) if key.empty?
25
+ key = Digest::SHA1.hexdigest(local_file + Time.now.to_s) if key.nil?
26
26
  entry_uri = bucket + ':' + key
27
- if mime_type.empty?
27
+ if mime_type.nil?
28
28
  mime = MIME::Types.type_for local_file
29
29
  mime_type = mime.empty? ? 'application/octet-stream' : mime[0].content_type
30
30
  end
31
31
  action_params = '/rs-put/' + Utils.urlsafe_base64_encode(entry_uri) + '/mimeType/' + Utils.urlsafe_base64_encode(mime_type)
32
- action_params += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) unless custom_meta.empty?
33
- callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.empty?
32
+ action_params += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) unless custom_meta.nil?
33
+ action_params += '/crc32/' + Utils.crc32checksum(local_file).to_s if enable_crc32_check
34
+ callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.nil?
34
35
  callback_query_string = Utils.generate_query_string(callback_params)
35
36
  Utils.upload_multipart_data(url, local_file, action_params, callback_query_string)
36
37
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'uri'
4
4
  require 'json'
5
+ require 'zlib'
5
6
  require 'base64'
6
7
  require 'rest_client'
7
8
  require 'qiniu/rs/exceptions'
@@ -119,6 +120,10 @@ module Qiniu
119
120
  URI.escape(total_param.join("&"))
120
121
  end
121
122
 
123
+ def crc32checksum(filepath)
124
+ File.open(filepath, "rb") { |f| Zlib.crc32 f.read }
125
+ end
126
+
122
127
  end
123
128
  end
124
129
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Qiniu
4
4
  module RS
5
- VERSION = "1.0.4"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -34,7 +34,11 @@ module Qiniu
34
34
  put_url.should_not be_false
35
35
  put_url.should_not be_empty
36
36
  puts put_url.inspect
37
- result = Qiniu::RS.upload(put_url, __FILE__, @bucket, @key)
37
+ result = Qiniu::RS.upload :url => put_url,
38
+ :file => __FILE__,
39
+ :bucket => @bucket,
40
+ :key => @key,
41
+ :enable_crc32_check => true
38
42
  result.should be_true
39
43
  end
40
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiniu-rs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-28 00:00:00.000000000 Z
12
+ date: 2012-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: -2405318946135011499
158
+ hash: -2090865148466765232
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: -2405318946135011499
167
+ hash: -2090865148466765232
168
168
  requirements: []
169
169
  rubyforge_project:
170
170
  rubygems_version: 1.8.24