Module: Qiniu
- Defined in:
- lib/qiniu/http.rb,
lib/qiniu.rb,
lib/qiniu/adt.rb,
lib/qiniu/log.rb,
lib/qiniu/auth.rb,
lib/qiniu/misc.rb,
lib/qiniu/pfop.rb,
lib/qiniu/image.rb,
lib/qiniu/utils.rb,
lib/qiniu/config.rb,
lib/qiniu/helper.rb,
lib/qiniu/upload.rb,
lib/qiniu/version.rb,
lib/qiniu/abstract.rb,
lib/qiniu/exceptions.rb,
lib/qiniu/management.rb,
lib/qiniu/resumable_upload.rb,
lib/qiniu/tokens/qbox_token.rb,
lib/qiniu/tokens/access_token.rb,
lib/qiniu/tokens/upload_token.rb,
lib/qiniu/tokens/download_token.rb
Overview
DownloadToken 类已经过时,请改用 Qiniu::Auth.authorize_download_url 方法 ### 或 Qiniu::Auth.authorize_download_url_2 方法 ###
Defined Under Namespace
Modules: ADT, Abstract, Auth, Config, Fop, HTTP, Helper, Log, Misc, Storage, Utils, Version
Classes: AccessToken, BlockCountNotMathchError, BlockSizeNotMathchError, DownloadToken, Exception, FileSeekReadError, InvalidArgsError, MissingAccessToken, MissingArgsError, MissingConfError, MissingRefreshToken, MissingUsernameOrPassword, NoSuchFileError, QboxToken, RequestFailed, ResponseError, UploadFailedError, UploadToken
Constant Summary
collapse
- StatusOK =
200
Class Method Summary
collapse
-
.batch(command, bucket, keys) ⇒ Object
-
.batch_copy(*args) ⇒ Object
-
.batch_delete(bucket, keys) ⇒ Object
-
.batch_download(bucket, keys) ⇒ Object
-
.batch_get(bucket, keys) ⇒ Object
-
.batch_move(*args) ⇒ Object
-
.batch_stat(bucket, keys) ⇒ Object
-
.buckets ⇒ Object
-
.copy(source_bucket, source_key, target_bucket, target_key) ⇒ Object
-
.delete(bucket, key) ⇒ Object
-
.download(bucket, key, save_as = nil, expires_in = nil, version = nil) ⇒ Object
-
.drop(bucket) ⇒ Object
-
.establish_connection!(opts = {}) ⇒ Object
-
.generate_download_token(opts = {}) ⇒ Object
-
.generate_upload_token(opts = {}) ⇒ Object
-
.get(bucket, key, save_as = nil, expires_in = nil, version = nil) ⇒ Object
-
.image_exif(url) ⇒ Object
-
.image_info(url) ⇒ Object
-
.image_mogrify_preview_url(source_image_url, options) ⇒ Object
-
.image_mogrify_save_as(bucket, key, source_image_url, options) ⇒ Object
-
.mkbucket(bucket_name) ⇒ Object
-
.move(source_bucket, source_key, target_bucket, target_key) ⇒ Object
-
.set_protected(bucket, protected_mode) ⇒ Object
-
.set_separator(bucket, separator) ⇒ Object
-
.set_style(bucket, name, style) ⇒ Object
-
.stat(bucket, key) ⇒ Object
-
.unset_style(bucket, name) ⇒ Object
-
.upload_file(opts = {}) ⇒ Object
Class Method Details
.batch(command, bucket, keys) ⇒ Object
121
122
123
124
|
# File 'lib/qiniu.rb', line 121
def batch(command, bucket, keys)
code, data = Storage.batch(command, bucket, keys)
code == StatusOK ? data : false
end
|
.batch_copy(*args) ⇒ Object
136
137
138
139
|
# File 'lib/qiniu.rb', line 136
def batch_copy(*args)
code, data = Storage.batch_copy(args)
code == StatusOK
end
|
.batch_delete(bucket, keys) ⇒ Object
154
155
156
157
|
# File 'lib/qiniu.rb', line 154
def batch_delete(bucket, keys)
code, data = Storage.batch_delete(bucket, keys)
code == StatusOK ? data : false
end
|
.batch_download(bucket, keys) ⇒ Object
146
147
148
149
150
151
152
|
# File 'lib/qiniu.rb', line 146
def batch_download(bucket, keys)
code, data = Storage.batch_get(bucket, keys)
return false unless code == StatusOK
links = []
data.each { |e| links << e["data"]["url"] }
links
end
|
.batch_get(bucket, keys) ⇒ Object
131
132
133
134
|
# File 'lib/qiniu.rb', line 131
def batch_get(bucket, keys)
code, data = Storage.batch_get(bucket, keys)
code == StatusOK ? data : false
end
|
.batch_move(*args) ⇒ Object
141
142
143
144
|
# File 'lib/qiniu.rb', line 141
def batch_move(*args)
code, data = Storage.batch_move(args)
code == StatusOK
end
|
.batch_stat(bucket, keys) ⇒ Object
126
127
128
129
|
# File 'lib/qiniu.rb', line 126
def batch_stat(bucket, keys)
code, data = Storage.batch_stat(bucket, keys)
code == StatusOK ? data : false
end
|
.buckets ⇒ Object
32
33
34
35
|
# File 'lib/qiniu.rb', line 32
def buckets
code, data = Storage.buckets
code == StatusOK ? data : false
end
|
.copy(source_bucket, source_key, target_bucket, target_key) ⇒ Object
106
107
108
109
|
# File 'lib/qiniu.rb', line 106
def copy(source_bucket, source_key, target_bucket, target_key)
code, data = Storage.copy(source_bucket, source_key, target_bucket, target_key)
code == StatusOK
end
|
.delete(bucket, key) ⇒ Object
116
117
118
119
|
# File 'lib/qiniu.rb', line 116
def delete(bucket, key)
code, data = Storage.delete(bucket, key)
code == StatusOK
end
|
.download(bucket, key, save_as = nil, expires_in = nil, version = nil) ⇒ Object
101
102
103
104
|
# File 'lib/qiniu.rb', line 101
def download(bucket, key, save_as = nil, expires_in = nil, version = nil)
code, data = Storage.get(bucket, key, save_as, expires_in, version)
code == StatusOK ? data["url"] : false
end
|
.drop(bucket) ⇒ Object
159
160
161
162
|
# File 'lib/qiniu.rb', line 159
def drop(bucket)
code, data = Storage.drop(bucket)
code == StatusOK
end
|
.establish_connection!(opts = {}) ⇒ Object
.generate_download_token(opts = {}) ⇒ Object
198
199
200
201
202
203
204
205
|
# File 'lib/qiniu.rb', line 198
def generate_download_token(opts = {})
token_obj = DownloadToken.new(opts)
token_obj.access_key = Config.settings[:access_key]
token_obj.secret_key = Config.settings[:secret_key]
token_obj.generate_token
end
|
.generate_upload_token(opts = {}) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/qiniu.rb', line 183
def generate_upload_token(opts = {})
token_obj = UploadToken.new(opts)
token_obj.access_key = Config.settings[:access_key]
token_obj.secret_key = Config.settings[:secret_key]
token_obj.generate_token
end
|
.get(bucket, key, save_as = nil, expires_in = nil, version = nil) ⇒ Object
96
97
98
99
|
# File 'lib/qiniu.rb', line 96
def get(bucket, key, save_as = nil, expires_in = nil, version = nil)
code, data = Storage.get(bucket, key, save_as, expires_in, version)
code == StatusOK ? data : false
end
|
.image_exif(url) ⇒ Object
169
170
171
172
|
# File 'lib/qiniu.rb', line 169
def image_exif(url)
code, data = Fop::Image.exif(url)
code == StatusOK ? data : false
end
|
.image_info(url) ⇒ Object
164
165
166
167
|
# File 'lib/qiniu.rb', line 164
def image_info(url)
code, data = Fop::Image.info(url)
code == StatusOK ? data : false
end
|
.image_mogrify_preview_url(source_image_url, options) ⇒ Object
174
175
176
|
# File 'lib/qiniu.rb', line 174
def image_mogrify_preview_url(source_image_url, options)
Fop::Image.mogrify_preview_url(source_image_url, options)
end
|
.image_mogrify_save_as(bucket, key, source_image_url, options) ⇒ Object
178
179
180
181
|
# File 'lib/qiniu.rb', line 178
def image_mogrify_save_as(bucket, key, source_image_url, options)
code, data = Storage.image_mogrify_save_as(bucket, key, source_image_url, options)
code == StatusOK ? data : false
end
|
.mkbucket(bucket_name) ⇒ Object
27
28
29
30
|
# File 'lib/qiniu.rb', line 27
def mkbucket(bucket_name)
code, data = Storage.mkbucket(bucket_name)
code == StatusOK
end
|
.move(source_bucket, source_key, target_bucket, target_key) ⇒ Object
111
112
113
114
|
# File 'lib/qiniu.rb', line 111
def move(source_bucket, source_key, target_bucket, target_key)
code, data = Storage.move(source_bucket, source_key, target_bucket, target_key)
code == StatusOK
end
|
.set_protected(bucket, protected_mode) ⇒ Object
37
38
39
40
|
# File 'lib/qiniu.rb', line 37
def set_protected(bucket, protected_mode)
code, data = Misc.set_protected(bucket, protected_mode)
code == StatusOK
end
|
.set_separator(bucket, separator) ⇒ Object
42
43
44
45
|
# File 'lib/qiniu.rb', line 42
def set_separator(bucket, separator)
code, data = Misc.set_separator(bucket, separator)
code == StatusOK
end
|
.set_style(bucket, name, style) ⇒ Object
47
48
49
50
|
# File 'lib/qiniu.rb', line 47
def set_style(bucket, name, style)
code, data = Misc.set_style(bucket, name, style)
code == StatusOK
end
|
.stat(bucket, key) ⇒ Object
91
92
93
94
|
# File 'lib/qiniu.rb', line 91
def stat(bucket, key)
code, data = Storage.stat(bucket, key)
code == StatusOK ? data : false
end
|
.unset_style(bucket, name) ⇒ Object
52
53
54
55
|
# File 'lib/qiniu.rb', line 52
def unset_style(bucket, name)
code, data = Misc.unset_style(bucket, name)
code == StatusOK
end
|
.upload_file(opts = {}) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/qiniu.rb', line 57
def upload_file opts = {}
uncontained_opts = [:uptoken, :file, :bucket, :key] - opts.keys
raise MissingArgsError, uncontained_opts unless uncontained_opts.empty?
source_file = opts[:file]
raise NoSuchFileError, source_file unless File.exist?(source_file)
opts[:enable_resumable_upload] = true unless opts.has_key?(:enable_resumable_upload)
if opts[:enable_resumable_upload] && File::size(source_file) > Config.settings[:block_size]
code, data, = Storage.upload_with_token(opts[:uptoken],
opts[:file],
opts[:bucket],
opts[:key],
opts[:mime_type],
opts[:note],
opts[:customer],
opts[:callback_params],
opts[:rotate])
else
code, data, = Storage.upload_with_token(opts[:uptoken],
opts[:file],
opts[:bucket],
opts[:key],
opts[:mime_type],
opts[:note],
opts[:callback_params],
opts[:enable_crc32_check],
opts[:rotate])
end
raise UploadFailedError.new(code, data) if code != StatusOK
return data
end
|