Module: Buckets

Included in:
CryptKeeper::Connection
Defined in:
lib/buckets.rb

Defined Under Namespace

Classes: Bucket, BucketMetaObject, Utils

Instance Method Summary collapse

Instance Method Details

#bucket_meta_objects(bucket_name, *args) ⇒ Object

GET Bucket lists the contents of a bucket or retrieves the ACLs that are applied to a bucket. returns an array of BucketMetaObjects takes a bucket name and hash for options. Possible keys for the hash are

  • :delimeter

  • :marker

  • :max_keys

  • :prefix



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/buckets.rb', line 51

def bucket_meta_objects(bucket_name, *args)
  options = {
      :delimeter => nil,
      :marker    => nil,
      :max_keys  => nil,
      :prefix    => nil
  }
  options.merge!(args.pop) if args.last.is_a? Hash

  path = "/?"
  path << "delimeter=#{options[:delimeter]}&" if !options[:delimeter].nil?
  path << "marker=#{options[:marker]}&" if !options[:marker].nil?
  path << "max-keys=#{options[:max_keys]}&" if !options[:max_keys].nil?
  path << "prefix=#{options[:prefix]}&" if !options[:prefix].nil?
  path.gsub!(/[&]$/, '')

  hpr        = Hpricot(connection.get(path, bucket_name))
  hpr.search("contents").map do |el|
    BucketMetaObject.new(
        {
            :bucket_name => bucket_name,
            :key => el.search("key").inner_html,
            :last_modified => el.search("lastmodified").inner_html,
            :e_tag => el.search("etag").inner_html,
            :size => el.search("size").inner_html,
            :storage_class => el.search("storageclass").inner_html,
            :owner_id => el.search("id").inner_html,
            :owner_display_name => el.search("displayname").inner_html
        }
    )
  end
end

#bucketsObject

GET Service lists all of the buckets that you own return an array of Bucket objects



8
9
10
# File 'lib/buckets.rb', line 8

def buckets
  find_buckets
end

#connectionObject

returns the connection object that was initialized



13
14
15
# File 'lib/buckets.rb', line 13

def connection
  CryptKeeper::Connection.http_instance
end

#create_bucket(*args) ⇒ Object

create a bucket. Takes a Hash as it’s argument => ‘my_new_bucket_name’



19
20
21
22
23
# File 'lib/buckets.rb', line 19

def create_bucket(*args)
  options = args.last
  connection.put("/", options[:name])
  find_buckets(options)
end

#find_buckets(*args) ⇒ Object

search for buckets by name => ‘my_bucket_name’



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/buckets.rb', line 27

def find_buckets(*args)
  options = args.last
  name = options[:name] if options.is_a? Hash
  buckets = Hpricot(connection.get("/")).search("bucket").map do |el|
    Bucket.new(
        {
            :name => el.search("name").inner_html,
            :created_at => el.search("creationdate").inner_html
        }
    )
  end
  name.nil? ? buckets : buckets.reject { |bucket| bucket.name != name }[0]
end