ross 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/lib/ross.rb +3 -0
- data/lib/ross/client.rb +51 -0
- data/ross.gemspec +12 -0
- metadata +83 -0
data/README.md
ADDED
data/lib/ross.rb
ADDED
data/lib/ross/client.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module ROSS
|
5
|
+
class Client
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
return nil unless options
|
9
|
+
@bucket_name = options[:bucket_name]
|
10
|
+
@appid = options[:appid]
|
11
|
+
@appkey = options[:appkey]
|
12
|
+
@aliyun_host = "oss.aliyuncs.com"
|
13
|
+
if options[:aliyun_internal] == true
|
14
|
+
@aliyun_host = "oss-internal.aliyuncs.com"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def put(path, file, options={})
|
19
|
+
content_md5 = Digest::MD5.hexdigest(file)
|
20
|
+
content_type = options[:content_type] || "image/jpg"
|
21
|
+
date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
22
|
+
path = "#{@bucket_name}/#{path}"
|
23
|
+
url = "http://#{@aliyun_host}/#{path}"
|
24
|
+
auth_sign = sign("PUT", path, content_md5, content_type, date)
|
25
|
+
headers = {
|
26
|
+
"Authorization" => auth_sign,
|
27
|
+
"Content-Type" => content_type,
|
28
|
+
"Content-Length" => file.length,
|
29
|
+
"Date" => date,
|
30
|
+
"Host" => @aliyun_host,
|
31
|
+
}
|
32
|
+
|
33
|
+
response = RestClient.put(url, file, headers)
|
34
|
+
end
|
35
|
+
|
36
|
+
def get(path)
|
37
|
+
return "http://#{@bucket_name}.#{@aliyun_host}/#{path}"
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def sign(verb, path, content_md5, content_type, date)
|
42
|
+
canonicalized_oss_headers = ''
|
43
|
+
canonicalized_resource = "/#{path}"
|
44
|
+
string_to_sign = "#{verb}\n\n#{content_type}\n#{date}\n#{canonicalized_oss_headers}#{canonicalized_resource}"
|
45
|
+
digest = OpenSSL::Digest::Digest.new('sha1')
|
46
|
+
h = OpenSSL::HMAC.digest(digest, @appkey, string_to_sign)
|
47
|
+
h = Base64.encode64(h)
|
48
|
+
"OSS #{@appid}:#{h}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/ross.gemspec
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'ross'
|
4
|
+
s.version = '0.0.1'
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.summary = "ROSS is a ruby client for aliyun oss"
|
7
|
+
s.authors = ["Fizz Wu"]
|
8
|
+
s.email = "fizzwu@gmail.com"
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
|
11
|
+
s.add_dependency("rest-client", ">=1.6.0")
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ross
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Fizz Wu
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-01-16 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rest-client
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 6
|
32
|
+
- 0
|
33
|
+
version: 1.6.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description:
|
37
|
+
email: fizzwu@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- README.md
|
46
|
+
- lib/ross.rb
|
47
|
+
- lib/ross/client.rb
|
48
|
+
- ross.gemspec
|
49
|
+
homepage:
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.24
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: ROSS is a ruby client for aliyun oss
|
82
|
+
test_files: []
|
83
|
+
|