better_ross 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bd5229956ac747ed97eb419b6e2fd06410ac1de
4
+ data.tar.gz: 189da9e09daed17ad79547d3255fdb037e242676
5
+ SHA512:
6
+ metadata.gz: 0e7a980b431d511a1fd12296bc254977163977c9f0fd3dcae96d20dfb24a48543c5364174687e138f9beebc67c035b82ca929ed16d1841240a881cbf7b659f09
7
+ data.tar.gz: 848715fcc9dc36c6495397641d943eb1d14b61e1995af53fe3d5bbee939790a54d4dd5a4c3044d5bfd894d900bdcb648b7363cc3decb15c4d97994c7c1706393
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ross
2
+ ====
3
+
4
+ a ruby client for aliyun oss
data/lib/ross.rb ADDED
@@ -0,0 +1,3 @@
1
+ module ROSS; end
2
+
3
+ require 'ross/client.rb'
@@ -0,0 +1,68 @@
1
+ # coding: utf-8
2
+ require 'rest-client'
3
+ require 'base64'
4
+
5
+ module ROSS
6
+ class Client
7
+
8
+ def initialize(options)
9
+ return nil unless options
10
+ @bucket_name = options[:bucket_name]
11
+ @appid = options[:appid]
12
+ @appkey = options[:appkey]
13
+ @aliyun_host = options[:bucket_host] || "oss.aliyuncs.com"
14
+ if options[:aliyun_internal] == true
15
+ @aliyun_host = "oss-internal.aliyuncs.com"
16
+ end
17
+ end
18
+
19
+ def put(path, content, options={})
20
+ # content_md5 = Digest::MD5.hexdigest(content)
21
+ content_type = options[:content_type] || "application/octet-stream"
22
+ date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
23
+ auth_sign = sign("PUT", path, date, content_type) #, content_md5)
24
+ headers = {
25
+ "Authorization" => "OSS #{@appid}:#{auth_sign}",
26
+ "Content-Type" => content_type,
27
+ "Content-Length" => content.length,
28
+ "Date" => date,
29
+ "Host" => @aliyun_host,
30
+ }
31
+ response = RestClient.put(request_url(path), content, headers)
32
+ end
33
+
34
+ def put_file(path, file, options = {})
35
+ put(path, File.read(file), options)
36
+ end
37
+
38
+ def public_url(path)
39
+ "http://#{@bucket_name}.#{@aliyun_host}/#{path}"
40
+ end
41
+
42
+ alias :get :public_url
43
+
44
+ def private_url(path, expires_in = 3600)
45
+ expires_at = (8*3600 + Time.now.gmtime.to_i) + expires_in
46
+ params = {
47
+ 'Expires' => expires_at,
48
+ 'OSSAccessKeyId' => @appid,
49
+ 'Signature' => sign('GET', path, expires_at)
50
+ }
51
+ public_url(path) + '?' + URI.encode_www_form(params)
52
+ end
53
+
54
+ private
55
+ def sign(verb, path, date, content_type = nil, content_md5 = nil)
56
+ canonicalized_oss_headers = ''
57
+ canonicalized_resource = "/#{@bucket_name}/#{path.gsub(/^\//, '')}"
58
+ string_to_sign = "#{verb}\n\n#{content_type}\n#{date}\n#{canonicalized_oss_headers}#{canonicalized_resource}"
59
+ digest = OpenSSL::Digest.new('sha1')
60
+ h = OpenSSL::HMAC.digest(digest, @appkey, string_to_sign)
61
+ Base64.encode64(h).strip
62
+ end
63
+
64
+ def request_url(path)
65
+ "http://#{@aliyun_host}/#{@bucket_name}/#{path}"
66
+ end
67
+ end
68
+ end
data/ross.gemspec ADDED
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |s|
3
+ s.name = 'better_ross'
4
+ s.version = '0.0.2'
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,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_ross
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Fizz Wu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0
27
+ description:
28
+ email: fizzwu@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/ross.rb
35
+ - lib/ross/client.rb
36
+ - ross.gemspec
37
+ homepage:
38
+ licenses: []
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.2.2
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: ROSS is a ruby client for aliyun oss
60
+ test_files: []