upyun 1.0.7 → 1.0.8
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/CHANGELOG.md +3 -0
- data/README.md +2 -2
- data/lib/upyun/rest.rb +3 -0
- data/lib/upyun/version.rb +1 -1
- data/spec/upyun_spec.rb +125 -8
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0e0c04999244534cf121c344eac1cbb059e3d06
|
|
4
|
+
data.tar.gz: 6c0f41e3d546ff7427e163da6fcf9c39ea244de4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7e6d5b2263b1cf97ead353bbaf218ea71a7c68d6557b6a19ace4ee5af1de616b7aa2226a8cddfb2e97410f0e7cd2ebde034f35195ead9c1930966e6488f0413f
|
|
7
|
+
data.tar.gz: a316cabb91311c7fb843a2a16c3bb0620f8506134120e00c3965c4166f46b9a42034daa7a6ebd8365d07fd8c6a5f2d8e7e7f0dca48623fad2fc37a4cae3da4c4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
在 `Gemfile` 中加入以下代码
|
|
14
14
|
|
|
15
15
|
```ruby
|
|
16
|
-
gem 'upyun', '~> 1.0.
|
|
16
|
+
gem 'upyun', '~> 1.0.8'
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
然后执行如下命令安装:
|
|
@@ -300,7 +300,7 @@ upyun.upload(File.new('filepath.png'))
|
|
|
300
300
|
|
|
301
301
|
```ruby
|
|
302
302
|
opts = {
|
|
303
|
-
'
|
|
303
|
+
'save-key' => '/foo/bar.jpg',
|
|
304
304
|
'content-type' => 'image/jpeg',
|
|
305
305
|
'image-width-range' => '0,1024',
|
|
306
306
|
'return-url' => 'http://www.example.com'
|
data/lib/upyun/rest.rb
CHANGED
|
@@ -98,6 +98,9 @@ module Upyun
|
|
|
98
98
|
|
|
99
99
|
def fullpath(path)
|
|
100
100
|
decoded = URI::encode(URI::decode(path.to_s.force_encoding('utf-8')))
|
|
101
|
+
|
|
102
|
+
# URI::encode did not encode '[]'
|
|
103
|
+
decoded = decoded.gsub('[', '%5B').gsub(']', '%5D')
|
|
101
104
|
"/#{@bucket}#{decoded.start_with?('/') ? decoded : '/' + decoded}"
|
|
102
105
|
end
|
|
103
106
|
|
data/lib/upyun/version.rb
CHANGED
data/spec/upyun_spec.rb
CHANGED
|
@@ -26,25 +26,36 @@ describe "Upyun Restful API Basic testing" do
|
|
|
26
26
|
describe ".put" do
|
|
27
27
|
before { @path = "/ruby-sdk/foo/#{String.random}/test.jpg" }
|
|
28
28
|
|
|
29
|
-
it "PUT
|
|
30
|
-
|
|
29
|
+
it "PUT an image should return image information" do
|
|
30
|
+
metas = @upyun.put(@path, File.new(@file, 'rb'))
|
|
31
|
+
expect(metas).to include(:width, :height, :frames, :file_type)
|
|
32
|
+
expect(metas[:width].is_a?(Integer))
|
|
33
|
+
expect(metas[:height].is_a?(Integer))
|
|
34
|
+
expect(metas[:frames].is_a?(Integer))
|
|
35
|
+
expect(metas[:file_type].is_a?(String))
|
|
31
36
|
end
|
|
32
37
|
|
|
33
|
-
it "PUT a binary string" do
|
|
38
|
+
it "PUT a binary string should return no more information" do
|
|
34
39
|
expect(@upyun.put(@path, @str)).to be true
|
|
35
40
|
end
|
|
36
41
|
|
|
37
|
-
it "PUT with some extra
|
|
42
|
+
it "PUT with some extra headers" do
|
|
38
43
|
headers = {
|
|
39
44
|
'Contetn-type' => 'image/jpeg',
|
|
40
45
|
'x-gmkerl-type' => 'fix_width',
|
|
41
46
|
'x-gmkerl-value' => 42,
|
|
42
47
|
'x-gmkerl-unsharp' => true
|
|
43
48
|
}
|
|
44
|
-
|
|
49
|
+
metas = @upyun.put(@path, File.new(@file, 'rb'), headers)
|
|
50
|
+
|
|
51
|
+
expect(metas).to include(:width, :height, :frames, :file_type)
|
|
52
|
+
expect(metas[:width].is_a?(Integer))
|
|
53
|
+
expect(metas[:height].is_a?(Integer))
|
|
54
|
+
expect(metas[:frames].is_a?(Integer))
|
|
55
|
+
expect(metas[:file_type].is_a?(String))
|
|
45
56
|
end
|
|
46
57
|
|
|
47
|
-
describe "PUT
|
|
58
|
+
describe "PUT in Chinese path" do
|
|
48
59
|
before(:all) { @path_cn = '/ruby-sdk/foo/这是中文路径/foo.txt' }
|
|
49
60
|
|
|
50
61
|
it "should success" do
|
|
@@ -59,10 +70,110 @@ describe "Upyun Restful API Basic testing" do
|
|
|
59
70
|
expect(@upyun.get(URI.encode(@path_cn))).to eq(@str)
|
|
60
71
|
end
|
|
61
72
|
|
|
73
|
+
it "after all, delete should success" do
|
|
74
|
+
expect(@upyun.delete(@path_cn)).to be true
|
|
75
|
+
end
|
|
76
|
+
|
|
62
77
|
after(:all) { @upyun.delete(@path_cn) }
|
|
63
78
|
end
|
|
64
79
|
|
|
65
|
-
|
|
80
|
+
describe "PUT with '%2B' encoded url path" do
|
|
81
|
+
before(:all) do
|
|
82
|
+
@path_2b = '/ruby-sdk/foo/%2B/foo.txt'
|
|
83
|
+
@str_2b = 'This is 2b string binary.'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "shoud success" do
|
|
87
|
+
expect(@upyun.put(@path_2b, @str_2b)).to be true
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "then get the same url should also success" do
|
|
91
|
+
expect(@upyun.get(@path_2b)).to eq(@str_2b)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "then get replaced('%2B' -> '+') should also success" do
|
|
95
|
+
expect(@upyun.get(@path_2b.gsub("%2B", "+"))).to eq(@str_2b)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "after all, delete should success" do
|
|
99
|
+
expect(@upyun.delete(@path_2b)).to be true
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
after(:all) { @upyun.delete(@path_2b) }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe "PUT with '+' encoded url path" do
|
|
106
|
+
before(:all) do
|
|
107
|
+
@path_plus = '/ruby-sdk/foo/+/foo.txt'
|
|
108
|
+
@str_plus = 'This is plus string.'
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "should success" do
|
|
112
|
+
expect(@upyun.put(@path_plus, @str_plus)).to be true
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "then get the same url should also success" do
|
|
116
|
+
expect(@upyun.get(@path_plus)).to eq(@str_plus)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "then get replaced('+' -> '%2B') should also success" do
|
|
120
|
+
expect(@upyun.get(@path_plus.gsub("+", "%2B"))).to eq(@str_plus)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "after all, delete should success" do
|
|
124
|
+
expect(@upyun.delete(@path_plus)).to be true
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
after(:all) { @upyun.delete(@path_plus) }
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe "PUT with '%20' encoded url path" do
|
|
131
|
+
before(:all) do
|
|
132
|
+
@path_20 = '/ruby-sdk/bar/%20/foo.txt'
|
|
133
|
+
@str_20 = 'This is %20 string.'
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should success" do
|
|
137
|
+
expect(@upyun.put(@path_20, @str_20)).to be true
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "then get the same url should also success" do
|
|
141
|
+
expect(@upyun.get(@path_20)).to eq(@str_20)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "then get replaced('%20' -> ' ') should also success" do
|
|
145
|
+
expect(@upyun.get(@path_20.gsub("%20", " "))).to eq(@str_20)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "after all, delete should success" do
|
|
149
|
+
expect(@upyun.delete(@path_20)).to be true
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
after(:all) { @upyun.delete(@path_20) }
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
describe "PUT with '[{}]' encoded url path" do
|
|
156
|
+
before(:all) do
|
|
157
|
+
@path_sq = '/ruby-sdk/bar/[f{o]/}o.txt'
|
|
158
|
+
@str_sq = 'This is %sq string.'
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "should success" do
|
|
162
|
+
expect(@upyun.put(@path_sq, @str_sq)).to be true
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "then get the same url should also success" do
|
|
166
|
+
expect(@upyun.get(@path_sq)).to eq(@str_sq)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "after all, delete should success" do
|
|
170
|
+
expect(@upyun.delete(@path_sq)).to be true
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
after(:all) { @upyun.delete(@path_sq) }
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "Put a file to PICTURE bucket should return the image's metadata" do
|
|
66
177
|
upyunp = Upyun::Rest.new('sdkimg', 'tester', 'grjxv2mxELR3', {}, Upyun::ED_TELECOM)
|
|
67
178
|
metas = upyunp.put(@path, File.new(@file), content_type: 'image/jpeg')
|
|
68
179
|
expect(metas).to include(:width, :height, :frames, :file_type)
|
|
@@ -208,9 +319,15 @@ describe "Form Upload", current: true do
|
|
|
208
319
|
expect(res.keys).to include(:code, :message, :url, :time)
|
|
209
320
|
expect(res[:code]).to eq(200)
|
|
210
321
|
expect(res[:message]).to match(/ok/)
|
|
322
|
+
expect(res[:url]).to eq(Time.now.utc.strftime('/%Y/%m/%d/upyun.jpg'))
|
|
211
323
|
expect(fd.closed?).to eq(true)
|
|
212
324
|
end
|
|
213
325
|
|
|
326
|
+
it "with default 'save-key' should return '%Y/%m/%d/{filename}{.suffix}'" do
|
|
327
|
+
res = @form.upload(@file)
|
|
328
|
+
expect(res[:url]).to eq(Time.now.utc.strftime('/%Y/%m/%d/upyun.jpg'))
|
|
329
|
+
end
|
|
330
|
+
|
|
214
331
|
it "set 'save-key' should success" do
|
|
215
332
|
res = @form.upload(@file, {'save-key' => 'name-ed keypath'})
|
|
216
333
|
expect(res[:code]).to eq(200)
|
|
@@ -223,7 +340,7 @@ describe "Form Upload", current: true do
|
|
|
223
340
|
expect(res[:message]).to match(/Authorize has expired/)
|
|
224
341
|
end
|
|
225
342
|
|
|
226
|
-
it "set 'return-url' should a hash" do
|
|
343
|
+
it "set 'return-url' should return a hash" do
|
|
227
344
|
res = @form.upload(@file, {'return-url' => 'http://www.example.com'})
|
|
228
345
|
expect(res).to be_instance_of(Hash)
|
|
229
346
|
expect(res[:code]).to eq(200)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: upyun
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- jsvisa
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-client
|