upyun 1.0.5 → 1.0.6
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/README.md +18 -10
- data/lib/upyun/rest.rb +2 -2
- data/lib/upyun/version.rb +1 -1
- data/spec/upyun_spec.rb +6 -2
- 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: 5a66fd1986e039bfa120d3ce923ab1809edd6c5a
|
4
|
+
data.tar.gz: cec146d124a0257d94540c4b23001d56b9589402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8397e0d383e03a1574f47ed5ef1b18ce92ccc5b4ff3da243791b5dad47491c38136bbee8bf2adfcbb454ab6d743befb84c90b1535a19ce37db747e13aeb4f8e
|
7
|
+
data.tar.gz: 2760c52be9fb2be54d320c9b7064febc600163c98e888b6e47803b015670d4ad6d263a5c13838b520106a3a1e07ad5af526c629fcfd9227aa3d2a271aa48dedc
|
data/README.md
CHANGED
@@ -39,15 +39,17 @@ $ gem install upyun
|
|
39
39
|
```ruby
|
40
40
|
require 'upyun'
|
41
41
|
|
42
|
-
upyun = Upyun::Rest.new(
|
42
|
+
upyun = Upyun::Rest.new(bucket, operator, password, options, endpoint)
|
43
43
|
```
|
44
44
|
**参数**
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
| 参数名 | 类型 | 可选 | 说明 |
|
47
|
+
|:-------------:|:--------:|-------:| ------------- |
|
48
|
+
| `bucket` | `String` | 必选 | UPYUN 空间名称|
|
49
|
+
| `operator` | `String` | 必选 | 授权操作员帐号|
|
50
|
+
| `password` | `String` | 必选 | 授权操作员密码|
|
51
|
+
| `options` | `Hash` | 可选 | 连接选项,可用的选项见[RestClient::Resource](https://github.com/rest-client/rest-client/blob/master/lib/restclient/resource.rb), 默认设置超时时间 60s |
|
52
|
+
| `endpoint` | `String` | 可选 | (默认:`Upyun::ED_AUTO`): API接入点,可根据具体网络情况设置最优的接入点,详情见 [API 域名](http://docs.upyun.com/api/) |
|
51
53
|
|
52
54
|
其中 `endpoint` 可选值如下:
|
53
55
|
|
@@ -90,12 +92,17 @@ headers = {'Content-Type' => 'image/jpeg', 'x-gmkerl-type' => 'fix_width', 'x-gm
|
|
90
92
|
upyun.put('/save/to/path', 'file or binary', headers)
|
91
93
|
```
|
92
94
|
|
93
|
-
其中, `/save/to/path` 和 `file or binary` 和默认上传方式中一致,`headers` 参数即为额外的可选 HTTP Header
|
95
|
+
其中, `/save/to/path` 和 `file or binary` 和默认上传方式中一致,`headers` 参数即为额外的可选 HTTP Header 参数,
|
96
|
+
详情查阅 [Rest API](http://docs.upyun.com/api/rest_api/#_4)
|
94
97
|
|
95
98
|
**返回**
|
96
99
|
|
97
|
-
|
98
|
-
|
100
|
+
上传成功:
|
101
|
+
|
102
|
+
* 如果是图片空间,返回图片原信息,如 `{:height=>629, :file_type=>"JPEG", :width=>440, :frames=>1}`
|
103
|
+
* 如果是其它空间,返回 `true`,
|
104
|
+
|
105
|
+
失败返回一个 `Hash` 结构: `{request_id: request_id, error: {code: code, message: message}}`, 其中:
|
99
106
|
|
100
107
|
* `request_id` 为本次请求的请求码,由 UPYUN 本台返回,可用该值查询 UPYUN 日志;
|
101
108
|
* `code` 为又拍云返回的错误码;
|
@@ -126,13 +133,14 @@ file = upyun.get('/path/to/file')
|
|
126
133
|
##### 保存文件至本地
|
127
134
|
|
128
135
|
```ruby
|
129
|
-
upyun.get('/path/to/file', 'saved/foo.png')
|
136
|
+
upyun.get('/path/to/file', 'saved/foo.png', headers)
|
130
137
|
```
|
131
138
|
|
132
139
|
**参数**
|
133
140
|
|
134
141
|
* `'/path/to/file'`: 文件在 UPYUN 空间中的路径
|
135
142
|
* `saved/foo.png`: 文件本地保存路径
|
143
|
+
* `headers`: 指定下载时的头信息,默认为 `{}`
|
136
144
|
|
137
145
|
**返回**
|
138
146
|
下载成功返回获取的文件长度, 失败返回内容和上例一致。
|
data/lib/upyun/rest.rb
CHANGED
@@ -39,8 +39,8 @@ module Upyun
|
|
39
39
|
file.close if file.respond_to?(:close)
|
40
40
|
end
|
41
41
|
|
42
|
-
def get(path, savepath=nil)
|
43
|
-
res = request(:get, path)
|
42
|
+
def get(path, savepath=nil, headers={})
|
43
|
+
res = request(:get, path, headers: headers)
|
44
44
|
return res if res.is_a?(Hash) || !savepath
|
45
45
|
|
46
46
|
dir = File.dirname(savepath)
|
data/lib/upyun/version.rb
CHANGED
data/spec/upyun_spec.rb
CHANGED
@@ -92,6 +92,11 @@ describe "Upyun Restful API Basic testing" do
|
|
92
92
|
File.delete('./save.jpg')
|
93
93
|
end
|
94
94
|
|
95
|
+
it "GET a file with Accept Header" do
|
96
|
+
expect(@upyun.get(@path, nil, {'Accept' => '*/*'})).to eq(@str)
|
97
|
+
end
|
98
|
+
|
99
|
+
|
95
100
|
it "GET a not-exist file" do
|
96
101
|
res = @upyun.get("/ruby-sdk/foo/#{String.random}/test-not-exist.jpg")
|
97
102
|
expect(res.is_a?(Hash) && res[:error][:code] == 404)
|
@@ -193,8 +198,7 @@ describe "Form Upload", current: true do
|
|
193
198
|
expect(res.keys).to include(:code, :message, :url, :time)
|
194
199
|
expect(res[:code]).to eq(200)
|
195
200
|
expect(res[:message]).to match(/ok/)
|
196
|
-
|
197
|
-
expect(res[:url]).to eq("/#{now.year}/#{now.mon}/#{now.day}/upyun.jpg")
|
201
|
+
expect(res[:url]).to eq(Time.now.utc.strftime('/%Y/%m/%d/upyun.jpg'))
|
198
202
|
end
|
199
203
|
|
200
204
|
it "with file descriptor should 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.6
|
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-
|
11
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|