better_ross 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ross/client.rb +38 -9
  3. data/ross.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a13f14d3ce2844aa823e8d7a4014f659561a326
4
- data.tar.gz: fa02613618b59a88abee6a864c09b7445e6c8f9f
3
+ metadata.gz: f1f1d2390671663b426392fce34c982614ce9110
4
+ data.tar.gz: a94351861b7ed3b6bd668f02a35ac03e35f2d39c
5
5
  SHA512:
6
- metadata.gz: b145fb3260c5258eacc5e0ec4540c43070c4e1d248b6513adf0759689b0de1c8c52a98d6f797fce33dcd6d69e238ab76a763e7ca73f97fe84f21d93448a2157c
7
- data.tar.gz: a4b7d45a67939038b9ba0892cf96dbe85f7fedd11137bf37bf44737d389b643d0de664e80f3b2acc8186a80b6d2209198f284fe9d3bd1cb6a14afb7f9f560abf
6
+ metadata.gz: 0e04beaec8462b1ade61b1b7ccbfb7cdfd58863ab3ce5d68df70cdd66b1f6120f6f6997e5dbf7641da28d387b2e2e1931f8747afdf269d67be61b5bc067a5d8b
7
+ data.tar.gz: 73b092e5b364abba6aeb95b0a205655465a5273b8cff0bb4588eec4eea278034d37b1b4d3cb91df59f619f1a784351c8fcc0a627794b304ac406693aa692eb52
data/lib/ross/client.rb CHANGED
@@ -16,21 +16,42 @@ module ROSS
16
16
  end
17
17
  end
18
18
 
19
- def put(path, content, options={})
19
+ def put(path, content, options={}, xoss = {})
20
20
  # content_md5 = Digest::MD5.hexdigest(content)
21
- content_type = options[:content_type] || "application/octet-stream"
21
+ content_type = options.has_key?(:content_type) ? options[:content_type] : "application/octet-stream"
22
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
23
  headers = {
25
- "Authorization" => "OSS #{@appid}:#{auth_sign}",
24
+ "Authorization" => auth_sign("PUT", path, date, content_type, nil, xoss),
26
25
  "Content-Type" => content_type,
27
- "Content-Length" => content.length,
28
26
  "Date" => date,
29
- "Host" => @aliyun_host,
27
+ "Host" => @aliyun_host
30
28
  }
29
+ headers["Content-Length"] = content.length unless content.nil? # content can be nil
30
+ xoss.each_pair{|k,v| headers["x-oss-#{k}"] = v }
31
31
  response = RestClient.put(request_url(path), content, headers)
32
32
  end
33
33
 
34
+ def delete(path)
35
+ date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
36
+ content_type = nil
37
+ headers = {
38
+ "Authorization" => auth_sign("DELETE", path, date, content_type),
39
+ "Content-Type" => content_type,
40
+ "Date" => date,
41
+ "Host" => @aliyun_host
42
+ }
43
+ RestClient.delete(request_url(path), headers)
44
+ end
45
+
46
+ def copy(sour_path, dest_path)
47
+ put(dest_path, nil, {content_type: nil}, {'copy-source' => bucket_path(sour_path)})
48
+ end
49
+
50
+ def rename(sour_path, dest_path)
51
+ copy(sour_path, dest_path)
52
+ delete(path)
53
+ end
54
+
34
55
  def put_file(path, file, options = {})
35
56
  put(path, File.read(file), options)
36
57
  end
@@ -52,15 +73,23 @@ module ROSS
52
73
  end
53
74
 
54
75
  private
55
- def sign(verb, path, date, content_type = nil, content_md5 = nil)
56
- canonicalized_oss_headers = ''
57
- canonicalized_resource = "/#{@bucket_name}/#{path.gsub(/^\//, '')}"
76
+ def sign(verb, path, date, content_type = nil, content_md5 = nil, xoss = {})
77
+ canonicalized_oss_headers = xoss.sort.map{|k,v| "x-oss-#{k}:".downcase + v + "\n"}.join
78
+ canonicalized_resource = bucket_path(path)
58
79
  string_to_sign = "#{verb}\n\n#{content_type}\n#{date}\n#{canonicalized_oss_headers}#{canonicalized_resource}"
59
80
  digest = OpenSSL::Digest.new('sha1')
60
81
  h = OpenSSL::HMAC.digest(digest, @appkey, string_to_sign)
61
82
  Base64.encode64(h).strip
62
83
  end
63
84
 
85
+ def auth_sign(verb, path, date, content_type = nil, content_md5 = nil, xoss = {})
86
+ "OSS #{@appid}:#{sign(verb, path, date, content_type, content_md5, xoss)}"
87
+ end
88
+
89
+ def bucket_path(path)
90
+ "/#{@bucket_name}/#{path.gsub(/^\//, '')}"
91
+ end
92
+
64
93
  def request_url(path)
65
94
  "http://#{@aliyun_host}/#{@bucket_name}/#{URI.encode(path)}"
66
95
  end
data/ross.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'better_ross'
4
- s.version = '0.0.3'
4
+ s.version = '0.0.4'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.summary = "ROSS is a ruby client for aliyun oss"
7
7
  s.authors = ["Fizz Wu"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_ross
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fizz Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-27 00:00:00.000000000 Z
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client