Module: AmazonDeliver

Included in:
AmazonEmail
Defined in:
lib/amazon_deliver.rb

Class Method Summary collapse

Class Method Details

.get(amazon_email) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/amazon_deliver.rb', line 3

def self.get(amazon_email)
  resource = AmazonUrlGenerator.create_query(amazon_email.from, amazon_email.to, amazon_email.subject, amazon_email.body)

  date = Time.new.localtime.strftime("%a, %d %b %Y %H:%M:%S %Z")
  http = Net::HTTP.new("email.us-east-1.amazonaws.com", 443)
  http.use_ssl = true
  headers = {
    'Date' => date.to_s,
    'x-Amzn-Authorization' => "AWS3-HTTPS AWSAccessKeyId=#{amazon_email.aws_access_key}, Algorithm=HmacSHA1, Signature=#{AmazonAuthentication.key(amazon_email.aws_secret_key, date)}"
  }

  http.start do |http|
    req = Net::HTTP::Get.new(resource, headers)
    response = http.request(req)
    resp = response.body
  end
end