[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 SES
class Real 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 # Delete an existing verified email address
# #

View File

@ -5,9 +5,10 @@ module Fog
require 'fog/aws/parsers/ses/send_email' require 'fog/aws/parsers/ses/send_email'
# Delete an existing verified email address # Send an email
# #
# ==== Parameters # ==== Parameters
# * Source <~String> - The sender's email address
# * Destination <~Hash> - The destination for this email, composed of To:, From:, and CC: fields. # * Destination <~Hash> - The destination for this email, composed of To:, From:, and CC: fields.
# * BccAddresses <~Array> - The BCC: field(s) of the message. # * BccAddresses <~Array> - The BCC: field(s) of the message.
# * CcAddresses <~Array> - The CC: field(s) of the message. # * CcAddresses <~Array> - The CC: field(s) of the message.
@ -23,9 +24,9 @@ module Fog
# * Subject <~Hash> # * Subject <~Hash>
# * Charset <~String> # * Charset <~String>
# * Data <~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. # * options <~Hash>:
# * 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. # * 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.
# * Source <~String> - The sender's email address # * 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 # ==== Returns
# * response<~Excon::Response>: # * response<~Excon::Response>:
@ -33,13 +34,36 @@ module Fog
# * 'DeleteVerfiedEmailAddressResponse'<~nil> # * 'DeleteVerfiedEmailAddressResponse'<~nil>
# * 'ResponseMetadata'<~Hash>: # * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request # * 'RequestId'<~String> - Id of request
def send_email() def send_email(source, destination, message, options = {})
params = AWS.indexed_param('ReplyToAddresses.member', [*reply_to_addresses]) 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({ request({
'Action' => 'DeleteVerifiedEmailAddress', 'Action' => 'SendEmail',
'EmailAddress' => email_address, :parser => Fog::Parsers::AWS::SES::SendEmail.new
:parser => Fog::Parsers::AWS::SES::DeleteVerifiedEmailAddress.new
}.merge(params)) }.merge(params))
end end
@ -47,7 +71,7 @@ module Fog
class Mock class Mock
def delete_verified_email_address(email_address) def send_email(source, destination, message, options = {})
Fog::Mock.not_implemented Fog::Mock.not_implemented
end end

View File

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

View File

@ -68,22 +68,29 @@ module Fog
idempotent = params.delete(:idempotent) idempotent = params.delete(:idempotent)
parser = params.delete(:parser) parser = params.delete(:parser)
body = AWS.signed_params( headers = {
params, 'Content-Type' => 'application/x-www-form-urlencoded',
{ 'Date' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
:aws_access_key_id => @aws_access_key_id, }
:hmac => @hmac,
:host => @host, #AWS3-HTTPS AWSAccessKeyId=<Your AWS Access Key ID>, Algorithm=HmacSHA256, Signature=<Signature>
:path => @path, headers['X-Amzn-Authorization'] = 'AWS3-HTTPS '
:port => @port, headers['X-Amzn-Authorization'] << 'AWSAccessKeyId=' << @aws_access_key_id
:version => '2009-11-25' 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({ response = @connection.request({
:body => body, :body => body,
:expects => 200, :expects => 200,
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, :headers => headers,
:idempotent => idempotent, :idempotent => idempotent,
:host => @host, :host => @host,
:method => 'POST', :method => 'POST',

View File

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

View File

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