emaildirect 1.0.0
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/.gitignore +5 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +19 -0
- data/README.md +83 -0
- data/Rakefile +23 -0
- data/emaildirect.gemspec +23 -0
- data/lib/emaildirect.rb +104 -0
- data/lib/emaildirect/campaign.rb +135 -0
- data/lib/emaildirect/creative.rb +54 -0
- data/lib/emaildirect/creative_folder.rb +59 -0
- data/lib/emaildirect/database.rb +32 -0
- data/lib/emaildirect/filter.rb +42 -0
- data/lib/emaildirect/image_file.rb +46 -0
- data/lib/emaildirect/image_folder.rb +53 -0
- data/lib/emaildirect/import.rb +43 -0
- data/lib/emaildirect/list.rb +75 -0
- data/lib/emaildirect/mailer.rb +57 -0
- data/lib/emaildirect/publication.rb +79 -0
- data/lib/emaildirect/relay_send.rb +7 -0
- data/lib/emaildirect/relay_send/category.rb +51 -0
- data/lib/emaildirect/relay_send/email.rb +21 -0
- data/lib/emaildirect/relay_send/receipt.rb +39 -0
- data/lib/emaildirect/short_url.rb +53 -0
- data/lib/emaildirect/source.rb +65 -0
- data/lib/emaildirect/subscriber.rb +90 -0
- data/lib/emaildirect/suppression_list.rb +89 -0
- data/lib/emaildirect/version.rb +3 -0
- data/lib/emaildirect/workflow.rb +88 -0
- data/rails/init.rb +1 -0
- metadata +140 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EmailDirect
|
5
|
+
# Represents a creative folder and associated functionality
|
6
|
+
class CreativeFolder
|
7
|
+
class << self
|
8
|
+
def all(options = {})
|
9
|
+
response = EmailDirect.get '/Creatives/Folders', :query => options
|
10
|
+
Hashie::Mash.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(name, parent_id = nil)
|
14
|
+
uri = '/Creatives/Folders'
|
15
|
+
uri << "/#{parent_id}" if parent_id
|
16
|
+
response = EmailDirect.post uri, :body => name.to_json
|
17
|
+
Hashie::Mash.new(response)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :folder_id
|
22
|
+
|
23
|
+
def initialize(folder_id)
|
24
|
+
@folder_id = folder_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def details
|
28
|
+
response = get
|
29
|
+
Hashie::Mash.new(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def templates(options = {})
|
33
|
+
response = get 'Templates', options
|
34
|
+
Hashie::Mash.new(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update(name)
|
38
|
+
response = EmailDirect.put uri_for, :body => name.to_json
|
39
|
+
Hashie::Mash.new(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete
|
43
|
+
response = EmailDirect.delete uri_for, {}
|
44
|
+
Hashie::Mash.new(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def get(action = nil, options = {})
|
50
|
+
EmailDirect.get uri_for(action), :query => options
|
51
|
+
end
|
52
|
+
|
53
|
+
def uri_for(action = nil)
|
54
|
+
action = "/#{action}" if action
|
55
|
+
"/Creatives/Folders/#{folder_id}#{action}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EmailDirect
|
5
|
+
# Represents a database and associated functionality
|
6
|
+
class Database
|
7
|
+
class << self
|
8
|
+
def all
|
9
|
+
response = EmailDirect.get '/Databases'
|
10
|
+
Hashie::Mash.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(name, options = {})
|
14
|
+
options.merge! :ColumnName => name
|
15
|
+
response = EmailDirect.post '/Databases', :body => options.to_json
|
16
|
+
Hashie::Mash.new(response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :column_name
|
21
|
+
|
22
|
+
def initialize(column_name)
|
23
|
+
@column_name = column_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def details
|
27
|
+
response = EmailDirect.get "/Databases/#{column_name}"
|
28
|
+
Hashie::Mash.new(response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EmailDirect
|
5
|
+
# Represents a filter and associated functionality
|
6
|
+
class Filter
|
7
|
+
class << self
|
8
|
+
def all
|
9
|
+
response = EmailDirect.get '/Filters'
|
10
|
+
Hashie::Mash.new(response)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :filter_id
|
15
|
+
|
16
|
+
def initialize(filter_id)
|
17
|
+
@filter_id = filter_id
|
18
|
+
end
|
19
|
+
|
20
|
+
def details
|
21
|
+
response = get
|
22
|
+
Hashie::Mash.new(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def members(options = {})
|
26
|
+
response = get 'Members', options
|
27
|
+
Hashie::Mash.new(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def get(action = nil, options = {})
|
33
|
+
EmailDirect.get uri_for(action), :query => options
|
34
|
+
end
|
35
|
+
|
36
|
+
def uri_for(action = nil)
|
37
|
+
action = "/#{action}" if action
|
38
|
+
"/Filters/#{filter_id}#{action}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EmailDirect
|
5
|
+
# Represents a image file and associated functionality
|
6
|
+
class ImageFile
|
7
|
+
class << self
|
8
|
+
def create_from_url(url, options = {})
|
9
|
+
options.merge! :URL => url
|
10
|
+
response = EmailDirect.post uri, :body => options.to_json
|
11
|
+
Hashie::Mash.new(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_from_file(file_name, local_path, options = {})
|
15
|
+
options.merge! :FileName => file_name
|
16
|
+
EmailDirect.post '/ImageUpload', :query => options, :body => File.read(local_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def uri
|
20
|
+
'/ImageLibrary'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :file_path
|
25
|
+
|
26
|
+
def initialize(file_path)
|
27
|
+
@file_path = file_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def details
|
31
|
+
response = EmailDirect.get self.class.uri, query
|
32
|
+
Hashie::Mash.new(response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete
|
36
|
+
EmailDirect.delete self.class.uri, query
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def query
|
42
|
+
{ :query => { :File => file_path } }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EmailDirect
|
5
|
+
# Represents a image folder and associated functionality
|
6
|
+
class ImageFolder
|
7
|
+
class << self
|
8
|
+
def all(options = {})
|
9
|
+
response = EmailDirect.get uri, :query => options
|
10
|
+
Hashie::Mash.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(name, folder_path = nil)
|
14
|
+
options = { :body => name.to_json }
|
15
|
+
options[:query] = { :Folder => folder_path } if folder_path
|
16
|
+
response = EmailDirect.post uri, options
|
17
|
+
Hashie::Mash.new(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def uri
|
21
|
+
'/ImageLibrary/Folders'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :folder_path
|
26
|
+
|
27
|
+
def initialize(folder_path)
|
28
|
+
@folder_path = folder_path
|
29
|
+
end
|
30
|
+
|
31
|
+
def details
|
32
|
+
response = EmailDirect.get self.class.uri, query
|
33
|
+
Hashie::Mash.new(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def files
|
37
|
+
response = EmailDirect.get '/ImageLibrary/Files', query
|
38
|
+
Hashie::Mash.new(response)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete
|
42
|
+
response = EmailDirect.delete self.class.uri, query
|
43
|
+
Hashie::Mash.new(response)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def query
|
49
|
+
{ :query => { :Folder => folder_path } }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EmailDirect
|
5
|
+
# Represents an import and associated functionality
|
6
|
+
class Import
|
7
|
+
class << self
|
8
|
+
def add(subscribers)
|
9
|
+
options = { :Subscribers => subscribers.to_a }
|
10
|
+
response = EmailDirect.post uri_for('Subscribers'), :body => options.to_json
|
11
|
+
Hashie::Mash.new(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def update(subscribers)
|
15
|
+
options = { :Subscribers => subscribers.to_a }
|
16
|
+
response = EmailDirect.put uri_for('Subscribers'), :body => options.to_json
|
17
|
+
Hashie::Mash.new(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_or_update(subscribers)
|
21
|
+
options = { :Subscribers => subscribers.to_a }
|
22
|
+
response = EmailDirect.post uri_for('AddOrUpdate'), :body => options.to_json
|
23
|
+
Hashie::Mash.new(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove(email_addresses)
|
27
|
+
options = { :EmailAddresses => email_addresses.to_a }
|
28
|
+
response = EmailDirect.post uri_for('Remove'), :body => options.to_json
|
29
|
+
Hashie::Mash.new(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(email_addresses)
|
33
|
+
options = { :EmailAddresses => email_addresses.to_a }
|
34
|
+
response = EmailDirect.post uri_for('Delete'), :body => options.to_json
|
35
|
+
Hashie::Mash.new(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
def uri_for(action)
|
39
|
+
"/Import/#{action}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EmailDirect
|
5
|
+
# Represents a list and associated functionality
|
6
|
+
class List
|
7
|
+
class << self
|
8
|
+
def all(options = {})
|
9
|
+
response = EmailDirect.get '/Lists', :query => options
|
10
|
+
Hashie::Mash.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(name, options = {})
|
14
|
+
options.merge! :Name => name
|
15
|
+
response = EmailDirect.post '/Lists', :body => options.to_json
|
16
|
+
Hashie::Mash.new(response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :list_id
|
21
|
+
|
22
|
+
def initialize(list_id)
|
23
|
+
@list_id = list_id
|
24
|
+
end
|
25
|
+
|
26
|
+
def details
|
27
|
+
response = get
|
28
|
+
Hashie::Mash.new(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
def members
|
32
|
+
response = get 'Members'
|
33
|
+
Hashie::Mash.new(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def update(name, options)
|
37
|
+
options.merge! :Name => name
|
38
|
+
response = EmailDirect.put uri_for, :body => options.to_json
|
39
|
+
Hashie::Mash.new(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete
|
43
|
+
response = EmailDirect.delete uri_for, {}
|
44
|
+
Hashie::Mash.new(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_emails(email_addresses)
|
48
|
+
options = { :EmailAddresses => email_addresses.to_a }
|
49
|
+
response = post 'AddEmails', :body => options.to_json
|
50
|
+
Hashie::Mash.new(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_emails(email_addresses)
|
54
|
+
options = { :EmailAddresses => email_addresses.to_a }
|
55
|
+
response = post 'RemoveEmails', :body => options.to_json
|
56
|
+
Hashie::Mash.new(response)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def post(action, options)
|
62
|
+
EmailDirect.post uri_for(action), options
|
63
|
+
end
|
64
|
+
|
65
|
+
def get(action = nil)
|
66
|
+
EmailDirect.get uri_for(action)
|
67
|
+
end
|
68
|
+
|
69
|
+
def uri_for(action = nil)
|
70
|
+
action = "/#{action}" if action
|
71
|
+
"/Lists/#{list_id}#{action}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
|
3
|
+
module EmailDirect
|
4
|
+
# Implements a Mailer class that can be used by Mail to send using the relay functionality
|
5
|
+
class Mailer
|
6
|
+
def initialize(values = {})
|
7
|
+
self.settings = { :category_id => nil,
|
8
|
+
:options => {},
|
9
|
+
:logger => defined?(Rails) && Rails.logger,
|
10
|
+
:log_level => :debug
|
11
|
+
}.merge!(values)
|
12
|
+
raise ArgumentError, 'Category ID is required' unless settings[:category_id]
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :settings
|
16
|
+
|
17
|
+
def new(*args)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def deliver!(mail)
|
22
|
+
destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
|
23
|
+
Mail::Message
|
24
|
+
if destinations.blank?
|
25
|
+
raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message')
|
26
|
+
end
|
27
|
+
|
28
|
+
options = request_data mail
|
29
|
+
|
30
|
+
# Can only send to a max of 50 addresses at a time
|
31
|
+
destinations.each_slice(50).each do |destination_slice|
|
32
|
+
options[:Recipients] = []
|
33
|
+
destination_slice.each do |destination|
|
34
|
+
options[:Recipients] << { :ToEmail => destination }
|
35
|
+
end
|
36
|
+
response = RelaySend::Email.new(settings[:category_id]).send(options)
|
37
|
+
settings[:logger].send(settings[:log_level], "EmailDirect: #{response.inspect}") if settings[:logger]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def request_data(mail)
|
44
|
+
options = settings[:options].dup
|
45
|
+
options[:Subject] = mail.subject
|
46
|
+
options[:Text] = mail.multipart? ? mail.text_part.body.to_s : mail.body.to_s
|
47
|
+
options[:HTML] = mail.multipart? ? mail.html_part.body.to_s : mail.body.to_s
|
48
|
+
# Set the envelope from to be either the return-path, the sender or the first from address
|
49
|
+
envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
|
50
|
+
unless envelope_from.blank?
|
51
|
+
options[:FromEmail] = envelope_from
|
52
|
+
options[:FromName] = mail[:from].display_names.first if mail[:from].display_names.present?
|
53
|
+
end
|
54
|
+
options
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'emaildirect'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EmailDirect
|
5
|
+
# Represents a publication and associated functionality
|
6
|
+
class Publication
|
7
|
+
class << self
|
8
|
+
def all(options = {})
|
9
|
+
response = EmailDirect.get '/Publications', :query => options
|
10
|
+
Hashie::Mash.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(name, options = {})
|
14
|
+
options.merge! :Name => name
|
15
|
+
response = EmailDirect.post '/Publications', :body => options.to_json
|
16
|
+
Hashie::Mash.new(response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :publication_id
|
21
|
+
|
22
|
+
def initialize(publication_id)
|
23
|
+
@publication_id = publication_id
|
24
|
+
end
|
25
|
+
|
26
|
+
def details
|
27
|
+
response = get
|
28
|
+
Hashie::Mash.new(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
def members(options = {})
|
32
|
+
response = get 'Members', :query => options
|
33
|
+
Hashie::Mash.new(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def removes(options = {})
|
37
|
+
response = get 'Removes', :query => options
|
38
|
+
Hashie::Mash.new(response)
|
39
|
+
end
|
40
|
+
|
41
|
+
def update(name, options)
|
42
|
+
options.merge! :Name => name
|
43
|
+
response = EmailDirect.put uri_for, :body => options.to_json
|
44
|
+
Hashie::Mash.new(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete
|
48
|
+
response = EmailDirect.delete uri_for, {}
|
49
|
+
Hashie::Mash.new(response)
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_emails(email_addresses)
|
53
|
+
options = { :EmailAddresses => email_addresses.to_a }
|
54
|
+
response = post 'AddEmails', :body => options.to_json
|
55
|
+
Hashie::Mash.new(response)
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_emails(email_addresses)
|
59
|
+
options = { :EmailAddresses => email_addresses.to_a }
|
60
|
+
response = post 'RemoveEmails', :body => options.to_json
|
61
|
+
Hashie::Mash.new(response)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def post(action, options)
|
67
|
+
EmailDirect.post uri_for(action), options
|
68
|
+
end
|
69
|
+
|
70
|
+
def get(action = nil, options = {})
|
71
|
+
EmailDirect.get uri_for(action), options
|
72
|
+
end
|
73
|
+
|
74
|
+
def uri_for(action = nil)
|
75
|
+
action = "/#{action}" if action
|
76
|
+
"/Publications/#{publication_id}#{action}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|