10 This creates a connection so that you can interact with the server:
15 username = 'account_name:user_name'
16 api_key = 'your_secret_key'
18 conn = CloudFiles::Connection.new(
19 :username => username,
21 :auth_url => 'http://objects.dreamhost.com/auth'
28 This creates a new container called ``my-new-container``
32 container = conn.create_container('my-new-container')
38 This creates a file ``hello.txt`` from the file named ``my_hello.txt``
42 obj = container.create_object('hello.txt')
43 obj.load_from_filename('./my_hello.txt')
44 obj.content_type = 'text/plain'
51 This gets a list of Containers that you own, and also prints out
56 conn.containers.each do |container|
60 The output will look something like this::
67 List a Container's Contents
68 ===========================
70 This gets a list of objects in the container, and prints out each
71 object's name, the file size, and last modified date:
75 require 'date' # not necessary in the next version
77 container.objects_detail.each do |name, data|
78 puts "#{name}\t#{data[:bytes]}\t#{data[:last_modified]}"
81 The output will look something like this::
83 myphoto1.jpg 251262 2011-08-08T21:35:48.000Z
84 myphoto2.jpg 262518 2011-08-08T21:38:01.000Z
91 This downloads the object ``hello.txt`` and saves it in
96 obj = container.object('hello.txt')
97 obj.save_to_filename('./my_hello.txt')
103 This deletes the object ``goodbye.txt``:
107 container.delete_object('goodbye.txt')
115 The container must be empty! Otherwise the request won't work!
119 container.delete_container('my-new-container')