aliyunoss 0.1.5 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 876577d1a38f9218bd4951ff2edf9ea9ea4fd679e7d60bfb6f32308821090df4
4
- data.tar.gz: 6d152c72f42350eb65698504e94be2275432a0017a853271acb649892592e9df
3
+ metadata.gz: c1ab6499245a17d4022343848dea9974e95309a5748eb230ed4e576cf9239e96
4
+ data.tar.gz: 6d353d67e14ebab41f7465961b02984280aa1cac08d89a2a422decd6aadfac65
5
5
  SHA512:
6
- metadata.gz: d7d29ed290b1fc7fe49d5c64e7033e10b9a51371a61d5c374e5c6e46ce6edb4457c4201930e3598b9ba397f1770f4b59824cfdcfe223fbd526c9c618ba099253
7
- data.tar.gz: 0f59b16131f8d43b2f361f3c8836daedf063e4df030990e4db05c109893cf4f0e7d47807dbfb99502d15e3fea90b47f34f43ebdadf71a2f2cb2ea7c81b40c84f
6
+ metadata.gz: d89365a0762d01cadbee4fea9e9aca18674d49d8bd4c76bc9597dff91415f0b22a4967fae8f4f1b82f9021d543671612a007e648763ed4293689ca38f4a98fc4
7
+ data.tar.gz: 77d5136397e45db437cfecd604e0dc2208ced0d178c1e81f17d0072796881ab7639673ca53ca5465874c753773ce3630ab61ef4b3876dbba086eb95d80fcf67a
@@ -50,6 +50,34 @@ module Aliyun
50
50
  .body
51
51
  end
52
52
 
53
+ #
54
+ # Get file info
55
+ #
56
+ def get_file_info(path)
57
+ hash = Hash.new
58
+ Aliyun::Oss::API.head_object(self, path).raise_unless(Net::HTTPOK).each_header do |k,v|
59
+ hash[k] = v
60
+ end
61
+ hash
62
+ end
63
+
64
+ #
65
+ # Test if a file exist
66
+ # return true/false
67
+ #
68
+ def exist?(path)
69
+ begin
70
+ Aliyun::Oss::API.head_object(self, path).raise_unless(Net::HTTPOK)
71
+ true
72
+ rescue OssException => ex
73
+ if (ex.message.include? 'Net::HTTPNotFound')
74
+ false
75
+ else
76
+ raise ex
77
+ end
78
+ end
79
+ end
80
+
53
81
  #
54
82
  # Generate a url that can be shared to others
55
83
  #
@@ -57,6 +85,13 @@ module Aliyun
57
85
  Aliyun::Oss::API.generate_share_url(self, path, expires_in)
58
86
  end
59
87
 
88
+ #
89
+ # Generate public url for path
90
+ #
91
+ def public_url(path)
92
+ "https://#{name}.#{location}.aliyuncs.com#{path}"
93
+ end
94
+
60
95
  #
61
96
  # Delete remote file
62
97
  #
@@ -26,12 +26,12 @@ module Aliyun
26
26
  #
27
27
  def get_uri
28
28
  if @domain
29
- uri = URI("http://#{domain}/")
29
+ uri = URI("https://#{domain}/")
30
30
  else
31
31
  if @bucket
32
- uri = URI("http://#{bucket.name}.#{bucket.location}.#{host}")
32
+ uri = URI("https://#{bucket.name}.#{bucket.location}.#{host}")
33
33
  else
34
- uri = URI("http://oss.#{host}")
34
+ uri = URI("https://oss.#{host}")
35
35
  end
36
36
  end
37
37
  uri.path = @path
@@ -60,7 +60,7 @@ module Aliyun
60
60
  logger.info(verb.to_s.upcase + ' ' + uri.to_s + ' ' + request.to_hash.to_s)
61
61
 
62
62
  response = nil
63
- Net::HTTP.start(uri.host, uri.port) do |http|
63
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
64
64
  response = http.request(request)
65
65
  logger.info(response.code.to_s + ' ' + response.message)
66
66
  end
@@ -1,5 +1,5 @@
1
1
  module Aliyun
2
2
  module Oss
3
- VERSION = "0.1.5"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -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)
@@ -16,7 +16,7 @@ describe 'Aliyun::Oss Configuration' do
16
16
  end
17
17
 
18
18
  it 'should accept configuration from #configure' do
19
- url = "http://bucket_name.region.aliyuncs.com"
19
+ url = "https://bucket_name.region.aliyuncs.com"
20
20
  access_key = "access_key_from_aliyun"
21
21
  Aliyun::Oss.configure(:access_key_id => access_key, :not_used_para => "not used")
22
22
  config = Aliyun::Oss.config
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.1.5
4
+ version: 0.2.1
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-17 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri