[aws|ses] cleanup and getting all the basics working

This commit is contained in:
geemus 2011-01-25 17:28:03 -08:00
parent 284430f526
commit f291f192c6
6 changed files with 76 additions and 34 deletions

View File

@ -3,7 +3,7 @@ module Fog
class SES
class Real
require 'fog/aws/parsers/ses/delete_verified_email'
require 'fog/aws/parsers/ses/delete_verified_email_address'
# Delete an existing verified email address
#

View File

@ -5,9 +5,10 @@ module Fog
require 'fog/aws/parsers/ses/send_email'
# Delete an existing verified email address
# Send an email
#
# ==== Parameters
# * Source <~String> - The sender's email address
# * Destination <~Hash> - The destination for this email, composed of To:, From:, and CC: fields.
# * BccAddresses <~Array> - The BCC: field(s) of the message.
# * CcAddresses <~Array> - The CC: field(s) of the message.
@ -23,9 +24,9 @@ module Fog
# * Subject <~Hash>
# * Charset <~String>
# * Data <~String>
# * ReplyToAddresses <~Array> - The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply.
# * ReturnPath <~String> - The email address to which bounce notifications are to be forwarded. If the message cannot be delivered to the recipient, then an error message will be returned from the recipient's ISP; this message will then be forwarded to the email address specified by the ReturnPath parameter.
# * Source <~String> - The sender's email address
# * options <~Hash>:
# * ReplyToAddresses <~Array> - The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply.
# * ReturnPath <~String> - The email address to which bounce notifications are to be forwarded. If the message cannot be delivered to the recipient, then an error message will be returned from the recipient's ISP; this message will then be forwarded to the email address specified by the ReturnPath parameter.
#
# ==== Returns
# * response<~Excon::Response>:
@ -33,13 +34,36 @@ module Fog
# * 'DeleteVerfiedEmailAddressResponse'<~nil>
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
def send_email()
params = AWS.indexed_param('ReplyToAddresses.member', [*reply_to_addresses])
def send_email(source, destination, message, options = {})
params = {
'Source' => source
}
for key, values in destination
params.merge!(AWS.indexed_param("Destination.#{key}.member", [*values]))
end
for key, value in message['Subject']
params["Message.Subject.#{key}"] = value
end
for type, data in message['Body']
for key, value in data
params["Message.Body.#{type}.#{key}"] = value
end
end
if options.has_key?('ReplyToAddresses')
params.merge!(AWS.indexed_param("ReplyToAddresses.member", [*options['ReplyToAddresses']]))
end
if options.has_key?('ReturnPath')
params['ReturnPath'] = options['ReturnPath']
end
request({
'Action' => 'DeleteVerifiedEmailAddress',
'EmailAddress' => email_address,
:parser => Fog::Parsers::AWS::SES::DeleteVerifiedEmailAddress.new
'Action' => 'SendEmail',
:parser => Fog::Parsers::AWS::SES::SendEmail.new
}.merge(params))
end
@ -47,7 +71,7 @@ module Fog
class Mock
def delete_verified_email_address(email_address)
def send_email(source, destination, message, options = {})
Fog::Mock.not_implemented
end

View File

@ -8,10 +8,10 @@ module Fog
# Delete an existing verified email address
#
# ==== Parameters
# * Destinations <~Array> - The destination for this email, composed of To:, From:, and CC: fields.
# * RawMessage <~Hash> - The message to be sent.
# * Data <~String>
# * Source <~String> - The sender's email address
# * RawMessage <~String> - The message to be sent.
# * Options <~Hash>
# * Source <~String> - The sender's email address
# * Destinations <~Array> - The destination for this email, composed of To:, From:, and CC: fields.
#
# ==== Returns
# * response<~Excon::Response>:
@ -19,13 +19,19 @@ module Fog
# * 'DeleteVerfiedEmailAddressResponse'<~nil>
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
def send_raw_email()
# TODO: Make this work
params = AWS.indexed_param('ReplyToAddresses.member', [*reply_to_addresses])
def send_raw_email(raw_message, options = {})
params = {}
if options.has_key?('Destinations')
params['Destinations'] = AWS.indexed_param('Destinations.member', [*options['Destinations']])
end
if options.has_key?('Source')
params['Source'] = options['Source']
end
request({
'Action' => 'SendRawEmail',
:parser => Fog::Parsers::AWS::SES::SendRawEmail.new
'Action' => 'SendRawEmail',
'RawMessage.Data' => Base64.encode64(raw_message).chomp!,
:parser => Fog::Parsers::AWS::SES::SendRawEmail.new
}.merge(params))
end
@ -33,7 +39,7 @@ module Fog
class Mock
def send_raw_email()
def send_raw_email(source, destinations, raw_message)
Fog::Mock.not_implemented
end

View File

@ -68,22 +68,29 @@ module Fog
idempotent = params.delete(:idempotent)
parser = params.delete(:parser)
body = AWS.signed_params(
params,
{
:aws_access_key_id => @aws_access_key_id,
:hmac => @hmac,
:host => @host,
:path => @path,
:port => @port,
:version => '2009-11-25'
}
)
headers = {
'Content-Type' => 'application/x-www-form-urlencoded',
'Date' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
}
#AWS3-HTTPS AWSAccessKeyId=<Your AWS Access Key ID>, Algorithm=HmacSHA256, Signature=<Signature>
headers['X-Amzn-Authorization'] = 'AWS3-HTTPS '
headers['X-Amzn-Authorization'] << 'AWSAccessKeyId=' << @aws_access_key_id
headers['X-Amzn-Authorization'] << ', Algorithm=HmacSHA256'
headers['X-Amzn-Authorization'] << ', Signature=' << Base64.encode64(@hmac.sign(headers['Date'])).chomp!
body = ''
for key in params.keys.sort
unless (value = params[key]).nil?
body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
end
end
body.chop! # remove trailing '&'
response = @connection.request({
:body => body,
:expects => 200,
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
:headers => headers,
:idempotent => idempotent,
:host => @host,
:method => 'POST',

View File

@ -15,6 +15,8 @@ class AWS < Fog::Bin
Fog::AWS::IAM
when :sdb
Fog::AWS::SimpleDB
when :ses
Fog::AWS::SES
when :eu_storage, :s3, :storage
Fog::AWS::Storage
else
@ -48,6 +50,8 @@ class AWS < Fog::Bin
Fog::Storage.new(:provider => 'AWS', :region => 'eu-west-1')
when :sdb
Fog::AWS::SimpleDB.new
when :ses
Fog::AWS::SES.new
when :s3
location = caller.first
warning = "[yellow][WARN] AWS[:s3] is deprecated, use AWS[:storage] instead[/]"
@ -64,7 +68,7 @@ class AWS < Fog::Bin
end
def services
[:cdn, :compute, :dns, :elb, :iam, :sdb, :storage]
[:cdn, :compute, :dns, :elb, :iam, :sdb, :ses, :storage]
end
end

View File

@ -15,6 +15,7 @@ module Fog
service(:elb, 'aws/elb')
service(:iam, 'aws/iam')
service(:s3, 'storage/aws')
service(:ses, 'aws/ses')
service(:simpledb, 'aws/simpledb')
service(:storage, 'storage/aws')