aliyunoss 0.2.0 → 0.2.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 +4 -4
- data/lib/aliyunoss/bucket.rb +41 -3
- data/lib/aliyunoss/version.rb +1 -1
- data/spec/aliyunoss/bucket_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c22926d8762b8b4bf376899763a30ec4be2f719a4f304eb29012331d216c4a07
|
4
|
+
data.tar.gz: b08fd3ba38eadc4c6813b074113e9e2ae4356e41236f19e961b4150c4993abf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f068b547a30385271f91d3f955d47a604f7ed622527d158d50cd659348243910fe0e2c7345ad481240a967846d90eea61d6cdf533537b6b4b3d0e8ec354780f
|
7
|
+
data.tar.gz: e2cec40d40c0e8037755f1cadcdecb2c86652e376169901812feea4882eea0a50b15cba7542056255a3ec2dbb663f77c90b21339b277cd69e8eee07d61ecc47b
|
data/lib/aliyunoss/bucket.rb
CHANGED
@@ -45,9 +45,40 @@ module Aliyun
|
|
45
45
|
# Download file from remote server
|
46
46
|
#
|
47
47
|
def download(path, options = {})
|
48
|
-
Aliyun::Oss::API.get_object(self, path, options)
|
49
|
-
|
50
|
-
.body
|
48
|
+
response = Aliyun::Oss::API.get_object(self, path, options)
|
49
|
+
if response.code.to_i >= 200 and response.code.to_i < 300
|
50
|
+
response.body
|
51
|
+
else
|
52
|
+
raise OssException.new(response)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Get file info
|
58
|
+
#
|
59
|
+
def get_file_info(path)
|
60
|
+
hash = Hash.new
|
61
|
+
Aliyun::Oss::API.head_object(self, path).raise_unless(Net::HTTPOK).each_header do |k,v|
|
62
|
+
hash[k] = v
|
63
|
+
end
|
64
|
+
hash
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Test if a file exist
|
69
|
+
# return true/false
|
70
|
+
#
|
71
|
+
def exist?(path)
|
72
|
+
begin
|
73
|
+
Aliyun::Oss::API.head_object(self, path).raise_unless(Net::HTTPOK)
|
74
|
+
true
|
75
|
+
rescue OssException => ex
|
76
|
+
if (ex.message.include? 'Net::HTTPNotFound')
|
77
|
+
false
|
78
|
+
else
|
79
|
+
raise ex
|
80
|
+
end
|
81
|
+
end
|
51
82
|
end
|
52
83
|
|
53
84
|
#
|
@@ -57,6 +88,13 @@ module Aliyun
|
|
57
88
|
Aliyun::Oss::API.generate_share_url(self, path, expires_in)
|
58
89
|
end
|
59
90
|
|
91
|
+
#
|
92
|
+
# Generate public url for path
|
93
|
+
#
|
94
|
+
def public_url(path)
|
95
|
+
"https://#{name}.#{location}.aliyuncs.com#{path}"
|
96
|
+
end
|
97
|
+
|
60
98
|
#
|
61
99
|
# Delete remote file
|
62
100
|
#
|
data/lib/aliyunoss/version.rb
CHANGED
@@ -72,6 +72,26 @@ describe Aliyun::Oss::Bucket do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
it 'get file info from server' do
|
76
|
+
path = '/test-1.png'
|
77
|
+
file_info = @bucket.get_file_info(path)
|
78
|
+
expect(file_info['server']).to eq('AliyunOSS')
|
79
|
+
expect(file_info['content-length']).to eq('127759')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'cannot get file info if file not existed' do
|
83
|
+
path = '/test-8.png'
|
84
|
+
expect(@bucket.exist?(path)).to be false
|
85
|
+
|
86
|
+
path = '/test-3.png'
|
87
|
+
expect(@bucket.exist?(path)).to be true
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'get public url for file' do
|
91
|
+
path = '/test-3.png'
|
92
|
+
expect(@bucket.public_url(path)).to eq("https://#{@bucket_name}.oss-cn-beijing.aliyuncs.com/test-3.png")
|
93
|
+
end
|
94
|
+
|
75
95
|
it 'should delete file on server' do
|
76
96
|
['/test-1.png','/test-2.png','/test-3.png', '/multi-part-test.dat', '/multi-part-copy.dat'].each do |path|
|
77
97
|
@bucket.delete(path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyunoss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yijiecc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|