qiniu-kit 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/.travis.yml +24 -0
- data/Gemfile +9 -0
- data/LICENSE +20 -0
- data/README.md +124 -0
- data/Rakefile +6 -0
- data/lib/qiniu/errors.rb +22 -0
- data/lib/qiniu/kit/mac.rb +43 -0
- data/lib/qiniu/kit/version.rb +7 -0
- data/lib/qiniu/kit.rb +36 -0
- data/lib/qiniu-kit.rb +10 -0
- data/lib/qiniu.rb +28 -0
- data/qiniu-kit.gemspec +26 -0
- data/spec/qiniu/kit/mac_spec.rb +47 -0
- data/spec/qiniu/kit/version_spec.rb +15 -0
- data/spec/qiniu/kit_spec.rb +47 -0
- data/spec/spec_helper.rb +15 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzJlYmRkYzQxYzExZjc0YjgzOTdhOGRjMWMyNWRhMmE1ZGJmM2JiZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWRmMzJmYzdmYWU1ZGY5MTNkNWZmMzRjMWExNDJmNWRkNDE5MGYxZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDk0NzI2MGViZTRiYTBlY2YwMmE1OGU4ZDdmN2Y4MDI2OTgxMDQxNWNjYjll
|
10
|
+
ODA0MTVkMTQxNjliOWI0OGZjYjA5YTU2MzYyYzNlOTdhMzg5MTQwMzM0NDIy
|
11
|
+
NjI2NmE2NzNlMmVmMDFiOTBiZGYwNGVmNTFmOTY3MDhjMzZlZTk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTZiOGZhM2RhNWRjOTk5MjQ0ZTA5ZmE4YmJmMjgzODEzNDlkYjAyNDdkMGU5
|
14
|
+
ZGFkMTIyMjcwYmE0NjZkYzkwMzI5M2E4MDk5OTEzZTc5NjZlOThiZTcxNzkw
|
15
|
+
OTc3ODhkODg0N2UxNTc3Y2EyZDIzODY5ZDQ3ODIzM2M0MzYwN2I=
|
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
Gemfile.lock
|
6
|
+
coverage
|
7
|
+
InstalledFiles
|
8
|
+
lib/bundler/man
|
9
|
+
pkg
|
10
|
+
rdoc
|
11
|
+
spec/reports
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tmp
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
# VIM
|
22
|
+
[._]*.s[a-w][a-z]
|
23
|
+
[._]s[a-w][a-z]
|
24
|
+
*.un~
|
25
|
+
*~
|
26
|
+
|
27
|
+
# OSX
|
28
|
+
.DS_Store
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.8.7
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1.0
|
8
|
+
- ruby-head
|
9
|
+
- jruby-18mode
|
10
|
+
- jruby-19mode
|
11
|
+
- jruby-head
|
12
|
+
- rbx
|
13
|
+
- ree
|
14
|
+
before_script:
|
15
|
+
- export QINIU_ACCESS_KEY=key_for_test
|
16
|
+
- export QINIU_SECRET_KEY=secret_for_test
|
17
|
+
deploy:
|
18
|
+
provider: rubygems
|
19
|
+
api_key:
|
20
|
+
secure: dFb7wl5NabGx+uhx6sph47sTVV1zdgHH+n5wsaIyLkQmGZPdgDc0Kz1Gr3XrKzUTjFeiKwRnPkamqMReweq/nkH43Z/F01dgPdgWVNekDTFEd6V06VXN00yhHeCLpQo52YdJ9f/gPsZKlCiOo+4Y3uwzClS3n8pT8kXb2M8z3ao=
|
21
|
+
gem: qiniu-kit
|
22
|
+
on:
|
23
|
+
tags: true
|
24
|
+
repo: why404/qiniu-kit
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 why404
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# qiniu-kit
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/why404/qiniu-kit.png?branch=master)](https://travis-ci.org/why404/qiniu-kit)
|
4
|
+
[![Dependency Status](https://gemnasium.com/why404/qiniu-kit.png)](https://gemnasium.com/why404/qiniu-kit)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/why404/qiniu-kit/badge.png)](https://coveralls.io/r/why404/qiniu-kit)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/why404/qiniu-kit.png)](https://codeclimate.com/github/why404/qiniu-kit)
|
7
|
+
[![Gem Version](https://fury-badge.herokuapp.com/rb/qiniu-kit.png)](http://badge.fury.io/rb/qiniu-kit)
|
8
|
+
|
9
|
+
A collection of helpful methods for debugging Qiniu Cloud Storage API.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'qiniu-kit'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install qiniu-kit
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'qiniu-kit'
|
29
|
+
|
30
|
+
|
31
|
+
Qiniu::Kit.decode_json('{"abc":"def"}')
|
32
|
+
#=> {"abc" => "def"}
|
33
|
+
|
34
|
+
Qiniu::Kit.decode_json('{"abc":"def"}', :symbolize_keys => true)
|
35
|
+
#=> {:abc => "def"}
|
36
|
+
|
37
|
+
Qiniu::Kit.encode_json({:abc => 'def'})
|
38
|
+
# convert Ruby back to JSON
|
39
|
+
|
40
|
+
Qiniu::Kit.encode_json({:abc => 'def'}, :pretty => true)
|
41
|
+
# encoded in a pretty form (if supported by the coder)
|
42
|
+
|
43
|
+
|
44
|
+
Qiniu::Kit.base64_url_encode("bucket:key")
|
45
|
+
#=> "YnVja2V0OmtleQ=="
|
46
|
+
|
47
|
+
Qiniu::Kit.base64_url_decode("YnVja2V0OmtleQ==")
|
48
|
+
#=> "bucket:key"
|
49
|
+
|
50
|
+
Qiniu::Kit.entry_uri_encode("bucket", "key")
|
51
|
+
#=> "YnVja2V0OmtleQ=="
|
52
|
+
|
53
|
+
|
54
|
+
default_mac = Qiniu::Kit::Mac.new
|
55
|
+
# this will load Qiniu.config[:access_key] and Qiniu.config[:secret_key] as its args
|
56
|
+
|
57
|
+
mac = Qiniu::Kit::Mac.new("access_key", "secret_key")
|
58
|
+
#=> #<Qiniu::Kit::Mac:0x007fb87ba89040 @access_key="access_key", @secret_key="secret_key">
|
59
|
+
|
60
|
+
mac.hmac_sha1_digest('data')
|
61
|
+
#=> "A\xF3\xC2\x14\xCE\x97\xEEY5,\rC\xD5P/\xAC\xA4\xB9l\x13"
|
62
|
+
|
63
|
+
mac.base64_hmac_sha1_digest('data')
|
64
|
+
#=> "QfPCFM6X7lk1LA1D1VAvrKS5bBM="
|
65
|
+
|
66
|
+
mac.sign('data')
|
67
|
+
#=> "access_key:QfPCFM6X7lk1LA1D1VAvrKS5bBM="
|
68
|
+
|
69
|
+
mac.sign_with_data('data')
|
70
|
+
#=> "access_key:AbKufp75scn1gPkjEi1PNDcH3qg=:ZGF0YQ=="
|
71
|
+
|
72
|
+
url = 'http://domain/key?param1=value1¶m2=value2'
|
73
|
+
body = nil
|
74
|
+
mac.sign_with_request(url, body)
|
75
|
+
#=> "access_key:85Q_5E2cYOMeVFg1a50nW3To2n8="
|
76
|
+
```
|
77
|
+
|
78
|
+
## Configuration
|
79
|
+
|
80
|
+
You can configure your Qiniu account access credentials globally. This is very useful to setup onther Qiniu libraries, like [qiniu-policy](https://github.com/why404/qiniu-policy).
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
require 'qiniu-kit'
|
84
|
+
|
85
|
+
Qiniu.config = {:access_key => '...', :secret_key => '...'}
|
86
|
+
```
|
87
|
+
|
88
|
+
Additionally, the library will attempt to load these options from `ENV`:
|
89
|
+
|
90
|
+
export QINIU_ACCESS_KEY='...'
|
91
|
+
export QINIU_SECRET_KEY='...'
|
92
|
+
|
93
|
+
|
94
|
+
## TODO
|
95
|
+
|
96
|
+
- support http requests/responses
|
97
|
+
|
98
|
+
## Supported Ruby versions
|
99
|
+
|
100
|
+
This library aims to support and is [tested against](https://travis-ci.org/why404/qiniu-kit) the following Ruby implementations:
|
101
|
+
|
102
|
+
- MRI 2.1.0
|
103
|
+
- MRI 2.0.0
|
104
|
+
- MRI 1.9.3
|
105
|
+
- MRI 1.9.2
|
106
|
+
- MRI 1.8.7
|
107
|
+
- JRuby 1.7.9 in Ruby 1.8 mode
|
108
|
+
- JRuby 1.7.9 in Ruby 1.9 mode
|
109
|
+
- Ruby Enterprise Edition 1.8.7 2012.02
|
110
|
+
- Ruby (latest master)
|
111
|
+
- [JRuby](http://jruby.org/) (latest master)
|
112
|
+
- [Rubinius](http://rubini.us/)
|
113
|
+
|
114
|
+
If something doesn't work on one of these Ruby versions, it's a bug.
|
115
|
+
|
116
|
+
This library may inadvertently work (or seem to work) on other Ruby implementations, however support will only be provided for the versions listed above.
|
117
|
+
|
118
|
+
## Contributing
|
119
|
+
|
120
|
+
1. Fork it ( <https://github.com/why404/qiniu-kit/fork> )
|
121
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
122
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
123
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
124
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/qiniu/errors.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Qiniu
|
4
|
+
module Errors
|
5
|
+
|
6
|
+
class JSONDecodeError < StandardError; end
|
7
|
+
|
8
|
+
class NotAnInstanceOfError < StandardError; end
|
9
|
+
|
10
|
+
# Raised when a {Service} is constructed and credentials are not
|
11
|
+
# set, or the set credentials are empty.
|
12
|
+
class MissingCredentialsError < RuntimeError; end
|
13
|
+
|
14
|
+
class MissingArgsError < RuntimeError
|
15
|
+
def initialize(missing_keys)
|
16
|
+
key_list = missing_keys.map {|key| key.to_s}.join(' and the ')
|
17
|
+
super("#{key_list} are required.")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Qiniu
|
7
|
+
module Kit
|
8
|
+
class Mac
|
9
|
+
|
10
|
+
def initialize(access_key, secret_key)
|
11
|
+
@access_key = access_key || Qiniu.config[:access_key]
|
12
|
+
@secret_key = secret_key || Qiniu.config[:secret_key]
|
13
|
+
end
|
14
|
+
|
15
|
+
def hmac_sha1_digest(data)
|
16
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), @secret_key, data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def base64_hmac_sha1_digest(data)
|
20
|
+
return Qiniu::Kit.base64_url_encode(hmac_sha1_digest(data))
|
21
|
+
end
|
22
|
+
|
23
|
+
def sign(data)
|
24
|
+
return %Q(#{@access_key}:#{base64_hmac_sha1_digest(data)})
|
25
|
+
end
|
26
|
+
|
27
|
+
def sign_with_data(data)
|
28
|
+
base64data = Qiniu::Kit.base64_url_encode(data)
|
29
|
+
return %Q(#{sign(base64data)}:#{base64data})
|
30
|
+
end
|
31
|
+
|
32
|
+
def sign_with_request(url, body = nil)
|
33
|
+
uri = URI.parse(url)
|
34
|
+
data = uri.path
|
35
|
+
data += '?' + uri.query if !uri.query.nil? && !uri.query.empty?
|
36
|
+
data += "\n"
|
37
|
+
data += body if !body.nil? && !body.empty?
|
38
|
+
return sign(data)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/qiniu/kit.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require "base64"
|
4
|
+
require "multi_json"
|
5
|
+
|
6
|
+
|
7
|
+
module Qiniu
|
8
|
+
module Kit
|
9
|
+
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def base64_url_encode(str)
|
13
|
+
Base64.encode64(str).tr("+/", "-_").gsub(/[\n\r]?/, "")
|
14
|
+
end
|
15
|
+
|
16
|
+
def base64_url_decode(str)
|
17
|
+
Base64.decode64(str.tr("-_", "+/"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def entry_uri_encode(bucket, key)
|
21
|
+
entry_uri = bucket + ':' + key
|
22
|
+
base64_url_encode(entry_uri)
|
23
|
+
end
|
24
|
+
|
25
|
+
def decode_json(*args)
|
26
|
+
MultiJson.load(*args)
|
27
|
+
rescue MultiJson::LoadError
|
28
|
+
raise Qiniu::JSONDecodeError.new("Invalid segment encoding")
|
29
|
+
end
|
30
|
+
|
31
|
+
def encode_json(*args)
|
32
|
+
MultiJson.dump(*args)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/qiniu-kit.rb
ADDED
data/lib/qiniu.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'qiniu', 'errors.rb')
|
4
|
+
|
5
|
+
module Qiniu
|
6
|
+
|
7
|
+
@config = {}
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
DEFAULT_OPTIONS = {}
|
12
|
+
|
13
|
+
attr_reader :config
|
14
|
+
|
15
|
+
def config=(options)
|
16
|
+
unless Hash === options
|
17
|
+
raise ArgumentError, "configuration object must be a hash"
|
18
|
+
end
|
19
|
+
@config = DEFAULT_OPTIONS.merge(options)
|
20
|
+
akid = ENV["QINIU_ACCESS_KEY"] || @config[:access_key]
|
21
|
+
skid = ENV["QINIU_SECRET_KEY"] || @config[:secret_key]
|
22
|
+
if akid.nil? || akid.empty? || skid.nil? || skid.nil?
|
23
|
+
raise Qiniu::Errors::MissingCredentialsError, "missing :access_key or :secret_key"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/qiniu-kit.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'qiniu/kit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "qiniu-kit"
|
8
|
+
spec.version = Qiniu::Kit::VERSION
|
9
|
+
spec.authors = ["why404"]
|
10
|
+
spec.email = ["awhy.xu@gmail.com"]
|
11
|
+
spec.summary = %q{A collection of helpful methods for debugging Qiniu Cloud Storage API.}
|
12
|
+
spec.description = %q{Qiniu basic for setup other libraries, also can be used independently.}
|
13
|
+
spec.homepage = "https://github.com/why404/qiniu-kit"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "multi_json", "~> 1.8"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
26
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Qiniu::Kit::Mac do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@mac_object = Qiniu::Kit::Mac.new("access_key", "secret_key")
|
9
|
+
@data = 'The quick brown fox jumps over the lazy dog'
|
10
|
+
end
|
11
|
+
|
12
|
+
context '.hmac_sha1_digest' do
|
13
|
+
it 'should works' do
|
14
|
+
@mac_object.hmac_sha1_digest(@data).size.should eq(20)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '.base64_hmac_sha1_digest' do
|
19
|
+
it 'should works' do
|
20
|
+
@mac_object.base64_hmac_sha1_digest(@data).should eq("MuPjQo_SKFFla-gElUbMr6YJ_3M=")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '.sign' do
|
25
|
+
it 'should works' do
|
26
|
+
result = 'access_key:MuPjQo_SKFFla-gElUbMr6YJ_3M='
|
27
|
+
@mac_object.sign(@data).should eq(result)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '.sign_with_data' do
|
32
|
+
it 'should works' do
|
33
|
+
result = 'access_key:o596toAWk5uj15G8YPpEItyWfAk=:VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=='
|
34
|
+
@mac_object.sign_with_data(@data).should eq(result)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context '.sign_with_request' do
|
39
|
+
it 'should works' do
|
40
|
+
url = 'http://foo.com/posts?id=30&limit=5#time=1305298413'
|
41
|
+
body = nil
|
42
|
+
result = 'access_key:rCCViSFht5oGE2oAOakBG62wbJA='
|
43
|
+
@mac_object.sign_with_request(url, body).should eq(result)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Qiniu::Kit do
|
6
|
+
|
7
|
+
it 'should have a version number' do
|
8
|
+
Qiniu::Kit::VERSION.should_not be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'version should be number' do
|
12
|
+
Qiniu::Kit::VERSION.to_s.should =~ /^\d+\.\d+\.\d+?$/
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Qiniu::Kit do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@bucket = 'bucket'
|
9
|
+
@key = 'key'
|
10
|
+
@encoded = 'YnVja2V0OmtleQ=='
|
11
|
+
end
|
12
|
+
|
13
|
+
context '.decode_json' do
|
14
|
+
it 'should works' do
|
15
|
+
Qiniu::Kit.decode_json('{"abc":"def"}').should eq({"abc" => "def"})
|
16
|
+
Qiniu::Kit.decode_json('{"abc":"def"}', :symbolize_keys => true).should eq({:abc => "def"})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '.encode_json' do
|
21
|
+
it 'should works' do
|
22
|
+
Qiniu::Kit.encode_json({:abc => 'def'}).should eq('{"abc":"def"}')
|
23
|
+
if RUBY_VERSION >= "1.9"
|
24
|
+
Qiniu::Kit.encode_json({:abc => 'def'}, :pretty => true).should eq("{\n \"abc\": \"def\"\n}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '.base64_url_encode' do
|
30
|
+
it 'should works' do
|
31
|
+
Qiniu::Kit.base64_url_encode("#{@bucket}:#{@key}").should eq(@encoded)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context '.base64_url_decode' do
|
36
|
+
it 'should works' do
|
37
|
+
Qiniu::Kit.base64_url_decode(@encoded).should eq("#{@bucket}:#{@key}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context '.entry_uri_encode' do
|
42
|
+
it 'should works' do
|
43
|
+
Qiniu::Kit.entry_uri_encode(@bucket, @key).should eq(@encoded)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'qiniu-kit'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.before :all do
|
7
|
+
Qiniu.config = {
|
8
|
+
:access_key => ENV["QINIU_ACCESS_KEY"],
|
9
|
+
:secret_key => ENV["QINIU_SECRET_KEY"]
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'coveralls'
|
15
|
+
Coveralls.wear!
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qiniu-kit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- why404
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
description: Qiniu basic for setup other libraries, also can be used independently.
|
70
|
+
email:
|
71
|
+
- awhy.xu@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/qiniu-kit.rb
|
84
|
+
- lib/qiniu.rb
|
85
|
+
- lib/qiniu/errors.rb
|
86
|
+
- lib/qiniu/kit.rb
|
87
|
+
- lib/qiniu/kit/mac.rb
|
88
|
+
- lib/qiniu/kit/version.rb
|
89
|
+
- qiniu-kit.gemspec
|
90
|
+
- spec/qiniu/kit/mac_spec.rb
|
91
|
+
- spec/qiniu/kit/version_spec.rb
|
92
|
+
- spec/qiniu/kit_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
homepage: https://github.com/why404/qiniu-kit
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.2.2
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: A collection of helpful methods for debugging Qiniu Cloud Storage API.
|
118
|
+
test_files:
|
119
|
+
- spec/qiniu/kit/mac_spec.rb
|
120
|
+
- spec/qiniu/kit/version_spec.rb
|
121
|
+
- spec/qiniu/kit_spec.rb
|
122
|
+
- spec/spec_helper.rb
|