mtodd-silverpop_mailer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +50 -0
- data/init.rb +3 -0
- data/lib/silverpop/action_mailer.rb +29 -0
- data/lib/silverpop/mailer.rb +33 -0
- data/lib/silverpop/request.rb +99 -0
- data/lib/silverpop/response.rb +44 -0
- data/lib/silverpop/transact.rb +9 -0
- data/lib/silverpop.rb +28 -0
- data/silverpop_mailer.gemspec +25 -0
- metadata +89 -0
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/packagetask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
require 'fileutils'
|
8
|
+
include FileUtils
|
9
|
+
|
10
|
+
Spec::Rake::SpecTask.new do |t|
|
11
|
+
t.spec_opts = ["--color"]
|
12
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'rubygems/specification'
|
16
|
+
spec_def = File.read('silverpop-mailer.gemspec')
|
17
|
+
spec = nil
|
18
|
+
Thread.new { spec = eval("$SAFE = 3\n#{spec_def}") }.join
|
19
|
+
|
20
|
+
Rake::GemPackageTask.new(spec) do |p|
|
21
|
+
p.need_zip = true
|
22
|
+
p.need_tar = true
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Package and Install halcyon"
|
26
|
+
task :install do
|
27
|
+
name = "#{project[:name]}-#{project[:version]}.gem"
|
28
|
+
sh %{rake package}
|
29
|
+
sh %{sudo gem install pkg/#{name}}
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Uninstall the halcyon gem"
|
33
|
+
task :uninstall => [:clean] do
|
34
|
+
sh %{sudo gem uninstall #{project[:name]}}
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Generate RDoc documentation"
|
38
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
39
|
+
rdoc.options << '--line-numbers' << '--inline-source' <<
|
40
|
+
'--main' << 'README' <<
|
41
|
+
'--title' << 'Halcyon Documentation' <<
|
42
|
+
'--charset' << 'utf-8'
|
43
|
+
rdoc.rdoc_dir = "doc"
|
44
|
+
rdoc.rdoc_files.include 'README'
|
45
|
+
rdoc.rdoc_files.include('lib/halcyon.rb')
|
46
|
+
rdoc.rdoc_files.include('lib/halcyon/*.rb')
|
47
|
+
rdoc.rdoc_files.include('lib/halcyon/*/*.rb')
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => Rake::Task['spec']
|
data/init.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Silverpop
|
2
|
+
|
3
|
+
module ActionMailer
|
4
|
+
|
5
|
+
def perform_delivery_silverpop(mail)
|
6
|
+
@mailer ||= Silverpop::Mailer.new(self.class.options)
|
7
|
+
response = @mailer.mail(self.class.options[:campaign_id], mail, self.class.options)
|
8
|
+
raise response.errors.first[:message] unless response.errors.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(target) # :nodoc:
|
12
|
+
target.extend ClassMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
def set_silverpop_delivery_options(options = {})
|
18
|
+
cattr_accessor :options
|
19
|
+
self.options = options
|
20
|
+
|
21
|
+
raise ArgumentError.new("Missing required option :server") unless self.options[:server]
|
22
|
+
raise ArgumentError.new("Missing required option :campaign_id") unless self.options[:campaign_id]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Silverpop
|
2
|
+
|
3
|
+
class Mailer
|
4
|
+
|
5
|
+
attr_accessor :config, :request, :response
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
# config
|
9
|
+
self.config = options
|
10
|
+
|
11
|
+
# logger
|
12
|
+
Silverpop.logger.level = self.config[:log_level] || Logger::ERROR
|
13
|
+
|
14
|
+
# logging
|
15
|
+
Silverpop.logger.debug "Mailer init: #{self.config[:server]}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def mail(campaign_id, email, options = {})
|
19
|
+
self.request = Silverpop::Request.new(campaign_id, email, options)
|
20
|
+
self.response = Silverpop::Response.new(self.send(self.request.generate))
|
21
|
+
end
|
22
|
+
|
23
|
+
# Submits the request.
|
24
|
+
#
|
25
|
+
def send(request)
|
26
|
+
# TODO: implement into Silverpop::Transact
|
27
|
+
res = Net::HTTP.post_form(URI.parse(self.config[:server]), :xml => request)
|
28
|
+
res.body
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Silverpop
|
2
|
+
|
3
|
+
class Request
|
4
|
+
|
5
|
+
attr_accessor :campaign_id, :email, :options
|
6
|
+
|
7
|
+
def initialize(campaign_id, email, options = {})
|
8
|
+
self.campaign_id = campaign_id
|
9
|
+
self.email = email
|
10
|
+
self.options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate
|
14
|
+
result = ""
|
15
|
+
builder = Builder::XmlMarkup.new(:target => result, :indent => 2)
|
16
|
+
builder.XTMAILING do |xml|
|
17
|
+
xml.CAMPAIGN_ID(self.campaign_id)
|
18
|
+
xml.TRANSACTION_ID(self.options[:transaction_id]) if self.options[:transaction_id]
|
19
|
+
self.email.to.each do |recipient|
|
20
|
+
xml.RECIPIENT do |rec|
|
21
|
+
rec.EMAIL(recipient)
|
22
|
+
rec.BODY_TYPE("HTML")
|
23
|
+
rec.PERSONALIZATION do |per|
|
24
|
+
per.TAG_NAME("HTML_BODY")
|
25
|
+
per.VALUE do |per_val|
|
26
|
+
per_val.cdata! self.email.body
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
Silverpop.logger.debug "*** REQUEST:\n#{result}\n"
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sample Request
|
41
|
+
#
|
42
|
+
# <?xml version="1.0"?>
|
43
|
+
# <XTMAILING>
|
44
|
+
# <CAMPAIGN_ID>300401</CAMPAIGN_ID>
|
45
|
+
# <TRANSACTION_ID>trans-1234</TRANSACTION_ID>
|
46
|
+
# <SHOW_ALL_SEND_DETAIL>false</SHOW_ALL_SEND_DETAIL>
|
47
|
+
# <SEND_AS_BATCH>false</SEND_AS_BATCH>
|
48
|
+
# <NO_RETRY_ON_FAILURE>false</NO_RETRY_ON_FAILURE>
|
49
|
+
# <SAVE_COLUMNS>
|
50
|
+
# <COLUMN_NAME>NAME</COLUMN_NAME>
|
51
|
+
# <COLUMN_NAME>ADDRESS</COLUMN_NAME>
|
52
|
+
# </SAVE_COLUMNS>
|
53
|
+
# <RECIPIENT>
|
54
|
+
# <EMAIL>person@domain.com</EMAIL>
|
55
|
+
# <BODY_TYPE>HTML</BODY_TYPE>
|
56
|
+
# <PERSONALIZATION>
|
57
|
+
# <TAG_NAME>FLIGHT-NUMBER</TAG_NAME>
|
58
|
+
# <VALUE>Flight 807 </VALUE>
|
59
|
+
# </PERSONALIZATION>
|
60
|
+
# <PERSONALIZATION>
|
61
|
+
# <TAG_NAME>FLIGHT-INFORMATION</TAG_NAME>
|
62
|
+
# <VALUE><![CDATA[
|
63
|
+
# <HTML><span style="color:#000000;”>No meals on this flight</span></HTML>
|
64
|
+
# ]]></VALUE>
|
65
|
+
# </PERSONALIZATION>
|
66
|
+
# </RECIPIENT>
|
67
|
+
# </XTMAILING>
|
68
|
+
|
69
|
+
# Another example, specificying TRANSACT_MAIL_BODY
|
70
|
+
#
|
71
|
+
# <?xml version="1.0"?>
|
72
|
+
# <XTMAILING>
|
73
|
+
# <CAMPAIGN_ID>numeric campaign id</CAMPAIGN_ID>
|
74
|
+
# <TRANSACTION_ID>TRANS-1234</TRANSACTION_ID>
|
75
|
+
# <SHOW_ALL_SEND_DETAIL>false</SHOW_ALL_SEND_DETAIL>
|
76
|
+
# <SEND_AS_BATCH>false</SEND_AS_BATCH>
|
77
|
+
# <NO_RETRY_ON_FAILURE>false</NO_RETRY_ON_FAILURE>
|
78
|
+
# <SAVE_COLUMNS>
|
79
|
+
# <COLUMN_NAME>ACCOUNT_ID</COLUMN_NAME>
|
80
|
+
# </SAVE_COLUMNS>
|
81
|
+
# <RECIPIENT>
|
82
|
+
# <EMAIL>person@domain.com</EMAIL>
|
83
|
+
# <BODY_TYPE>HTML</BODY_TYPE>
|
84
|
+
# <PERSONALIZATION>
|
85
|
+
# <TAG_NAME>ACCOUNT_ID</TAG_NAME>
|
86
|
+
# <VALUE>807</VALUE>
|
87
|
+
# </PERSONALIZATION>
|
88
|
+
# <PERSONALIZATION>
|
89
|
+
# <TAG_NAME>TRANSACT_MAIL_BODY</TAG_NAME>
|
90
|
+
# <VALUE><![CDATA[
|
91
|
+
# <p>Here is a link, click it: <a
|
92
|
+
# href="http://recp.mkt32.net/ctt?m=%%MAILING_ID%%&r=%%RECIPIENT_ID%%&b=0&j=%%JOB_ID%%&k
|
93
|
+
# =The_Only_Link&kt=12&kd=http://www.spopdemo.com%3FAccountID%3D%25%25Account_ID%25%25">
|
94
|
+
# link</a><p>
|
95
|
+
# ]]></VALUE>
|
96
|
+
# </PERSONALIZATION>
|
97
|
+
# </RECIPIENT>
|
98
|
+
# </XTMAILING>
|
99
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Silverpop
|
2
|
+
|
3
|
+
class Response
|
4
|
+
|
5
|
+
attr_accessor :body, :status, :response, :errors
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
self.parse(response)
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(response)
|
12
|
+
Silverpop.logger.debug "*** RESPONSE:\n#{response}\n"
|
13
|
+
self.body = REXML::Document.new(response)
|
14
|
+
self.response = {
|
15
|
+
:status => self.body.root.elements['STATUS'][0].value,
|
16
|
+
:error_code => (self.body.root.elements['ERROR_CODE'][0].value rescue nil),
|
17
|
+
:error_string => (self.body.root.elements['ERROR_STRING'][0].value rescue nil)
|
18
|
+
}
|
19
|
+
self.status = self.response[:status].to_i
|
20
|
+
self.errors ||= []
|
21
|
+
self.errors << {:code => self.response[:error_code], :message => self.response[:error_string]}
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
"#<Silverpop::Response status:#{self.status} response=#{self.response.inspect}>"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sample Response Document
|
33
|
+
#
|
34
|
+
# <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
35
|
+
# <XTMAILING_RESPONSE>
|
36
|
+
# <CAMPAIGN_ID>0</CAMPAIGN_ID>
|
37
|
+
# <TRANSACTION_ID>unknown</TRANSACTION_ID>
|
38
|
+
# <RECIPIENTS_RECEIVED>0</RECIPIENTS_RECEIVED>
|
39
|
+
# <EMAILS_SENT>0</EMAILS_SENT>
|
40
|
+
# <NUMBER_ERRORS>0</NUMBER_ERRORS>
|
41
|
+
# <STATUS>2</STATUS>
|
42
|
+
# <ERROR_CODE>5</ERROR_CODE>
|
43
|
+
# <ERROR_STRING>Access not allowed to application for this ip 208.52.141.138</ERROR_STRING>
|
44
|
+
# </XTMAILING_RESPONSE>
|
data/lib/silverpop.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w(rubygems builder tmail rexml/document uri net/http net/https logger).each{|dep|require dep}
|
2
|
+
|
3
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__))))
|
4
|
+
|
5
|
+
module Silverpop
|
6
|
+
|
7
|
+
VERSION = [0,0,1]
|
8
|
+
|
9
|
+
autoload :Mailer, "silverpop/mailer"
|
10
|
+
autoload :Transact, "silverpop/transact"
|
11
|
+
autoload :Request, "silverpop/request"
|
12
|
+
autoload :Response, "silverpop/response"
|
13
|
+
|
14
|
+
autoload :ActionMailer, "silverpop/action_mailer"
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
def logger
|
19
|
+
@logger ||= Logger.new(STDOUT)
|
20
|
+
end
|
21
|
+
|
22
|
+
def version
|
23
|
+
VERSION.join('.')
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "silverpop_mailer"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2008-08-27"
|
5
|
+
s.summary = "SilverPOP Mailer Gem/Plugin for ActionMailer"
|
6
|
+
s.email = "mtodd@highgroove.com"
|
7
|
+
s.homepage = "http://github.com/mtodd/silverpop_mailer"
|
8
|
+
s.description = "A SilverPOP Mailer Gem/Plugin for sending emails with the ability to override ActionMailer"
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Matt Todd"]
|
11
|
+
s.files = ["init.rb",
|
12
|
+
"README",
|
13
|
+
"Rakefile",
|
14
|
+
"silverpop_mailer.gemspec",
|
15
|
+
"lib/silverpop/action_mailer.rb",
|
16
|
+
"lib/silverpop/mailer.rb",
|
17
|
+
"lib/silverpop/request.rb",
|
18
|
+
"lib/silverpop/response.rb",
|
19
|
+
"lib/silverpop/transact.rb",
|
20
|
+
"lib/silverpop.rb"]
|
21
|
+
s.rdoc_options = ["--main", "README"]
|
22
|
+
s.add_dependency("action_mailer", [">= 2.0.0"])
|
23
|
+
s.add_dependency("builder", [">= 2.1.2"])
|
24
|
+
s.add_dependency("tmail", [">= 1.2.3.1"])
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mtodd-silverpop_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Todd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-27 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: action_mailer
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: builder
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 2.1.2
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: tmail
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.3.1
|
41
|
+
version:
|
42
|
+
description: A SilverPOP Mailer Gem/Plugin for sending emails with the ability to override ActionMailer
|
43
|
+
email: mtodd@highgroove.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
files:
|
51
|
+
- init.rb
|
52
|
+
- README
|
53
|
+
- Rakefile
|
54
|
+
- silverpop_mailer.gemspec
|
55
|
+
- lib/silverpop/action_mailer.rb
|
56
|
+
- lib/silverpop/mailer.rb
|
57
|
+
- lib/silverpop/request.rb
|
58
|
+
- lib/silverpop/response.rb
|
59
|
+
- lib/silverpop/transact.rb
|
60
|
+
- lib/silverpop.rb
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://github.com/mtodd/silverpop_mailer
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --main
|
66
|
+
- README
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.2.0
|
85
|
+
signing_key:
|
86
|
+
specification_version: 2
|
87
|
+
summary: SilverPOP Mailer Gem/Plugin for ActionMailer
|
88
|
+
test_files: []
|
89
|
+
|