Module: ClientBucketMethods

Defined in:
lib/client_bucket_methods.rb

Overview

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Instance Method Summary collapse

Instance Method Details

#blob_data(params) ⇒ Object

RestClient doesn’t do streaming ‘get’ yet - we already opened a pull request on this see github.com/archiloque/rest-client/issues/closed#issue/62 - apparently its going to be in the next version - unknown when. For now get full response. FIXME



63
64
65
66
67
# File 'lib/client_bucket_methods.rb', line 63

def blob_data(params)
  request(:get, "#{api_uri.to_s}/buckets/#{params['bucket']}/#{params[:id]}/content") do |response|
    response
  end
end

#create_blob(params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/client_bucket_methods.rb', line 34

def create_blob(params)
  blob = nil
  resource = RestClient::Resource.new("#{api_uri.to_s}/buckets/#{params['bucket']}", :open_timeout => 10, :timeout => 45)
  headers = default_headers.merge(extended_headers)
  unless params['metadata'].nil?
     = {}
    params['metadata'].each   do |k,v|
      ["X-Deltacloud-Blobmeta-#{k}"] = v
    end
    headers = headers.merge()
  end
  resource.send(:post, {:blob_data => File.new(params['file_path'], 'rb'), :blob_id => params[:id]}, headers) do |response, request, block|
    handle_backend_error(response) if response.code.eql?(500)
    blob = base_object(:blob, response)
    yield blob if block_given?
  end
  return blob
end

#create_bucket(params) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/client_bucket_methods.rb', line 18

def create_bucket(params)
  obj = nil
  request(:post, "#{api_uri.to_s}/buckets", {:name => params['id'],:location=>params['bucket_location'] }) do |response|
    handle_backend_error(response) if response.code!=201
    obj = base_object(:bucket, response)
  end
end

#destroy_blob(params) ⇒ Object



53
54
55
56
57
58
# File 'lib/client_bucket_methods.rb', line 53

def destroy_blob(params)
  request(:delete, "#{api_uri.to_s}/buckets/#{params['bucket']}/#{params[:id]}") do |response|
    handle_backend_error(response) if response.code!=204
    nil if response.code == 204
  end
end

#destroy_bucket(params) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/client_bucket_methods.rb', line 26

def destroy_bucket(params)
  #actually response here is 204 - no content - so nothing returned to client?
  request(:delete, "#{api_uri.to_s}/buckets/#{params['id']}") do |response|
    handle_backend_error(response) if response.code!=204
    nil if response.code == 204
  end
end