Class: AmazonSES::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon_ses/base.rb

Class Method Summary collapse

Class Method Details

.make_request(form_hash, secret, key) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/amazon_ses/base.rb', line 10

def self.make_request(form_hash,secret,key)
  date = AmazonSES::Base.rfc2616(Time.now)
  uri = URI.parse("https://email.us-east-1.amazonaws.com/")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data(form_hash)
  request['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
  request.add_field("Date",date)
  request.add_field("X-Amzn-Authorization",AmazonSES::Base.sign_https_request(request,date,secret,key))
  response = http.request(request)
  case response
    when Net::HTTPSuccess then return response
    when Net::HTTPClientError then raise response.body
    when Net::HTTPServerError then raise response.body
    else raise response.body
  end
  #return response
end

.rfc2616(time) ⇒ Object



4
5
6
# File 'lib/amazon_ses/base.rb', line 4

def self.rfc2616(time)
  time.utc.strftime("%a, %d %b %Y %H:%M:%S")+" +0000"
end

.sign_https_request(request, date, secret, key) ⇒ Object



7
8
9
# File 'lib/amazon_ses/base.rb', line 7

def self.sign_https_request(request,date,secret,key) 
  return "AWS3-HTTPS AWSAccessKeyId=#{key}, Algorithm=HmacSHA256, Signature=#{Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha256"), secret, date)).strip}"
end