Module: DeltacloudVM::Client::Methods::Blob

Included in:
Blob, Bucket, Connection
Defined in:
lib/deltacloud_vm/client/methods/blob.rb

Instance Method Summary collapse

Instance Method Details

#blob(bucket_id, blob_id) ⇒ Object

Retrieve the single blob entity

  • blob_id -> Blob entity to retrieve



31
32
33
34
35
36
# File 'lib/deltacloud_vm/client/methods/blob.rb', line 31

def blob(bucket_id, blob_id)
  model(:blob).convert(
    self,
    connection.get(api_uri("buckets/#{bucket_id}/#{blob_id}"))
  )
end

#blobs(bucket_id = nil) ⇒ Object

Retrieve a list of all blob entities from given bucket

Raises:

  • (error)


22
23
24
25
# File 'lib/deltacloud_vm/client/methods/blob.rb', line 22

def blobs(bucket_id=nil)
  raise error.new("The :bucket_id cannot be nil.") if bucket_id.nil?
  bucket(bucket_id).blob_ids.map { |blob_id| blob(bucket_id, blob_id) }
end

#create_blob(bucket_id, blob_name, blob_data, create_opts = {}) ⇒ Object

Create a new blob

  • bucket_id -> A bucket ID that new blob should belong to

  • blob_name -> A name for new blob

  • blob_data -> Data stored in this blob

  • create_opts

    • :user_metadata -> A Ruby Hash with key => value metadata



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/deltacloud_vm/client/methods/blob.rb', line 46

def create_blob(bucket_id, blob_name, blob_data, create_opts={})
  must_support! :buckets
  create_opts.merge!(convert_meta_params(create_opts.delete(:user_metadata)))
  response = connection.post(api_uri("buckets/#{bucket_id}")) do |request|
    request.params = create_opts.merge(
      :blob_id => blob_name,
      :blob_data => blob_data
  )
  end
  model(:blob).convert(self, response.body)
end

#destroy_blob(bucket_id, blob_id) ⇒ Object

Destroy given bucket blob



60
61
62
63
64
# File 'lib/deltacloud_vm/client/methods/blob.rb', line 60

def destroy_blob(bucket_id, blob_id)
  must_support! :buckets
  r = connection.delete(api_uri("buckets/#{bucket_id}/#{blob_id}"))
  r.status == 204
end