mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-10 05:18:37 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38326cbb83 | ||
|
|
853c3b537d | ||
|
|
285b766819 | ||
|
|
e54081dd88 | ||
|
|
a0657ee26f | ||
|
|
0fa0839a70 | ||
|
|
4c6be498b5 | ||
|
|
47db00b7cf | ||
|
|
658f1ad091 | ||
|
|
e2597366e9 |
+12
@@ -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,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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Qiniu Resource (Cloud) Storage SDK for Ruby - [](http://travis-ci.org/why404/qiniu-rs) [](https://gemnasium.com/why404/qiniu-rs)
|
||||
|
||||
# 关于
|
||||
|
||||
此 Ruby SDK 适用于 Ruby 1.8.x, 1.9.x 版本,基于 [七牛云存储官方API](http://docs.qiniutek.com/v1/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
VERSION = "1.0.1"
|
||||
VERSION = "1.1.0"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user