Class: Uplink::Project
- Inherits:
-
Object
- Object
- Uplink::Project
- Defined in:
- lib/uplink/project.rb
Instance Method Summary collapse
- #abort_upload(bucket_name, object_key, upload_id) ⇒ Object
- #begin_upload(bucket_name, object_key, options = nil) ⇒ Object
- #close ⇒ Object
- #commit_upload(bucket_name, object_key, upload_id, options = nil) ⇒ Object
- #copy_object(old_bucket_name, old_object_key, new_bucket_name, new_object_key, options = nil) ⇒ Object
- #create_bucket(bucket_name) ⇒ Object
- #delete_bucket(bucket_name) ⇒ Object
- #delete_bucket_with_objects(bucket_name) ⇒ Object
- #delete_object(bucket_name, object_key) ⇒ Object
- #download_object(bucket_name, object_key, options = nil, auto_close: true) ⇒ Object
- #ensure_bucket(bucket_name) ⇒ Object
-
#initialize(project_result) ⇒ Project
constructor
A new instance of Project.
- #list_buckets(options = nil) ⇒ Object
- #list_objects(bucket_name, options = nil) ⇒ Object
- #list_upload_parts(bucket_name, object_key, upload_id, options = nil) ⇒ Object
- #list_uploads(bucket_name, options = nil) ⇒ Object
- #move_object(old_bucket_name, old_object_key, new_bucket_name, new_object_key, options = nil) ⇒ Object
- #revoke_access(access) ⇒ Object
- #stat_bucket(bucket_name) ⇒ Object
- #stat_object(bucket_name, object_key) ⇒ Object
- #update_object_metadata(bucket_name, object_key, new_metadata, options = nil) ⇒ Object
- #upload_object(bucket_name, object_key, options = nil) ⇒ Object
- #upload_part(bucket_name, object_key, upload_id, part_number) ⇒ Object
Constructor Details
#initialize(project_result) ⇒ Project
Returns a new instance of Project.
5 6 7 |
# File 'lib/uplink/project.rb', line 5 def initialize(project_result) @project = project_result[:project] end |
Instance Method Details
#abort_upload(bucket_name, object_key, upload_id) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/uplink/project.rb', line 121 def abort_upload(bucket_name, object_key, upload_id) error = UplinkLib.uplink_abort_upload(@project, bucket_name, object_key, upload_id) ErrorUtil.handle_error(error) ensure UplinkLib.uplink_free_error(error) if error end |
#begin_upload(bucket_name, object_key, options = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/uplink/project.rb', line 80 def begin_upload(bucket_name, object_key, = nil) = UplinkUtil.() result = UplinkLib.uplink_begin_upload(@project, bucket_name, object_key, ) ErrorUtil.handle_result_error(result) UploadInfo.new(result) ensure UplinkLib.uplink_free_upload_info_result(result) if result end |
#close ⇒ Object
252 253 254 255 256 257 |
# File 'lib/uplink/project.rb', line 252 def close error = UplinkLib.uplink_close_project(@project) ErrorUtil.handle_error(error) ensure UplinkLib.uplink_free_error(error) if error end |
#commit_upload(bucket_name, object_key, upload_id, options = nil) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/uplink/project.rb', line 100 def commit_upload(bucket_name, object_key, upload_id, = nil) = nil if && !.empty? = nil if [:custom_metadata] && ![:custom_metadata].empty? = UplinkUtil.([:custom_metadata]) end = UplinkLib::UplinkCommitUploadOptions.new [:custom_metadata] = end result = UplinkLib.uplink_commit_upload(@project, bucket_name, object_key, upload_id, ) ErrorUtil.handle_result_error(result) Object.new(result) ensure UplinkLib.uplink_free_commit_upload_result(result) if result end |
#copy_object(old_bucket_name, old_object_key, new_bucket_name, new_object_key, options = nil) ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/uplink/project.rb', line 220 def copy_object(old_bucket_name, old_object_key, new_bucket_name, new_object_key, = nil) result = UplinkLib.uplink_copy_object(@project, old_bucket_name, old_object_key, new_bucket_name, new_object_key, ) ErrorUtil.handle_result_error(result) Object.new(result) ensure UplinkLib.uplink_free_object_result(result) if result end |
#create_bucket(bucket_name) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/uplink/project.rb', line 9 def create_bucket(bucket_name) result = UplinkLib.uplink_create_bucket(@project, bucket_name) ErrorUtil.handle_result_error(result) Bucket.new(result) ensure UplinkLib.uplink_free_bucket_result(result) if result end |
#delete_bucket(bucket_name) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/uplink/project.rb', line 51 def delete_bucket(bucket_name) result = UplinkLib.uplink_delete_bucket(@project, bucket_name) ErrorUtil.handle_result_error(result) Bucket.new(result) ensure UplinkLib.uplink_free_bucket_result(result) if result end |
#delete_bucket_with_objects(bucket_name) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/uplink/project.rb', line 60 def delete_bucket_with_objects(bucket_name) result = UplinkLib.uplink_delete_bucket_with_objects(@project, bucket_name) ErrorUtil.handle_result_error(result) Bucket.new(result) ensure UplinkLib.uplink_free_bucket_result(result) if result end |
#delete_object(bucket_name, object_key) ⇒ Object
236 237 238 239 240 241 242 243 |
# File 'lib/uplink/project.rb', line 236 def delete_object(bucket_name, object_key) result = UplinkLib.uplink_delete_object(@project, bucket_name, object_key) ErrorUtil.handle_result_error(result) Object.new(result) ensure UplinkLib.uplink_free_object_result(result) if result end |
#download_object(bucket_name, object_key, options = nil, auto_close: true) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/uplink/project.rb', line 163 def download_object(bucket_name, object_key, = nil, auto_close: true) = nil if && !.empty? = UplinkLib::UplinkDownloadOptions.new [:offset] = [:offset].to_i if [:offset] [:length] = [:length].to_i if [:length] end result = UplinkLib.uplink_download_object(@project, bucket_name, object_key, ) ErrorUtil.handle_result_error(result) download = Download.new(result) yield download ensure download.close if auto_close && download UplinkLib.uplink_free_download_result(result) if result end |
#ensure_bucket(bucket_name) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/uplink/project.rb', line 18 def ensure_bucket(bucket_name) result = UplinkLib.uplink_ensure_bucket(@project, bucket_name) ErrorUtil.handle_result_error(result) Bucket.new(result) ensure UplinkLib.uplink_free_bucket_result(result) if result end |
#list_buckets(options = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/uplink/project.rb', line 36 def list_buckets( = nil) = nil if && !.empty? = UplinkLib::UplinkListBucketsOptions.new cursor = FFI::MemoryPointer.from_string([:cursor]) if [:cursor] [:cursor] = cursor end iterator = UplinkLib.uplink_list_buckets(@project, ) yield BucketIterator.new(iterator) ensure UplinkLib.uplink_free_bucket_iterator(iterator) if iterator end |
#list_objects(bucket_name, options = nil) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/uplink/project.rb', line 191 def list_objects(bucket_name, = nil) = nil if && !.empty? = UplinkLib::UplinkListObjectsOptions.new cursor = FFI::MemoryPointer.from_string([:cursor]) if [:cursor] prefix = FFI::MemoryPointer.from_string([:prefix]) if [:prefix] [:cursor] = cursor [:prefix] = prefix [:recursive] = [:recursive] [:system] = [:system] [:custom] = [:custom] end iterator = UplinkLib.uplink_list_objects(@project, bucket_name, ) yield ObjectIterator.new(iterator) ensure UplinkLib.uplink_free_object_iterator(iterator) if iterator end |
#list_upload_parts(bucket_name, object_key, upload_id, options = nil) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/uplink/project.rb', line 148 def list_upload_parts(bucket_name, object_key, upload_id, = nil) = nil if && !.empty? = UplinkLib::UplinkListUploadPartsOptions.new cursor = [:cursor].to_i if [:cursor] [:cursor] = cursor || 0 end iterator = UplinkLib.uplink_list_upload_parts(@project, bucket_name, object_key, upload_id, ) yield UploadPartIterator.new(iterator) ensure UplinkLib.uplink_free_part_iterator(iterator) if iterator end |
#list_uploads(bucket_name, options = nil) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/uplink/project.rb', line 128 def list_uploads(bucket_name, = nil) = nil if && !.empty? = UplinkLib::UplinkListUploadsOptions.new cursor = FFI::MemoryPointer.from_string([:cursor]) if [:cursor] prefix = FFI::MemoryPointer.from_string([:prefix]) if [:prefix] [:cursor] = cursor [:prefix] = prefix [:recursive] = [:recursive] [:system] = [:system] [:custom] = [:custom] end iterator = UplinkLib.uplink_list_uploads(@project, bucket_name, ) yield UploadIterator.new(iterator) ensure UplinkLib.uplink_free_upload_iterator(iterator) if iterator end |
#move_object(old_bucket_name, old_object_key, new_bucket_name, new_object_key, options = nil) ⇒ Object
229 230 231 232 233 234 |
# File 'lib/uplink/project.rb', line 229 def move_object(old_bucket_name, old_object_key, new_bucket_name, new_object_key, = nil) error = UplinkLib.uplink_move_object(@project, old_bucket_name, old_object_key, new_bucket_name, new_object_key, ) ErrorUtil.handle_error(error) ensure UplinkLib.uplink_free_error(error) if error end |
#revoke_access(access) ⇒ Object
245 246 247 248 249 250 |
# File 'lib/uplink/project.rb', line 245 def revoke_access(access) error = UplinkLib.uplink_revoke_access(@project, access&.access) ErrorUtil.handle_error(error) ensure UplinkLib.uplink_free_error(error) if error end |
#stat_bucket(bucket_name) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/uplink/project.rb', line 27 def stat_bucket(bucket_name) result = UplinkLib.uplink_stat_bucket(@project, bucket_name) ErrorUtil.handle_result_error(result) Bucket.new(result) ensure UplinkLib.uplink_free_bucket_result(result) if result end |
#stat_object(bucket_name, object_key) ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/uplink/project.rb', line 182 def stat_object(bucket_name, object_key) result = UplinkLib.uplink_stat_object(@project, bucket_name, object_key) ErrorUtil.handle_result_error(result) Object.new(result) ensure UplinkLib.uplink_free_object_result(result) if result end |
#update_object_metadata(bucket_name, object_key, new_metadata, options = nil) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/uplink/project.rb', line 211 def (bucket_name, object_key, , = nil) = UplinkUtil.() error = UplinkLib.(@project, bucket_name, object_key, , ) ErrorUtil.handle_error(error) ensure UplinkLib.uplink_free_error(error) if error end |
#upload_object(bucket_name, object_key, options = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/uplink/project.rb', line 69 def upload_object(bucket_name, object_key, = nil) = UplinkUtil.() result = UplinkLib.uplink_upload_object(@project, bucket_name, object_key, ) ErrorUtil.handle_result_error(result) yield Upload.new(result) ensure UplinkLib.uplink_free_upload_result(result) if result end |
#upload_part(bucket_name, object_key, upload_id, part_number) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/uplink/project.rb', line 91 def upload_part(bucket_name, object_key, upload_id, part_number) result = UplinkLib.uplink_upload_part(@project, bucket_name, object_key, upload_id, part_number) ErrorUtil.handle_result_error(result) yield PartUpload.new(result) ensure UplinkLib.uplink_free_part_upload_result(result) if result end |