Top Level Namespace

Includes:
Stree

Defined Under Namespace

Modules: Stree

Constant Summary collapse

ACCESS_KEY_ID =

COMMAND LINE PARSER

ENV["ACCESS_KEY_ID"]
SECRET_ACCESS_KEY =
ENV["SECRET_ACCESS_KEY"]
COMMANDS =
%w(bucket object)
BUCKET_SUBCOMMANDS =
%w(add remove show)
OBJECT_SUBCOMMANDS =
%w(add remove show)

Constants included from Stree

Stree::HOST

Instance Method Summary collapse

Instance Method Details

#create_bucket(service, name, location) ⇒ Object



18
19
20
# File 'bin/stree', line 18

def create_bucket(service, name, location)
  service.buckets.build(name).save(location)
end

#create_object(service, name, file_name, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'bin/stree', line 40

def create_object(service, name, file_name, options = {})
  bucket_name, object_name = name.split("/", 2)
  object = service.buckets.find(bucket_name).objects.build(object_name)
  object.content_type = options[:type]
  object.content_encoding = options[:encoding]
  object.content_disposition = options[:disposition]
  object.acl = options[:acl]
  object.content = File.new(file_name)
  object.save
end

#destroy_bucket(service, name) ⇒ Object



22
23
24
# File 'bin/stree', line 22

def destroy_bucket(service, name)
  service.buckets.find(name).destroy
end

#destroy_object(service, name) ⇒ Object



51
52
53
54
55
# File 'bin/stree', line 51

def destroy_object(service, name)
  bucket_name, object_name = name.split("/", 2)
  object = service.buckets.find(bucket_name).objects.find(object_name)
  object.destroy
end

#list_buckets(service) ⇒ Object



12
13
14
15
16
# File 'bin/stree', line 12

def list_buckets(service)
  service.buckets.each do |bucket|
    puts bucket.name
  end
end

#list_objects(service) ⇒ Object



32
33
34
35
36
37
38
# File 'bin/stree', line 32

def list_objects(service)
  service.buckets.each do |bucket|
    bucket.objects.each do |object|
      puts "#{bucket.name}/#{object.key}"
    end
  end
end

#show_bucket(service, name, options = {}) ⇒ Object



26
27
28
29
30
# File 'bin/stree', line 26

def show_bucket(service, name, options = {})
  service.buckets.find(name).objects.find_all.each do |object|
    puts "#{name}/#{object.key}"
  end
end

#show_object(service, name, file_name = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'bin/stree', line 57

def show_object(service, name, file_name = nil)
  bucket_name, object_name = name.split("/", 2)
  object = service.buckets.find(bucket_name).objects.find_first(object_name)
  puts "         object:   #{object.name}/#{object.key}"
  puts "   content type:   #{object.content_type}"
  puts "           size:   #{object.size}"
  puts "           etag:   #{object.etag}"
  puts "  last modified:   #{object.last_modified}"
  if file_name
    if file_name == "-"
      puts object.content
    else
      File.open(file_name, "wb") do |file|
        file.write(object.content)
      end
    end
  end
end