amazon_ses 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ test/credentials.yml
data/Rakefile CHANGED
@@ -10,7 +10,8 @@ begin
10
10
  gem.email = "jeff.durand@gmail.com"
11
11
  gem.homepage = "http://github.com/johnnyiller/amazon_ses"
12
12
  gem.authors = ["jeff durand"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
13
+ gem.add_dependency "mail"
14
+ #gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amazon_ses}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jeff durand"]
@@ -25,6 +25,11 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "amazon_ses.gemspec",
27
27
  "lib/amazon_ses.rb",
28
+ "lib/amazon_ses/amz_mail.rb",
29
+ "lib/amazon_ses/base.rb",
30
+ "lib/amazon_ses/stats.rb",
31
+ "lib/amazon_ses/verify.rb",
32
+ "rails/init.rb",
28
33
  "test/helper.rb",
29
34
  "test/test_amazon_ses.rb"
30
35
  ]
@@ -43,12 +48,12 @@ Gem::Specification.new do |s|
43
48
  s.specification_version = 3
44
49
 
45
50
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_runtime_dependency(%q<mail>, [">= 0"])
47
52
  else
48
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ s.add_dependency(%q<mail>, [">= 0"])
49
54
  end
50
55
  else
51
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ s.add_dependency(%q<mail>, [">= 0"])
52
57
  end
53
58
  end
54
59
 
@@ -0,0 +1,15 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require 'time'
4
+ require "cgi"
5
+ require "base64"
6
+ require "openssl"
7
+ require "digest/sha1"
8
+ require "rubygems"
9
+ require "mail"
10
+
11
+ $:.unshift(File.dirname(__FILE__))
12
+ require 'amazon_ses/base'
13
+ require 'amazon_ses/verify'
14
+ require 'amazon_ses/stats'
15
+ require 'amazon_ses/amz_mail'
@@ -0,0 +1,29 @@
1
+ module AmazonSES
2
+
3
+ class AmzMail
4
+
5
+ def self.send(source,to_addresses,subject,body,secret,key)
6
+ AmazonSES::Base.make_request({"Action"=>"SendEmail",
7
+ "Source"=>source,
8
+ "Destination.ToAddresses.member.1"=>to_addresses,
9
+ "Message.Subject.Data"=>subject,
10
+ "Message.Body.Text.Data"=>body},secret,key)
11
+ end
12
+ def self.send_html(source,to_addresses,subject_txt,body_txt,secret,key)
13
+ mail = Mail.new do
14
+ to to_addresses
15
+ from source
16
+ subject subject_txt
17
+ html_part do
18
+ content_type 'text/html; charset=UTF-8'
19
+ body body_txt
20
+ end
21
+ end
22
+ str=mail.to_s.gsub("multipart/alternative","multipart/mixed")
23
+ encoded = Base64.encode64(str)
24
+ puts encoded
25
+ AmazonSES::Base.make_request({"Action"=>"SendRawEmail", "RawMessage.Data"=>encoded},secret,key)
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,26 @@
1
+ module AmazonSES
2
+ class Base
3
+
4
+ def self.rfc2616(time)
5
+ time.utc.strftime("%a, %d %b %Y %H:%M:%S")+" +0000"
6
+ end
7
+ def self.sign_https_request(request,date,secret,key)
8
+ return "AWS3-HTTPS AWSAccessKeyId=#{key}, Algorithm=HmacSHA256, Signature=#{Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha256"), secret, date)).strip}"
9
+ end
10
+ def self.make_request(form_hash,secret,key)
11
+ date = AmazonSES::Base.rfc2616(Time.now)
12
+ uri = URI.parse("https://email.us-east-1.amazonaws.com/")
13
+ http = Net::HTTP.new(uri.host, uri.port)
14
+ http.use_ssl = true
15
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
+ request = Net::HTTP::Post.new(uri.request_uri)
17
+ request.set_form_data(form_hash)
18
+ request['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
19
+ request.add_field("Date",date)
20
+ request.add_field("X-Amzn-Authorization",AmazonSES::Base.sign_https_request(request,date,secret,key))
21
+ response = http.request(request)
22
+ return response
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module AmazonSES
2
+
3
+ class Stats
4
+ def self.send_quota(secret,key)
5
+ AmazonSES::Base.make_request({"Action"=>"GetSendQuota"},secret,key)
6
+ end
7
+ def self.send_stats(secret,key)
8
+ AmazonSES::Base.make_request({"Action"=>"GetSendStatistics"},secret,key)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ module AmazonSES
2
+
3
+ class Verify
4
+ # returns the response object
5
+ def self.address(emailaddress,secret,key)
6
+ AmazonSES::Base.make_request({"Action"=>"VerifyEmailAddress","EmailAddress"=>emailaddress},secret,key)
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. lib amazon_ses])
2
+ module ActionMailer
3
+ class Base
4
+ def self.method_missing(method_symbol, *parameters) #:nodoc:
5
+
6
+ if match = matches_dynamic_method?(method_symbol)
7
+ if match[1]=='create'
8
+ new(match[2], *parameters).mail
9
+ elsif match[1]=='deliver'
10
+ @mymsg = new(match[2], *parameters).mail
11
+ AmazonSES::AmzMail.send_html(@mymsg.from,@mymsg.to.first,@mymsg.subject,@mymsg.body,AppConfig.ses_amz_secret,AppConfig.ses_amz_key)
12
+ elsif match[1]=='new'
13
+ nil
14
+ else
15
+ super
16
+ end
17
+ else
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
@@ -7,4 +7,6 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
7
  require 'amazon_ses'
8
8
 
9
9
  class Test::Unit::TestCase
10
+
11
+ #YAML.load_file("./test/credentials.yml").each { |key,value| instance_variable_set("@#{key}", value) }
10
12
  end
@@ -1,7 +1,20 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestAmazonSes < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ context "Has valid credentials" do
5
+ setup do
6
+ YAML.load_file("./test/credentials.yml").each { |key,value| instance_variable_set("@#{key}", value) }
7
+ end
8
+ #should "Be able to verify address" do
9
+ # resp = AmazonSES::Verify.address("admin@flickaday.com",@aws_secret,@aws_key)
10
+ #end
11
+ should "Get some stats" do
12
+ resp = AmazonSES::Stats.send_quota(@aws_secret,@aws_key)
13
+ puts resp.body
14
+ end
15
+ should "Send an email" do
16
+ resp = AmazonSES::AmzMail.send_html("admin@flickaday.com","admin@flickaday.com","hey how are you doing","<h1>Just wanted</h1><p> to send you a quick message.</p>",@aws_secret,@aws_key)
17
+ puts resp.body
18
+ end
6
19
  end
7
20
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 0.0.0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - jeff durand
@@ -18,7 +18,7 @@ date: 2011-02-17 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
21
+ name: mail
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
@@ -27,7 +27,7 @@ dependencies:
27
27
  segments:
28
28
  - 0
29
29
  version: "0"
30
- type: :development
30
+ type: :runtime
31
31
  version_requirements: *id001
32
32
  description: wrapper for the simple email service api
33
33
  email: jeff.durand@gmail.com
@@ -47,6 +47,11 @@ files:
47
47
  - VERSION
48
48
  - amazon_ses.gemspec
49
49
  - lib/amazon_ses.rb
50
+ - lib/amazon_ses/amz_mail.rb
51
+ - lib/amazon_ses/base.rb
52
+ - lib/amazon_ses/stats.rb
53
+ - lib/amazon_ses/verify.rb
54
+ - rails/init.rb
50
55
  - test/helper.rb
51
56
  - test/test_amazon_ses.rb
52
57
  has_rdoc: true