upyun 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ede2802f726646a9e884163947fd0deb0bda7bb
4
- data.tar.gz: ffd7837ffa0dd88cf1f204fe10a95eb91a9c3ad3
3
+ metadata.gz: a0e0c04999244534cf121c344eac1cbb059e3d06
4
+ data.tar.gz: 6c0f41e3d546ff7427e163da6fcf9c39ea244de4
5
5
  SHA512:
6
- metadata.gz: 722d70c68fbd1e73efd3cf4b7361e4290715902fc28a4d949bd5f2e39eb4d0de3d58e016c7c954fcee3daef1eee4af9d760efbaafc983752aa8481ec66aaa637
7
- data.tar.gz: 895bccf056eac1f6e35314dca90c297e4cfbdb1561c274300d35e2d7aaa296bb0de4541e5c37f6bccd8350c1563e470d06b27737991fb79eafdde87a21818f11
6
+ metadata.gz: 7e6d5b2263b1cf97ead353bbaf218ea71a7c68d6557b6a19ace4ee5af1de616b7aa2226a8cddfb2e97410f0e7cd2ebde034f35195ead9c1930966e6488f0413f
7
+ data.tar.gz: a316cabb91311c7fb843a2a16c3bb0620f8506134120e00c3965c4166f46b9a42034daa7a6ebd8365d07fd8c6a5f2d8e7e7f0dca48623fad2fc37a4cae3da4c4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## CHANGE LOG
2
2
 
3
+ ### v1.0.8
4
+ - URI encode '[]'
5
+
3
6
  ### v1.0.7
4
7
  - 表单上传返回的信息不论是否设置了 `return-url`, 返回信息一致
5
8
 
data/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  在 `Gemfile` 中加入以下代码
14
14
 
15
15
  ```ruby
16
- gem 'upyun', '~> 1.0.5'
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
- 'save_key' => '/foo/bar.jpg',
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
@@ -1,3 +1,3 @@
1
1
  module Upyun
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
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 a file" do
30
- expect(@upyun.put(@path, File.new(@file, 'rb'))).to be true
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 process headers" do
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
- expect(@upyun.put(@path, File.new(@file, 'rb'), headers)).to be true
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 while the path is not encoded" do
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
- it "put a file to Picture bucket should return the image's metadata" do
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.7
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-04-09 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client