Module: Qiniu::RS
- Defined in:
- lib/qiniu/rs.rb,
lib/qiniu/rs/eu.rb,
lib/qiniu/rs/io.rb,
lib/qiniu/rs/rs.rb,
lib/qiniu/rs/up.rb,
lib/qiniu/rs/log.rb,
lib/qiniu/rs/pub.rb,
lib/qiniu/rs/auth.rb,
lib/qiniu/rs/image.rb,
lib/qiniu/rs/utils.rb,
lib/qiniu/rs/config.rb,
lib/qiniu/rs/version.rb,
lib/qiniu/rs/abstract.rb,
lib/qiniu/rs/exceptions.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
Defined Under Namespace
Modules: Abstract, Auth, Config, EU, IO, Image, Log, Pub, RS, UP, 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
-
.image_preview_url(url, spec) ⇒ Object
-
.login!(user, pwd) ⇒ Object
-
.mkbucket(bucket_name) ⇒ Object
-
.move(source_bucket, source_key, target_bucket, target_key) ⇒ Object
-
.put_auth(expires_in = nil, callback_url = nil) ⇒ Object
def set_watermark(customer_id, options = {}) code, data = EU.set_watermark(customer_id, options) code == StatusOK end.
-
.put_file(opts = {}) ⇒ 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(opts = {}) ⇒ Object
-
.upload_file(opts = {}) ⇒ Object
Class Method Details
.batch(command, bucket, keys) ⇒ Object
169
170
171
172
|
# File 'lib/qiniu/rs.rb', line 169
def batch(command, bucket, keys)
code, data = RS.batch(command, bucket, keys)
code == StatusOK ? data : false
end
|
.batch_copy(*args) ⇒ Object
184
185
186
187
|
# File 'lib/qiniu/rs.rb', line 184
def batch_copy(*args)
code, data = RS.batch_copy(*args)
code == StatusOK
end
|
.batch_delete(bucket, keys) ⇒ Object
202
203
204
205
|
# File 'lib/qiniu/rs.rb', line 202
def batch_delete(bucket, keys)
code, data = RS.batch_delete(bucket, keys)
code == StatusOK ? data : false
end
|
.batch_download(bucket, keys) ⇒ Object
194
195
196
197
198
199
200
|
# File 'lib/qiniu/rs.rb', line 194
def batch_download(bucket, keys)
code, data = RS.batch_get(bucket, keys)
return false unless code == StatusOK
links = []
data.each { |e| links << e["data"]["url"] }
links
end
|
.batch_get(bucket, keys) ⇒ Object
179
180
181
182
|
# File 'lib/qiniu/rs.rb', line 179
def batch_get(bucket, keys)
code, data = RS.batch_get(bucket, keys)
code == StatusOK ? data : false
end
|
.batch_move(*args) ⇒ Object
189
190
191
192
|
# File 'lib/qiniu/rs.rb', line 189
def batch_move(*args)
code, data = RS.batch_move(*args)
code == StatusOK
end
|
.batch_stat(bucket, keys) ⇒ Object
174
175
176
177
|
# File 'lib/qiniu/rs.rb', line 174
def batch_stat(bucket, keys)
code, data = RS.batch_stat(bucket, keys)
code == StatusOK ? data : false
end
|
.buckets ⇒ Object
41
42
43
44
|
# File 'lib/qiniu/rs.rb', line 41
def buckets
code, data = RS.buckets
code == StatusOK ? data : false
end
|
.copy(source_bucket, source_key, target_bucket, target_key) ⇒ Object
154
155
156
157
|
# File 'lib/qiniu/rs.rb', line 154
def copy(source_bucket, source_key, target_bucket, target_key)
code, data = RS.copy(source_bucket, source_key, target_bucket, target_key)
code == StatusOK
end
|
.delete(bucket, key) ⇒ Object
164
165
166
167
|
# File 'lib/qiniu/rs.rb', line 164
def delete(bucket, key)
code, data = RS.delete(bucket, key)
code == StatusOK
end
|
.download(bucket, key, save_as = nil, expires_in = nil, version = nil) ⇒ Object
149
150
151
152
|
# File 'lib/qiniu/rs.rb', line 149
def download(bucket, key, save_as = nil, expires_in = nil, version = nil)
code, data = RS.get(bucket, key, save_as, expires_in, version)
code == StatusOK ? data["url"] : false
end
|
.drop(bucket) ⇒ Object
207
208
209
210
|
# File 'lib/qiniu/rs.rb', line 207
def drop(bucket)
code, data = RS.drop(bucket)
code == StatusOK
end
|
.establish_connection!(opts = {}) ⇒ Object
.generate_download_token(opts = {}) ⇒ Object
250
251
252
253
254
255
256
257
|
# File 'lib/qiniu/rs.rb', line 250
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
# File 'lib/qiniu/rs.rb', line 235
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
144
145
146
147
|
# File 'lib/qiniu/rs.rb', line 144
def get(bucket, key, save_as = nil, expires_in = nil, version = nil)
code, data = RS.get(bucket, key, save_as, expires_in, version)
code == StatusOK ? data : false
end
|
.image_exif(url) ⇒ Object
217
218
219
220
|
# File 'lib/qiniu/rs.rb', line 217
def image_exif(url)
code, data = Image.exif(url)
code == StatusOK ? data : false
end
|
.image_info(url) ⇒ Object
212
213
214
215
|
# File 'lib/qiniu/rs.rb', line 212
def image_info(url)
code, data = Image.info(url)
code == StatusOK ? data : false
end
|
.image_mogrify_preview_url(source_image_url, options) ⇒ Object
226
227
228
|
# File 'lib/qiniu/rs.rb', line 226
def image_mogrify_preview_url(source_image_url, options)
Image.mogrify_preview_url(source_image_url, options)
end
|
.image_mogrify_save_as(bucket, key, source_image_url, options) ⇒ Object
230
231
232
233
|
# File 'lib/qiniu/rs.rb', line 230
def image_mogrify_save_as(bucket, key, source_image_url, options)
code, data = RS.image_mogrify_save_as(bucket, key, source_image_url, options)
code == StatusOK ? data : false
end
|
.image_preview_url(url, spec) ⇒ Object
222
223
224
|
# File 'lib/qiniu/rs.rb', line 222
def image_preview_url(url, spec)
Image.preivew_url(url, spec)
end
|
.login!(user, pwd) ⇒ Object
31
32
33
34
|
# File 'lib/qiniu/rs.rb', line 31
def login!(user, pwd)
code, data = Auth.exchange_by_password!(user, pwd)
code == StatusOK
end
|
.mkbucket(bucket_name) ⇒ Object
36
37
38
39
|
# File 'lib/qiniu/rs.rb', line 36
def mkbucket(bucket_name)
code, data = RS.mkbucket(bucket_name)
code == StatusOK
end
|
.move(source_bucket, source_key, target_bucket, target_key) ⇒ Object
159
160
161
162
|
# File 'lib/qiniu/rs.rb', line 159
def move(source_bucket, source_key, target_bucket, target_key)
code, data = RS.move(source_bucket, source_key, target_bucket, target_key)
code == StatusOK
end
|
.put_auth(expires_in = nil, callback_url = nil) ⇒ Object
def set_watermark(customer_id, options = {})
code, data = EU.set_watermark(customer_id, options)
code == StatusOK
end
def get_watermark(customer_id = nil)
code, data = EU.get_watermark(customer_id)
code == StatusOK ? data : false
end
78
79
80
81
|
# File 'lib/qiniu/rs.rb', line 78
def put_auth(expires_in = nil, callback_url = nil)
code, data = IO.put_auth(expires_in, callback_url)
code == StatusOK ? data["url"] : false
end
|
.put_file(opts = {}) ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/qiniu/rs.rb', line 95
def put_file opts = {}
code, data = IO.put_file(opts[:file],
opts[:bucket],
opts[:key],
opts[:mime_type],
opts[:note],
opts[:enable_crc32_check])
code == StatusOK
end
|
.set_protected(bucket, protected_mode) ⇒ Object
46
47
48
49
|
# File 'lib/qiniu/rs.rb', line 46
def set_protected(bucket, protected_mode)
code, data = Pub.set_protected(bucket, protected_mode)
code == StatusOK
end
|
.set_separator(bucket, separator) ⇒ Object
51
52
53
54
|
# File 'lib/qiniu/rs.rb', line 51
def set_separator(bucket, separator)
code, data = Pub.set_separator(bucket, separator)
code == StatusOK
end
|
.set_style(bucket, name, style) ⇒ Object
56
57
58
59
|
# File 'lib/qiniu/rs.rb', line 56
def set_style(bucket, name, style)
code, data = Pub.set_style(bucket, name, style)
code == StatusOK
end
|
.stat(bucket, key) ⇒ Object
139
140
141
142
|
# File 'lib/qiniu/rs.rb', line 139
def stat(bucket, key)
code, data = RS.stat(bucket, key)
code == StatusOK ? data : false
end
|
.unset_style(bucket, name) ⇒ Object
61
62
63
64
|
# File 'lib/qiniu/rs.rb', line 61
def unset_style(bucket, name)
code, data = Pub.unset_style(bucket, name)
code == StatusOK
end
|
.upload(opts = {}) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/qiniu/rs.rb', line 83
def upload opts = {}
code, data = IO.upload_file(opts[:url],
opts[:file],
opts[:bucket],
opts[:key],
opts[:mime_type],
opts[:note],
opts[:callback_params],
opts[:enable_crc32_check])
code == StatusOK
end
|
.upload_file(opts = {}) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/qiniu/rs.rb', line 105
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 = UP.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 = IO.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
|