upyun 1.0.6 → 1.0.7
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/form.rb +12 -1
 - data/lib/upyun/version.rb +1 -1
 - data/spec/upyun_spec.rb +11 -6
 - 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: 7ede2802f726646a9e884163947fd0deb0bda7bb
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ffd7837ffa0dd88cf1f204fe10a95eb91a9c3ad3
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 722d70c68fbd1e73efd3cf4b7361e4290715902fc28a4d949bd5f2e39eb4d0de3d58e016c7c954fcee3daef1eee4af9d760efbaafc983752aa8481ec66aaa637
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 895bccf056eac1f6e35314dca90c297e4cfbdb1561c274300d35e2d7aaa296bb0de4541e5c37f6bccd8350c1563e470d06b27737991fb79eafdde87a21818f11
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        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  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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
    
    
    
        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  
     | 
| 
      
 226 
     | 
    
         
            +
                it "set 'return-url' should a hash" do
         
     | 
| 
       226 
227 
     | 
    
         
             
                  res = @form.upload(@file, {'return-url' => 'http://www.example.com'})
         
     | 
| 
       227 
     | 
    
         
            -
                  expect(res 
     | 
| 
       228 
     | 
    
         
            -
                  expect(res 
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
| 
       238 
     | 
    
         
            -
                  expect(res 
     | 
| 
      
 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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-04-09 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rest-client
         
     |