Class: Uplink::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/uplink/project.rb

Instance Method Summary collapse

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, options = nil)
  upload_options = UplinkUtil.build_upload_options(options)

  result = UplinkLib.uplink_begin_upload(@project, bucket_name, object_key, upload_options)
  ErrorUtil.handle_result_error(result)

  UploadInfo.new(result)
ensure
  UplinkLib.uplink_free_upload_info_result(result) if result
end

#closeObject



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, options = nil)
  upload_options = nil
  if options && !options.empty?
     = nil

    if options[:custom_metadata] && !options[:custom_metadata].empty?
       = UplinkUtil.(options[:custom_metadata])
    end

    upload_options = UplinkLib::UplinkCommitUploadOptions.new
    upload_options[:custom_metadata] = 
  end

  result = UplinkLib.uplink_commit_upload(@project, bucket_name, object_key, upload_id, upload_options)
  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, options = nil)
  result = UplinkLib.uplink_copy_object(@project, old_bucket_name, old_object_key, new_bucket_name, new_object_key, options)
  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, options = nil, auto_close: true)
  download_options = nil
  if options && !options.empty?
    download_options = UplinkLib::UplinkDownloadOptions.new
    download_options[:offset] = options[:offset].to_i if options[:offset]
    download_options[:length] = options[:length].to_i if options[:length]
  end

  result = UplinkLib.uplink_download_object(@project, bucket_name, object_key, download_options)
  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(options = nil)
  list_options = nil
  if options && !options.empty?
    list_options = UplinkLib::UplinkListBucketsOptions.new
    cursor = FFI::MemoryPointer.from_string(options[:cursor]) if options[:cursor]
    list_options[:cursor] = cursor
  end

  iterator = UplinkLib.uplink_list_buckets(@project, list_options)

  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, options = nil)
  list_options = nil
  if options && !options.empty?
    list_options = UplinkLib::UplinkListObjectsOptions.new
    cursor = FFI::MemoryPointer.from_string(options[:cursor]) if options[:cursor]
    prefix = FFI::MemoryPointer.from_string(options[:prefix]) if options[:prefix]
    list_options[:cursor] = cursor
    list_options[:prefix] = prefix
    list_options[:recursive] = options[:recursive]
    list_options[:system] = options[:system]
    list_options[:custom] = options[:custom]
  end

  iterator = UplinkLib.uplink_list_objects(@project, bucket_name, list_options)

  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, options = nil)
  list_options = nil
  if options && !options.empty?
    list_options = UplinkLib::UplinkListUploadPartsOptions.new
    cursor = options[:cursor].to_i if options[:cursor]
    list_options[:cursor] = cursor || 0
  end

  iterator = UplinkLib.uplink_list_upload_parts(@project, bucket_name, object_key, upload_id, list_options)

  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, options = nil)
  list_options = nil
  if options && !options.empty?
    list_options = UplinkLib::UplinkListUploadsOptions.new
    cursor = FFI::MemoryPointer.from_string(options[:cursor]) if options[:cursor]
    prefix = FFI::MemoryPointer.from_string(options[:prefix]) if options[:prefix]
    list_options[:cursor] = cursor
    list_options[:prefix] = prefix
    list_options[:recursive] = options[:recursive]
    list_options[:system] = options[:system]
    list_options[:custom] = options[:custom]
  end

  iterator = UplinkLib.uplink_list_uploads(@project, bucket_name, list_options)

  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, options = nil)
  error = UplinkLib.uplink_move_object(@project, old_bucket_name, old_object_key, new_bucket_name, new_object_key, options)
  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, , options = nil)
   = UplinkUtil.()

  error = UplinkLib.(@project, bucket_name, object_key, , options)
  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, options = nil)
  upload_options = UplinkUtil.build_upload_options(options)

  result = UplinkLib.uplink_upload_object(@project, bucket_name, object_key, upload_options)
  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