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/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, 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
-
.fetch(bucket, target_url, key) ⇒ 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
126
127
128
129
|
# File 'lib/qiniu.rb', line 126
def batch(command, bucket, keys)
code, data = Storage.batch(command, bucket, keys)
code == StatusOK ? data : false
end
|
.batch_copy(*args) ⇒ Object
141
142
143
144
|
# File 'lib/qiniu.rb', line 141
def batch_copy(*args)
code, data = Storage.batch_copy(args)
code == StatusOK
end
|
.batch_delete(bucket, keys) ⇒ Object
159
160
161
162
|
# File 'lib/qiniu.rb', line 159
def batch_delete(bucket, keys)
code, data = Storage.batch_delete(bucket, keys)
code == StatusOK ? data : false
end
|
.batch_download(bucket, keys) ⇒ Object
151
152
153
154
155
156
157
|
# File 'lib/qiniu.rb', line 151
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
136
137
138
139
|
# File 'lib/qiniu.rb', line 136
def batch_get(bucket, keys)
code, data = Storage.batch_get(bucket, keys)
code == StatusOK ? data : false
end
|
.batch_move(*args) ⇒ Object
146
147
148
149
|
# File 'lib/qiniu.rb', line 146
def batch_move(*args)
code, data = Storage.batch_move(args)
code == StatusOK
end
|
.batch_stat(bucket, keys) ⇒ Object
131
132
133
134
|
# File 'lib/qiniu.rb', line 131
def batch_stat(bucket, keys)
code, data = Storage.batch_stat(bucket, keys)
code == StatusOK ? data : false
end
|
.buckets ⇒ Object
33
34
35
36
|
# File 'lib/qiniu.rb', line 33
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
164
165
166
167
|
# File 'lib/qiniu.rb', line 164
def drop(bucket)
code, data = Storage.drop(bucket)
code == StatusOK
end
|
.establish_connection!(opts = {}) ⇒ Object
.fetch(bucket, target_url, key) ⇒ Object
121
122
123
124
|
# File 'lib/qiniu.rb', line 121
def fetch(bucket, target_url, key)
code, data = Storage.fetch(bucket, target_url, key)
code == StatusOK
end
|
.generate_download_token(opts = {}) ⇒ Object
203
204
205
206
207
208
209
210
|
# File 'lib/qiniu.rb', line 203
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/qiniu.rb', line 188
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
174
175
176
177
|
# File 'lib/qiniu.rb', line 174
def image_exif(url)
code, data = Fop::Image.exif(url)
code == StatusOK ? data : false
end
|
.image_info(url) ⇒ Object
169
170
171
172
|
# File 'lib/qiniu.rb', line 169
def image_info(url)
code, data = Fop::Image.info(url)
code == StatusOK ? data : false
end
|
.image_mogrify_preview_url(source_image_url, options) ⇒ Object
179
180
181
|
# File 'lib/qiniu.rb', line 179
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
183
184
185
186
|
# File 'lib/qiniu.rb', line 183
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
28
29
30
31
|
# File 'lib/qiniu.rb', line 28
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
38
39
40
41
|
# File 'lib/qiniu.rb', line 38
def set_protected(bucket, protected_mode)
code, data = Misc.set_protected(bucket, protected_mode)
code == StatusOK
end
|
.set_separator(bucket, separator) ⇒ Object
43
44
45
46
|
# File 'lib/qiniu.rb', line 43
def set_separator(bucket, separator)
code, data = Misc.set_separator(bucket, separator)
code == StatusOK
end
|
.set_style(bucket, name, style) ⇒ Object
48
49
50
51
|
# File 'lib/qiniu.rb', line 48
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
53
54
55
56
|
# File 'lib/qiniu.rb', line 53
def unset_style(bucket, name)
code, data = Misc.unset_style(bucket, name)
code == StatusOK
end
|
.upload_file(opts = {}) ⇒ Object
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 58
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.resumable_upload_with_token(opts[:uptoken],
opts[:file],
opts[:bucket],
opts[:key],
opts[:mime_type],
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
|