Class: RAWS::S3

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/raws/s3.rb

Defined Under Namespace

Modules: Model Classes: ACL, Adapter, Metadata, Owner

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name) ⇒ S3

Returns a new instance of S3.



113
114
115
# File 'lib/raws/s3.rb', line 113

def initialize(bucket_name)
  @bucket_name = bucket_name
end

Class Attribute Details

.httpObject



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

def http
  @http ||= RAWS.http
end

Instance Attribute Details

#bucket_nameObject (readonly) Also known as: name

Returns the value of attribute bucket_name.



110
111
112
# File 'lib/raws/s3.rb', line 110

def bucket_name
  @bucket_name
end

Class Method Details

.[](bucket_name) ⇒ Object

Returns the instance of RAWS::S3.



65
66
67
# File 'lib/raws/s3.rb', line 65

def [](bucket_name)
  self.new bucket_name
end

.acl(bucket_name, key = nil) ⇒ Object



74
75
76
# File 'lib/raws/s3.rb', line 74

def acl(bucket_name, key=nil)
  ACL.new bucket_name, key
end

.allObject



82
83
84
85
# File 'lib/raws/s3.rb', line 82

def filter(bucket_name, query={})
  vals = Adapter.get_bucket(bucket_name, query).doc['ListBucketResult']
  vals['Contents'] || []
end

.buckets(&block) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/raws/s3.rb', line 52

def buckets(&block)
  if block_given?
    each(&block)
  else
    map
  end
end

.copyObject



92
93
94
# File 'lib/raws/s3.rb', line 92

def copy_object(src_bucket, src_key, dest_bucket, dest_key, header={})
  Adapter.copy_object src_bucket, src_key, dest_bucket, dest_key, header
end

.copy_object(src_bucket, src_key, dest_bucket, dest_key, header = {}) ⇒ Object



89
90
91
# File 'lib/raws/s3.rb', line 89

def copy_object(src_bucket, src_key, dest_bucket, dest_key, header={})
  Adapter.copy_object src_bucket, src_key, dest_bucket, dest_key, header
end

.create_bucket(bucket_name, location = nil, header = {}) ⇒ Object

Creates a new bucket and returns the instance of RAWS::S3.



18
19
20
21
# File 'lib/raws/s3.rb', line 18

def create_bucket(bucket_name, location=nil, header={})
  Adapter.put_bucket bucket_name, location, header
  self[bucket_name]
end

.deleteObject



107
108
109
# File 'lib/raws/s3.rb', line 107

def delete_object(bucket_name, key)
  Adapter.delete_object bucket_name, key
end

.delete_bucket(bucket_name, force = nil) ⇒ Object

Delete the bucket.



24
25
26
27
28
29
30
31
32
33
# File 'lib/raws/s3.rb', line 24

def delete_bucket(bucket_name, force=nil)
  begin
    objects = filter(bucket_name)
    objects.each do |val|
      delete(bucket_name, val['Key'])
    end
  end until objects.empty? if force == :force

  Adapter.delete_bucket(bucket_name)
end

.delete_object(bucket_name, key) ⇒ Object



104
105
106
# File 'lib/raws/s3.rb', line 104

def delete_object(bucket_name, key)
  Adapter.delete_object bucket_name, key
end

.each(&block) ⇒ Object



60
61
62
# File 'lib/raws/s3.rb', line 60

def each(&block)
  list_buckets.each(&block)
end

.filter(bucket_name, query = {}) ⇒ Object



78
79
80
81
# File 'lib/raws/s3.rb', line 78

def filter(bucket_name, query={})
  vals = Adapter.get_bucket(bucket_name, query).doc['ListBucketResult']
  vals['Contents'] || []
end

.getObject



97
98
99
# File 'lib/raws/s3.rb', line 97

def get_object(bucket_name, key, header={}, &block)
  Adapter.get_object bucket_name, key, header, &block
end

.get_object(bucket_name, key, header = {}, &block) ⇒ Object



94
95
96
# File 'lib/raws/s3.rb', line 94

def get_object(bucket_name, key, header={}, &block)
  Adapter.get_object bucket_name, key, header, &block
end

.headObject



102
103
104
# File 'lib/raws/s3.rb', line 102

def head_object(bucket_name, key)
  Adapter.head_object bucket_name, key
end

.head_object(bucket_name, key) ⇒ Object



99
100
101
# File 'lib/raws/s3.rb', line 99

def head_object(bucket_name, key)
  Adapter.head_object bucket_name, key
end

.list_bucketsObject

Returns an array of RAWS::S3 objects.



41
42
43
44
45
46
47
48
49
50
# File 'lib/raws/s3.rb', line 41

def list_buckets
  doc = Adapter.get_service.doc['ListAllMyBucketsResult']['Buckets']
  if doc
    doc['Bucket'].map do |val|
      self[val['Name']]
    end
  else
    []
  end
end

.location(bucket_name) ⇒ Object



69
70
71
72
# File 'lib/raws/s3.rb', line 69

def location(bucket_name)
  doc = Adapter.get_bucket_location(bucket_name).doc['LocationConstraint']
  doc || 'US'
end

.ownerObject

Returns the instance of RAWS::S3::Owner.



36
37
38
# File 'lib/raws/s3.rb', line 36

def owner
  Owner.new Adapter.get_service.doc['ListAllMyBucketsResult']['Owner']
end

.putObject



87
88
89
# File 'lib/raws/s3.rb', line 87

def put_object(bucket_name, key, header={}, &block)
  Adapter.put_object bucket_name, key, header, &block
end

.put_object(bucket_name, key, header = {}, &block) ⇒ Object



84
85
86
# File 'lib/raws/s3.rb', line 84

def put_object(bucket_name, key, header={}, &block)
  Adapter.put_object bucket_name, key, header, &block
end

Instance Method Details

#<=>(a) ⇒ Object



167
168
169
# File 'lib/raws/s3.rb', line 167

def <=>(a)
  bucket_name <=> a.bucket_name
end

#acl(key = nil) ⇒ Object



133
134
135
# File 'lib/raws/s3.rb', line 133

def acl(key=nil)
  self.class.acl @bucket_name, key
end

#copy_object(key, dest_bucket, dest_key) ⇒ Object Also known as: copy



147
148
149
# File 'lib/raws/s3.rb', line 147

def copy_object(key, dest_bucket, dest_key)
  self.class.copy_object @bucket_name, key, dest_bucket, dest_key
end

#create_bucket(location = nil) ⇒ Object



117
118
119
# File 'lib/raws/s3.rb', line 117

def create_bucket(location=nil)
  self.class.create_bucket @bucket_name, location
end

#delete_bucket(force = nil) ⇒ Object



121
122
123
# File 'lib/raws/s3.rb', line 121

def delete_bucket(force=nil)
  self.class.delete_bucket @bucket_name, force
end

#delete_object(key) ⇒ Object Also known as: delete



162
163
164
# File 'lib/raws/s3.rb', line 162

def delete_object(key)
  self.class.delete_object @bucket_name, key
end

#filter(query = {}) ⇒ Object Also known as: all



137
138
139
# File 'lib/raws/s3.rb', line 137

def filter(query={})
  self.class.filter @bucket_name, query
end

#get_object(key, header = {}, &block) ⇒ Object Also known as: get



152
153
154
# File 'lib/raws/s3.rb', line 152

def get_object(key, header={}, &block)
  self.class.get_object @bucket_name, key, header, &block
end

#head_object(key) ⇒ Object Also known as: head



157
158
159
# File 'lib/raws/s3.rb', line 157

def head_object(key)
  self.class.head_object @bucket_name, key
end

#locationObject



129
130
131
# File 'lib/raws/s3.rb', line 129

def location
  self.class.location @bucket_name
end

#ownerObject



125
126
127
# File 'lib/raws/s3.rb', line 125

def owner
  self.class.owner
end

#put_object(key, header = {}, &block) ⇒ Object Also known as: put



142
143
144
# File 'lib/raws/s3.rb', line 142

def put_object(key, header={}, &block)
  self.class.put_object @bucket_name, key, header, &block
end