Module: RAWS::S3::Adapter::Adapter20060301

Included in:
RAWS::S3::Adapter
Defined in:
lib/raws/s3/adapter.rb

Constant Summary collapse

URI_PARAMS =
{
  :scheme => 'https',
  :host   => 's3.amazonaws.com',
  :path   => '/',
  :query  => {}
}

Instance Method Summary collapse

Instance Method Details

#connect(method, params = {}, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/raws/s3/adapter.rb', line 76

def connect(method, params={}, &block)
  uri, path = parse_params params
  RAWS::S3.http.connect(uri) do |request|
    request.method = method
    request.header['date'] = Time.now.httpdate
    request.before_send do |_request|
      sign _request, path
    end
    block.call request
  end
end

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



206
207
208
209
210
211
212
213
214
215
216
# File 'lib/raws/s3/adapter.rb', line 206

def copy_object(src_bucket, src_key, dest_bucket, dest_key, header={})
  connect(
    'PUT',
    :bucket => dest_bucket,
    :path   => '/' << dest_key
  ) do |request|
    request.header.merge! header
    request.header['x-amz-copy-source'] = "/#{src_bucket}/#{src_key}"
    request.send
  end
end

#delete_bucket(bucket_name) ⇒ Object



189
190
191
192
193
# File 'lib/raws/s3/adapter.rb', line 189

def delete_bucket(bucket_name)
  connect 'DELETE', :bucket => bucket_name do |request|
    request.send
  end
end

#delete_object(bucket_name, key) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
# File 'lib/raws/s3/adapter.rb', line 247

def delete_object(bucket_name, key)
  connect(
    'DELETE',
    :bucket => bucket_name,
    :path   => '/' << key
  ) do |request|
    response = request.send
    response.receive
    response
  end
end

#get_acl(bucket_name, key) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/raws/s3/adapter.rb', line 163

def get_acl(bucket_name, key)
  connect(
    'GET', 
    :bucket => bucket_name,
    :path   => "/#{key}",
    :query  => {'acl' => nil}
  ) do |request|
    response = request.send
    response.parse :multiple => ['Grant']
    response
  end
end

#get_bucket(bucket_name, query = {}) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/raws/s3/adapter.rb', line 127

def get_bucket(bucket_name, query={})
  connect(
    'GET', 
    :bucket => bucket_name,
    :query  => query
  ) do |request|
    response = request.send
    response.parse :multiple => ['Contents']
    response
  end
end

#get_bucket_location(bucket_name) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/raws/s3/adapter.rb', line 151

def get_bucket_location(bucket_name)
  connect(
    'GET', 
    :bucket => bucket_name,
    :query  => {'location' => nil}
  ) do |request|
    response = request.send
    response.parse
    response
  end
end

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



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/raws/s3/adapter.rb', line 218

def get_object(bucket_name, key=nil, header={}, &block)
  connect(
    'GET',
    :bucket => bucket_name,
    :path   => "/#{key}"
  ) do |request|
    request.header.merge! header
    if block_given?
      block.call(request)
    else
      response = request.send
      response.receive
      response
    end
  end
end

#get_request_payment(bucket_name) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/raws/s3/adapter.rb', line 139

def get_request_payment(bucket_name)
  connect(
    'GET', 
    :bucket => bucket_name,
    :query  => {'requestPayment' => nil}
  ) do |request|
    response = request.send
    response.parse
    response
  end
end

#get_serviceObject



88
89
90
91
92
93
94
# File 'lib/raws/s3/adapter.rb', line 88

def get_service
  connect 'GET' do |request|
    response = request.send
    response.parse :multiple => ['Bucket']
    response
  end
end

#head_object(bucket_name, key) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
# File 'lib/raws/s3/adapter.rb', line 235

def head_object(bucket_name, key)
  connect(
    'HEAD',
    :bucket => bucket_name,
    :path   => '/' << key
  ) do |request|
    response = request.send
    response.receive
    response
  end
end

#put_acl(bucket_name, key, acl) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/raws/s3/adapter.rb', line 176

def put_acl(bucket_name, key, acl)
  connect(
    'PUT', 
    :bucket => bucket_name,
    :path   => "/#{key}",
    :query  => {'acl' => nil}
  ) do |request|
    response = request.send acl
    response.parse :multiple => ['Grant']
    response
  end
end

#put_bucket(bucket_name, location = nil, header = {}) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/raws/s3/adapter.rb', line 96

def put_bucket(bucket_name, location=nil, header={})
  connect 'PUT', :bucket => bucket_name do |request|
    request.header.merge! header
    response = request.send(
      if location
        "<CreateBucketConfiguration>" <<
          "<LocationConstraint>#{location}</LocationConstraint>" <<
        "</CreateBucketConfiguration>"
      end
    )
    response.receive
    response
  end
end

#put_object(bucket_name, key, header, &block) ⇒ Object



195
196
197
198
199
200
201
202
203
204
# File 'lib/raws/s3/adapter.rb', line 195

def put_object(bucket_name, key, header, &block)
  connect(
    'PUT',
    :bucket => bucket_name,
    :path   => '/' << key
  ) do |request|
    request.header.merge!(header)
    block.call(request)
  end
end

#put_request_payment(bucket_name, requester) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/raws/s3/adapter.rb', line 111

def put_request_payment(bucket_name, requester)
  connect(
    'PUT', 
    :bucket => bucket_name,
    :query  => {'requestPayment' => nil}
  ) do |request|
    response = request.send\
      '<RequestPaymentConfiguration' <<
        ' xmlns="http://s3.amazonaws.com/doc/2006-03-01/">' <<
        "<Payer>#{requester}</Payer>" <<
      '</RequestPaymentConfiguration>'
    response.receive
    response
  end
end