qiniu_mini_sdk 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/qiniu_mini_sdk.rb +1 -0
- data/lib/qiniu_mini_sdk/policy.rb +17 -1
- data/lib/qiniu_mini_sdk/sign.rb +13 -0
- data/lib/qiniu_mini_sdk/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4702d5745c9b30176cabf6e4c36fa1f27b47e605
|
4
|
+
data.tar.gz: bcfd6c38858c041903b593052ae5f76ced063e5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2698039be3a5d43b454da8d60ede884987711e70071ab1e897dd89a70c9b516d7a32c20d6e1188695f62139a1d74e2aad3dbcedd833c83fc4313c0572911ffd3
|
7
|
+
data.tar.gz: 5bf582135d5316acea69b50c016b3c90e4ff0008c44b0be76e4e8624410337d6a38109d7db4e5b3675828319f23d3bb362d6f6532e3d713e32af8cf9fc4dbe8d
|
data/README.md
CHANGED
@@ -35,6 +35,10 @@ qiniu.uptoken
|
|
35
35
|
# 获取下载地址
|
36
36
|
qiniu = QiniuMiniSdk::Policy.new bucket: '你的buckname', key: '你下载资源的key', expires_in: '有效期,可以不填直接忽略这个参数, 默认为3600秒'
|
37
37
|
qiniu.download_url
|
38
|
+
|
39
|
+
# 管理token
|
40
|
+
qiniu = QiniuMiniSdk::Policy.new url: "http://rs.qiniu.com/delete/#{QiniuMiniSdk::Sign.urlsafe_base64_encode 'test-123123:FuAUJ1D1kqiFSJ8bhJ2ZvfyJj_aH'}"
|
41
|
+
qiniu.acctoken
|
38
42
|
```
|
39
43
|
|
40
44
|
## Contributing
|
data/lib/qiniu_mini_sdk.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'json'
|
4
4
|
require 'base64'
|
5
5
|
require 'openssl'
|
6
|
+
require 'uri'
|
6
7
|
|
7
8
|
module QiniuMiniSdk
|
8
9
|
class Policy
|
@@ -22,6 +23,13 @@ module QiniuMiniSdk
|
|
22
23
|
@bucket = bucket
|
23
24
|
end
|
24
25
|
|
26
|
+
def url=(url)
|
27
|
+
@url = url
|
28
|
+
end
|
29
|
+
|
30
|
+
def body=(body)
|
31
|
+
@body = body
|
32
|
+
end
|
25
33
|
|
26
34
|
def expires_in=(time)
|
27
35
|
@params[:deadline] = Time.now.to_i + time
|
@@ -33,12 +41,20 @@ module QiniuMiniSdk
|
|
33
41
|
"#{access_key}:#{encoded_sign}:#{hmac_sha1_sign encoded_put_policy}"
|
34
42
|
end
|
35
43
|
|
44
|
+
def acctoken
|
45
|
+
uri = URI.parse(@url)
|
46
|
+
query = '?' + uri.query unless uri.query.nil?
|
47
|
+
signing_str = "#{uri.path}#{uri.query}\n#{@body}"
|
48
|
+
"#{QiniuMiniSdk.access_key}:#{hmac_sha1_sign signing_str}"
|
49
|
+
end
|
50
|
+
|
36
51
|
def download_url
|
37
52
|
base_url = QiniuMiniSdk.urls[@bucket] || "http://#{@bucket}.qiniudn.com"
|
38
53
|
url = "#{base_url}/#{@key}?e=#{@params[:deadline]}"
|
39
54
|
"#{url}&token=#{QiniuMiniSdk.access_key}:#{hmac_sha1_sign url}"
|
40
55
|
end
|
41
56
|
|
57
|
+
|
42
58
|
def method_missing(meth, *args, &blk)
|
43
59
|
if meth =~ /(.+)=/
|
44
60
|
@params[$1.to_s] = args.first
|
@@ -63,7 +79,7 @@ module QiniuMiniSdk
|
|
63
79
|
end
|
64
80
|
|
65
81
|
def default
|
66
|
-
raise "没有指定bucket" if @bucket.nil?
|
82
|
+
raise "没有指定bucket" if @bucket.nil? && @url.nil?
|
67
83
|
self.expires_in = 3600 if @params[:deadline].nil?
|
68
84
|
@params[:scope] = "#{@bucket}:#{@key}" unless @key.nil?
|
69
85
|
@params[:scope] = "#{@bucket}" if @key.nil?
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module QiniuMiniSdk
|
2
|
+
module Sign
|
3
|
+
module_function
|
4
|
+
def urlsafe_base64_encode content
|
5
|
+
Base64.encode64(content).strip.gsub('+', '-').gsub('/','_').gsub(/\r?\n/, '')
|
6
|
+
end
|
7
|
+
|
8
|
+
def hmac_sha1_sign(data)
|
9
|
+
digest = OpenSSL::Digest.new('sha1')
|
10
|
+
urlsafe_base64_encode OpenSSL::HMAC.digest(digest, QiniuMiniSdk.secret_key, data)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiniu_mini_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mjason
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- lib/qiniu_mini_sdk.rb
|
54
54
|
- lib/qiniu_mini_sdk/policy.rb
|
55
|
+
- lib/qiniu_mini_sdk/sign.rb
|
55
56
|
- lib/qiniu_mini_sdk/version.rb
|
56
57
|
- qiniu_mini_sdk.gemspec
|
57
58
|
homepage: https://github.com/mjason/qiniu_mini_sdk
|