Compare commits

...
10 Commits
Author SHA1 Message Date
404 38326cbb83 Merge branch 'release/v1.1.0' 2012-06-08 14:05:17 +08:00
404 853c3b537d added file uploading crc32 check 2012-06-08 14:03:04 +08:00
404 285b766819 Merge branch 'hotfix/v1.0.4' into develop 2012-05-28 21:34:24 +08:00
404 e54081dd88 Merge branch 'hotfix/v1.0.4' 2012-05-28 21:33:52 +08:00
404 a0657ee26f added jruby-openssl bundling if RUBY_PLATFORM is JAVA 2012-05-28 21:33:27 +08:00
404 0fa0839a70 Merge branch 'hotfix/v1.0.3' into develop 2012-05-28 21:22:32 +08:00
404 4c6be498b5 Merge branch 'hotfix/v1.0.3' 2012-05-28 21:22:08 +08:00
404 47db00b7cf bundled gem json 2012-05-28 21:21:49 +08:00
404 658f1ad091 Merge branch 'release/v1.0.2' 2012-05-28 21:06:09 +08:00
404 e2597366e9 added travis and gemnasium hooks 2012-05-28 21:03:47 +08:00
11 changed files with 68 additions and 13 deletions
+12
View File
@@ -0,0 +1,12 @@
language: ruby
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- jruby-18mode
- jruby-19mode
- rbx-18mode
- rbx-19mode
- ruby-head
- jruby-head
- ree
+3 -1
View File
@@ -3,4 +3,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in qiniu-s3.gemspec
gemspec
gem "rake", "~> 0.9"
# platforms :jruby do
# gem "jruby-openssl"
# end
+2
View File
@@ -1,3 +1,5 @@
# Qiniu Resource (Cloud) Storage SDK for Ruby - [![Build Status](https://secure.travis-ci.org/why404/qiniu-rs.png?branch=master)](http://travis-ci.org/why404/qiniu-rs) [![Dependency Status](https://gemnasium.com/why404/qiniu-rs.png)](https://gemnasium.com/why404/qiniu-rs)
# 关于
此 Ruby SDK 适用于 Ruby 1.8.x, 1.9.x 版本,基于 [七牛云存储官方API](http://docs.qiniutek.com/v1/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。
+19
View File
@@ -1,2 +1,21 @@
#!/usr/bin/env rake
require 'rubygems'
require 'bundler'
require "bundler/gem_tasks"
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
task :default => :spec
+9 -2
View File
@@ -31,8 +31,15 @@ module Qiniu
code == StatusOK ? data["url"] : false
end
def upload(url, local_file, bucket = '', key = '', mime_type = '', custom_meta = '', callback_params = {})
code, data = IO.put_file(url, local_file, bucket, key, mime_type, custom_meta, callback_params)
def upload opts = {}
code, data = IO.put_file(opts[:url],
opts[:file],
opts[:bucket],
opts[:key],
opts[:mime_type],
opts[:note],
opts[:callback_params],
opts[:enable_crc32_check])
code == StatusOK
end
+3 -3
View File
@@ -21,9 +21,9 @@ module Qiniu
:content_type => 'application/x-www-form-urlencoded',
:auth_url => "https://acc.qbox.me/oauth2/token",
:rs_host => "http://rs.qbox.me:10100",
:io_host => "http://io.qbox.me",
:client_id => "<YOUR_APP_CLIENT_ID>",
:client_secret => "<YOUR_APP_CLIENT_SECRET>",
:io_host => "http://iovip.qbox.me",
:client_id => "",
:client_secret => "",
:auto_reconnect => true,
:max_retry_times => 5
}
+6 -5
View File
@@ -20,17 +20,18 @@ module Qiniu
Auth.request(url)
end
def put_file(url, local_file, bucket = '', key = '', mime_type = '', custom_meta = '', callback_params = '')
def put_file(url, local_file, bucket = nil, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false)
raise NoSuchFileError unless File.exist?(local_file)
key = Digest::SHA1.hexdigest(local_file + Time.now.to_s) if key.empty?
key = Digest::SHA1.hexdigest(local_file + Time.now.to_s) if key.nil?
entry_uri = bucket + ':' + key
if mime_type.empty?
if mime_type.nil?
mime = MIME::Types.type_for local_file
mime_type = mime.empty? ? 'application/octet-stream' : mime[0].content_type
end
action_params = '/rs-put/' + Utils.urlsafe_base64_encode(entry_uri) + '/mimeType/' + Utils.urlsafe_base64_encode(mime_type)
action_params += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) unless custom_meta.empty?
callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.empty?
action_params += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) unless custom_meta.nil?
action_params += '/crc32/' + Utils.crc32checksum(local_file).to_s if enable_crc32_check
callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.nil?
callback_query_string = Utils.generate_query_string(callback_params)
Utils.upload_multipart_data(url, local_file, action_params, callback_query_string)
end
+5
View File
@@ -2,6 +2,7 @@
require 'uri'
require 'json'
require 'zlib'
require 'base64'
require 'rest_client'
require 'qiniu/rs/exceptions'
@@ -119,6 +120,10 @@ module Qiniu
URI.escape(total_param.join("&"))
end
def crc32checksum(filepath)
File.open(filepath, "rb") { |f| Zlib.crc32 f.read }
end
end
end
end
+1 -1
View File
@@ -2,6 +2,6 @@
module Qiniu
module RS
VERSION = "1.0.1"
VERSION = "1.1.0"
end
end
+3
View File
@@ -17,8 +17,11 @@ Gem::Specification.new do |gem|
gem.version = Qiniu::RS::VERSION
# specify any dependencies here; for example:
gem.add_development_dependency "rake"
gem.add_development_dependency "rspec"
gem.add_development_dependency "fakeweb"
gem.add_runtime_dependency "json"
gem.add_runtime_dependency "rest-client"
gem.add_runtime_dependency "mime-types"
gem.add_runtime_dependency "jruby-openssl" if RUBY_PLATFORM == "java"
end
+5 -1
View File
@@ -34,7 +34,11 @@ module Qiniu
put_url.should_not be_false
put_url.should_not be_empty
puts put_url.inspect
result = Qiniu::RS.upload(put_url, __FILE__, @bucket, @key)
result = Qiniu::RS.upload :url => put_url,
:file => __FILE__,
:bucket => @bucket,
:key => @key,
:enable_crc32_check => true
result.should be_true
end
end