upyun 1.0.6 → 1.0.7

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: 5a66fd1986e039bfa120d3ce923ab1809edd6c5a
4
- data.tar.gz: cec146d124a0257d94540c4b23001d56b9589402
3
+ metadata.gz: 7ede2802f726646a9e884163947fd0deb0bda7bb
4
+ data.tar.gz: ffd7837ffa0dd88cf1f204fe10a95eb91a9c3ad3
5
5
  SHA512:
6
- metadata.gz: d8397e0d383e03a1574f47ed5ef1b18ce92ccc5b4ff3da243791b5dad47491c38136bbee8bf2adfcbb454ab6d743befb84c90b1535a19ce37db747e13aeb4f8e
7
- data.tar.gz: 2760c52be9fb2be54d320c9b7064febc600163c98e888b6e47803b015670d4ad6d263a5c13838b520106a3a1e07ad5af526c629fcfd9227aa3d2a271aa48dedc
6
+ metadata.gz: 722d70c68fbd1e73efd3cf4b7361e4290715902fc28a4d949bd5f2e39eb4d0de3d58e016c7c954fcee3daef1eee4af9d760efbaafc983752aa8481ec66aaa637
7
+ data.tar.gz: 895bccf056eac1f6e35314dca90c297e4cfbdb1561c274300d35e2d7aaa296bb0de4541e5c37f6bccd8350c1563e470d06b27737991fb79eafdde87a21818f11
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## CHANGE LOG
2
2
 
3
+ ### v1.0.7
4
+ - 表单上传返回的信息不论是否设置了 `return-url`, 返回信息一致
5
+
3
6
  ### v1.0.5
4
7
  - GET 请求支持自定义 Headers
5
8
  - 修正 Readme 说明
data/README.md CHANGED
@@ -104,7 +104,7 @@ upyun.put('/save/to/path', 'file or binary', headers)
104
104
 
105
105
  失败返回一个 `Hash` 结构: `{request_id: request_id, error: {code: code, message: message}}`, 其中:
106
106
 
107
- * `request_id` 为本次请求的请求码,由 UPYUN 本台返回,可用该值查询 UPYUN 日志;
107
+ * `request_id` 为本次请求的请求码,由 UPYUN 后台返回,可用该值查询 UPYUN 日志;
108
108
  * `code` 为又拍云返回的错误码;
109
109
  * `message` 为错误信息;
110
110
 
@@ -307,7 +307,7 @@ opts = {
307
307
  }
308
308
  upyun.upload('file', opts)
309
309
  ```
310
- 特别地,如果指定了 `return-url`, 那么返回的是需要跳转的地址,
310
+ 特别地,如果指定了 `return-url`, 那么返回的需要跳转的地址等信息也在这个 `Hash` 结构中,
311
311
  详情查阅 [通知规则](http://docs.upyun.com/api/form_api/#notify_return)
312
312
 
313
313
 
data/lib/upyun/form.rb CHANGED
@@ -58,13 +58,24 @@ module Upyun
58
58
  rest_client.post(payload, {'User-Agent' => "Upyun-Ruby-SDK-#{VERSION}"}) do |res|
59
59
  case res.code
60
60
  when 302
61
- res
61
+
62
+ # return 302 when set 'return-url' in opts
63
+ hds = res.headers
64
+ body = CGI::parse(URI.parse(hds[:location]).query).reduce({}) do |memo, (k, v)|
65
+ memo.merge!({k.to_sym => v.first})
66
+ end
67
+
68
+ body[:code] = body[:code].to_i
69
+ body[:time] = body[:time].to_i
70
+ body[:request_id] = hds[:x_request_id]
71
+ body
62
72
  else
63
73
  body = JSON.parse(res.body, symbolize_names: true)
64
74
 
65
75
  # TODO Upyun have a small bug for the `code`,
66
76
  # we have to adjust it to integer
67
77
  body[:code] = body[:code].to_i
78
+ body[:request_id] = res.headers[:x_request_id]
68
79
  body
69
80
  end
70
81
  end
data/lib/upyun/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Upyun
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
data/spec/upyun_spec.rb CHANGED
@@ -100,6 +100,7 @@ describe "Upyun Restful API Basic testing" do
100
100
  it "GET a not-exist file" do
101
101
  res = @upyun.get("/ruby-sdk/foo/#{String.random}/test-not-exist.jpg")
102
102
  expect(res.is_a?(Hash) && res[:error][:code] == 404)
103
+ expect(res[:request_id]).to be_instance_of(String)
103
104
  end
104
105
 
105
106
  after(:all) { @upyun.delete(@path) }
@@ -222,20 +223,24 @@ describe "Form Upload", current: true do
222
223
  expect(res[:message]).to match(/Authorize has expired/)
223
224
  end
224
225
 
225
- it "set 'return-url' should return 302 with 'location' header" do
226
+ it "set 'return-url' should a hash" do
226
227
  res = @form.upload(@file, {'return-url' => 'http://www.example.com'})
227
- expect(res.code).to eq(302)
228
- expect(res.headers.key?(:location)).to be true
228
+ expect(res).to be_instance_of(Hash)
229
+ expect(res[:code]).to eq(200)
230
+ expect(res[:time]).to be_instance_of(Fixnum)
231
+ expect(res[:request_id]).to be_instance_of(String)
229
232
  end
230
233
 
231
- it "set 'return-url' and handle failed, should also return 302 with 'location' header" do
234
+ it "set 'return-url' and handle failed, should also return a hash" do
232
235
  opts = {
233
236
  'image-width-range' => '0,10',
234
237
  'return-url' => 'http://www.example.com'
235
238
  }
236
239
  res = @form.upload(@file, opts)
237
- expect(res.code).to eq(302)
238
- expect(res.headers.key?(:location)).to be true
240
+ expect(res).to be_instance_of(Hash)
241
+ expect(res[:code]).to eq(403)
242
+ expect(res[:time]).to be_instance_of(Fixnum)
243
+ expect(res[:request_id]).to be_instance_of(String)
239
244
  end
240
245
 
241
246
  it "set 'notify-url' should return 200 success" do
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.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - jsvisa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client