mailfox 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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/mailfox/application.js +15 -0
- data/app/assets/stylesheets/mailfox/application.css +15 -0
- data/app/cms/snippets/newsletter_partial.snippet +6 -0
- data/app/controllers/mailfox/application_controller.rb +5 -0
- data/app/controllers/mailfox/newsletters_controller.rb +71 -0
- data/app/helpers/mailfox/application_helper.rb +13 -0
- data/app/services/mail_service.rb +16 -0
- data/app/services/mail_service/customer.rb +103 -0
- data/app/services/mail_service/list.rb +128 -0
- data/app/services/mail_service/member.rb +224 -0
- data/app/views/layouts/mailfox/application.html.erb +14 -0
- data/app/views/mailfox/newsletters/_form.html.erb +6 -0
- data/app/views/mailfox/newsletters/cms/_form.html.erb +1 -0
- data/app/views/mailfox/newsletters/create.js.erb +16 -0
- data/config/routes.rb +6 -0
- data/lib/mailfox.rb +10 -0
- data/lib/mailfox/engine.rb +13 -0
- data/lib/mailfox/gem_version.rb +14 -0
- data/lib/mailfox/version.rb +7 -0
- data/lib/tasks/mailfox_tasks.rake +4 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1ace07536211ef8f493dc0df1cb9f2421eb709fe
|
4
|
+
data.tar.gz: 4cbb42a06cf3ad587643c00e8c89bdbb9d25b166
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: af1a2c0c9f40e0527ddecc9163915845e8c3e828b4f329e680dfcc797e8863ae8bcdd57dd0313576a832c9c36591aad5c4e269a39822e6fc09b2e4bdedccce16
|
7
|
+
data.tar.gz: 2a7cfe37ff6350e8be7fd5f51d65b0ce7f8f7e8b927a6004c7dc1f5eda5da2d142dd9e470fc39398939bebff35cec565fe2fc204bfc2a53be15c5dc2e56f2c49
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Adam Bahlke
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Mailfox'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
task :routes => 'app:environment' do
|
28
|
+
Rails.application.reload_routes!
|
29
|
+
all_routes = Mailfox::Engine.routes.routes
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Mailfox
|
2
|
+
class NewslettersController < Mailfox::ApplicationController
|
3
|
+
|
4
|
+
#
|
5
|
+
# Settings
|
6
|
+
# ---------------------------------------------------------------------------------------
|
7
|
+
#
|
8
|
+
#
|
9
|
+
#
|
10
|
+
#
|
11
|
+
|
12
|
+
layout false
|
13
|
+
|
14
|
+
#
|
15
|
+
# Filter
|
16
|
+
# ---------------------------------------------------------------------------------------
|
17
|
+
#
|
18
|
+
#
|
19
|
+
#
|
20
|
+
#
|
21
|
+
|
22
|
+
#
|
23
|
+
# Plugins
|
24
|
+
# ---------------------------------------------------------------------------------------
|
25
|
+
#
|
26
|
+
#
|
27
|
+
#
|
28
|
+
#
|
29
|
+
|
30
|
+
#
|
31
|
+
# Actions
|
32
|
+
# ---------------------------------------------------------------------------------------
|
33
|
+
#
|
34
|
+
#
|
35
|
+
#
|
36
|
+
#
|
37
|
+
|
38
|
+
def create
|
39
|
+
@customer = MailService::Customer.create(permitted_params)
|
40
|
+
|
41
|
+
respond_to do |format|
|
42
|
+
format.js
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Protected
|
48
|
+
# ---------------------------------------------------------------------------------------
|
49
|
+
#
|
50
|
+
#
|
51
|
+
#
|
52
|
+
#
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
#
|
57
|
+
# Private
|
58
|
+
# ---------------------------------------------------------------------------------------
|
59
|
+
#
|
60
|
+
#
|
61
|
+
#
|
62
|
+
#
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def permitted_params
|
67
|
+
params.require(:newsletter).permit(:email, :list_id)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Mailfox
|
2
|
+
module ApplicationHelper
|
3
|
+
def error_messages_for(object, options = {})
|
4
|
+
messages = options[:length] ? [object.errors.full_messages[options[:length] - 1]] : object.errors.full_messages
|
5
|
+
|
6
|
+
content_tag :ul, class: 'error-messages' do
|
7
|
+
messages.each do |msg|
|
8
|
+
concat content_tag(:li, msg)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mail_service/member'
|
2
|
+
require 'mail_service/customer'
|
3
|
+
|
4
|
+
module MailService
|
5
|
+
autoload :Member, 'mail_service/member'
|
6
|
+
autoload :Customer, 'mail_service/customer'
|
7
|
+
|
8
|
+
Gibbon::API.api_key = Mailfox.mailservices['mailchimp']['api_key']
|
9
|
+
Gibbon::API.timeout = 15
|
10
|
+
Gibbon::API.throws_exceptions = false
|
11
|
+
|
12
|
+
def self.connection(api_key = nil)
|
13
|
+
Gibbon::API.new(api_key)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module MailService
|
2
|
+
class Customer < Member
|
3
|
+
|
4
|
+
#
|
5
|
+
# Concerns
|
6
|
+
# ---------------------------------------------------------------------------------------
|
7
|
+
#
|
8
|
+
#
|
9
|
+
#
|
10
|
+
#
|
11
|
+
|
12
|
+
#
|
13
|
+
# Constants
|
14
|
+
# ---------------------------------------------------------------------------------------
|
15
|
+
#
|
16
|
+
#
|
17
|
+
#
|
18
|
+
#
|
19
|
+
|
20
|
+
#
|
21
|
+
# Index
|
22
|
+
# ---------------------------------------------------------------------------------------
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#
|
26
|
+
#
|
27
|
+
|
28
|
+
#
|
29
|
+
# Attribute Settings
|
30
|
+
# ---------------------------------------------------------------------------------------
|
31
|
+
#
|
32
|
+
#
|
33
|
+
#
|
34
|
+
#
|
35
|
+
|
36
|
+
#
|
37
|
+
# Validations
|
38
|
+
# ---------------------------------------------------------------------------------------
|
39
|
+
#
|
40
|
+
#
|
41
|
+
#
|
42
|
+
#
|
43
|
+
|
44
|
+
#
|
45
|
+
# Callbacks
|
46
|
+
# ---------------------------------------------------------------------------------------
|
47
|
+
#
|
48
|
+
#
|
49
|
+
#
|
50
|
+
#
|
51
|
+
|
52
|
+
#
|
53
|
+
# Constructor
|
54
|
+
# ---------------------------------------------------------------------------------------
|
55
|
+
#
|
56
|
+
#
|
57
|
+
#
|
58
|
+
#
|
59
|
+
|
60
|
+
def initialize(attributes = {})
|
61
|
+
defaults = { list_id: Mailfox.mailservices['mailchimp']['list_id']['customer'] }
|
62
|
+
attributes = defaults.merge(attributes).symbolize_keys
|
63
|
+
|
64
|
+
super
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Instance Methods
|
69
|
+
# ---------------------------------------------------------------------------------------
|
70
|
+
#
|
71
|
+
#
|
72
|
+
#
|
73
|
+
#
|
74
|
+
|
75
|
+
#
|
76
|
+
# Class Methods
|
77
|
+
# ---------------------------------------------------------------------------------------
|
78
|
+
#
|
79
|
+
#
|
80
|
+
#
|
81
|
+
#
|
82
|
+
#
|
83
|
+
# Protected Methods
|
84
|
+
# ---------------------------------------------------------------------------------------
|
85
|
+
#
|
86
|
+
#
|
87
|
+
#
|
88
|
+
#
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
#
|
93
|
+
# Private Methods
|
94
|
+
# ---------------------------------------------------------------------------------------
|
95
|
+
#
|
96
|
+
#
|
97
|
+
#
|
98
|
+
#
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module MailService
|
2
|
+
class List
|
3
|
+
|
4
|
+
#
|
5
|
+
# Concerns
|
6
|
+
# ---------------------------------------------------------------------------------------
|
7
|
+
#
|
8
|
+
#
|
9
|
+
#
|
10
|
+
#
|
11
|
+
|
12
|
+
include ActiveModel::Model
|
13
|
+
|
14
|
+
#
|
15
|
+
# Constants
|
16
|
+
# ---------------------------------------------------------------------------------------
|
17
|
+
#
|
18
|
+
#
|
19
|
+
#
|
20
|
+
#
|
21
|
+
|
22
|
+
#
|
23
|
+
# Index
|
24
|
+
# ---------------------------------------------------------------------------------------
|
25
|
+
#
|
26
|
+
#
|
27
|
+
#
|
28
|
+
#
|
29
|
+
|
30
|
+
#
|
31
|
+
# Attribute Settings
|
32
|
+
# ---------------------------------------------------------------------------------------
|
33
|
+
#
|
34
|
+
#
|
35
|
+
#
|
36
|
+
#
|
37
|
+
|
38
|
+
#
|
39
|
+
# Validations
|
40
|
+
# ---------------------------------------------------------------------------------------
|
41
|
+
#
|
42
|
+
#
|
43
|
+
#
|
44
|
+
#
|
45
|
+
|
46
|
+
#
|
47
|
+
# Callbacks
|
48
|
+
# ---------------------------------------------------------------------------------------
|
49
|
+
#
|
50
|
+
#
|
51
|
+
#
|
52
|
+
#
|
53
|
+
|
54
|
+
#
|
55
|
+
# Constructor
|
56
|
+
# ---------------------------------------------------------------------------------------
|
57
|
+
#
|
58
|
+
#
|
59
|
+
#
|
60
|
+
#
|
61
|
+
|
62
|
+
#
|
63
|
+
# Instance Methods
|
64
|
+
# ---------------------------------------------------------------------------------------
|
65
|
+
#
|
66
|
+
#
|
67
|
+
#
|
68
|
+
#
|
69
|
+
|
70
|
+
#
|
71
|
+
# Class Methods
|
72
|
+
# ---------------------------------------------------------------------------------------
|
73
|
+
#
|
74
|
+
#
|
75
|
+
#
|
76
|
+
#
|
77
|
+
|
78
|
+
def self.exists?(id)
|
79
|
+
find_by_id(id).present?
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.find_by_id(id)
|
83
|
+
return nil unless id
|
84
|
+
|
85
|
+
response = fetch(filters: { list_id: id }).try(:with_indifferent_access)
|
86
|
+
response[:data].try(:map, &:with_indifferent_access).try(:first) if response[:total] == 1
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.all(options = {})
|
90
|
+
fetch(options)[:data].try(:map, &:with_indifferent_access)
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.count(options = {})
|
94
|
+
fetch(options)[:total]
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.fetch(options = {})
|
98
|
+
begin
|
99
|
+
parent.connection.lists.list(options).with_indifferent_access
|
100
|
+
rescue => e
|
101
|
+
Rails.logger.info "**[MailService Error][Exists] #{e.message}"
|
102
|
+
Rails.logger.warn "**[MailService Error][Exists] #{e.backtrace.join("\n")}" if Rails.env.development?
|
103
|
+
{}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Protected Methods
|
109
|
+
# ---------------------------------------------------------------------------------------
|
110
|
+
#
|
111
|
+
#
|
112
|
+
#
|
113
|
+
#
|
114
|
+
|
115
|
+
protected
|
116
|
+
|
117
|
+
#
|
118
|
+
# Private Methods
|
119
|
+
# ---------------------------------------------------------------------------------------
|
120
|
+
#
|
121
|
+
#
|
122
|
+
#
|
123
|
+
#
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
module MailService
|
2
|
+
class Member
|
3
|
+
|
4
|
+
#
|
5
|
+
# Concerns
|
6
|
+
# ---------------------------------------------------------------------------------------
|
7
|
+
#
|
8
|
+
#
|
9
|
+
#
|
10
|
+
#
|
11
|
+
|
12
|
+
include ActiveModel::Model
|
13
|
+
|
14
|
+
#
|
15
|
+
# Constants
|
16
|
+
# ---------------------------------------------------------------------------------------
|
17
|
+
#
|
18
|
+
#
|
19
|
+
#
|
20
|
+
#
|
21
|
+
|
22
|
+
#
|
23
|
+
# Index
|
24
|
+
# ---------------------------------------------------------------------------------------
|
25
|
+
#
|
26
|
+
#
|
27
|
+
#
|
28
|
+
#
|
29
|
+
|
30
|
+
#
|
31
|
+
# Attribute Settings
|
32
|
+
# ---------------------------------------------------------------------------------------
|
33
|
+
#
|
34
|
+
#
|
35
|
+
#
|
36
|
+
#
|
37
|
+
|
38
|
+
attr_accessor :email, :list_id, :locale
|
39
|
+
|
40
|
+
attr_reader :connection, :subscriber_id, :double_optin
|
41
|
+
|
42
|
+
alias_method :name, :email
|
43
|
+
|
44
|
+
#
|
45
|
+
# Validations
|
46
|
+
# ---------------------------------------------------------------------------------------
|
47
|
+
#
|
48
|
+
#
|
49
|
+
#
|
50
|
+
#
|
51
|
+
|
52
|
+
validates :email, :list_id, presence: true
|
53
|
+
|
54
|
+
validates :email, email: true, allow_blank: true
|
55
|
+
|
56
|
+
validate :uniqueness_of_email
|
57
|
+
|
58
|
+
#
|
59
|
+
# Callbacks
|
60
|
+
# ---------------------------------------------------------------------------------------
|
61
|
+
#
|
62
|
+
#
|
63
|
+
#
|
64
|
+
#
|
65
|
+
|
66
|
+
#
|
67
|
+
# Constructor
|
68
|
+
# ---------------------------------------------------------------------------------------
|
69
|
+
#
|
70
|
+
#
|
71
|
+
#
|
72
|
+
#
|
73
|
+
|
74
|
+
def initialize(attributes = {})
|
75
|
+
defaults = {
|
76
|
+
locale: I18n.locale,
|
77
|
+
double_optin: true
|
78
|
+
}
|
79
|
+
|
80
|
+
attributes = defaults.merge(attributes).symbolize_keys
|
81
|
+
|
82
|
+
@email = attributes[:email]
|
83
|
+
@locale = attributes[:locale]
|
84
|
+
@connection = self.class.parent.connection
|
85
|
+
@double_optin = attributes[:double_optin]
|
86
|
+
@list_id = attributes[:list_id]
|
87
|
+
|
88
|
+
yield self if block_given?
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Instance Methods
|
93
|
+
# ---------------------------------------------------------------------------------------
|
94
|
+
#
|
95
|
+
#
|
96
|
+
#
|
97
|
+
#
|
98
|
+
|
99
|
+
def list
|
100
|
+
List.find_by_list_id(list_id) if list_id
|
101
|
+
end
|
102
|
+
|
103
|
+
def info
|
104
|
+
begin
|
105
|
+
unless @info
|
106
|
+
response = connection.lists.member_info(id: list_id, emails: [{ email: email}]).with_indifferent_access
|
107
|
+
@info = response[:data].first if response[:success_count] && response[:success_count] >= 1
|
108
|
+
end
|
109
|
+
rescue => e
|
110
|
+
Rails.logger.info "**[MailService Error][Info] #{e.message}"
|
111
|
+
Rails.logger.warn "**[MailService Error][Info] #{e.backtrace.join("\n")}" if Rails.env.development?
|
112
|
+
end
|
113
|
+
|
114
|
+
@info || {}
|
115
|
+
end
|
116
|
+
|
117
|
+
def persisted?
|
118
|
+
false
|
119
|
+
end
|
120
|
+
|
121
|
+
def save
|
122
|
+
return false unless valid?
|
123
|
+
|
124
|
+
return true if Rails.env.test?
|
125
|
+
|
126
|
+
begin
|
127
|
+
connection.lists.subscribe(
|
128
|
+
id: list_id,
|
129
|
+
email: { email: email },
|
130
|
+
double_optin: double_optin,
|
131
|
+
merge_vars: { mc_language: locale }
|
132
|
+
)
|
133
|
+
rescue => e
|
134
|
+
Rails.logger.info "**[MailService Error][Save] #{e.message}"
|
135
|
+
Rails.logger.warn "**[MailService Error][Save] #{e.backtrace.join("\n")}" if Rails.env.development?
|
136
|
+
false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def destroy
|
141
|
+
begin
|
142
|
+
connection.lists.unsubscribe(
|
143
|
+
id: list_id,
|
144
|
+
email: { email: email }
|
145
|
+
)
|
146
|
+
rescue => e
|
147
|
+
Rails.logger.info "**[MailService Error][Destroy] #{e.message}"
|
148
|
+
Rails.logger.warn "**[MailService Error][Destroy] #{e.backtrace.join("\n")}" if Rails.env.development?
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def confirmed?
|
153
|
+
info[:timestamp_opt].present?
|
154
|
+
end
|
155
|
+
|
156
|
+
def method_missing(method_name, *args, &block)
|
157
|
+
if info.keys.include?(method_name.to_s)
|
158
|
+
info[method_name]
|
159
|
+
else
|
160
|
+
super
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# Class Methods
|
166
|
+
# ---------------------------------------------------------------------------------------
|
167
|
+
#
|
168
|
+
#
|
169
|
+
#
|
170
|
+
#
|
171
|
+
|
172
|
+
def self.create(attributes = {})
|
173
|
+
mailservice = new(attributes)
|
174
|
+
mailservice.save
|
175
|
+
mailservice
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.find_by_email(email)
|
179
|
+
new(new(email: email).info.symbolize_keys)
|
180
|
+
end
|
181
|
+
|
182
|
+
def self.exists?(options = {})
|
183
|
+
return false if options.blank?
|
184
|
+
|
185
|
+
begin
|
186
|
+
new(options.slice(:email, :list_id)).info.present?
|
187
|
+
rescue => e
|
188
|
+
Rails.logger.info "**[MailService Error][Exists] #{e.message}"
|
189
|
+
Rails.logger.warn "**[MailService Error][Exists] #{e.backtrace.join("\n")}" if Rails.env.development?
|
190
|
+
e.message
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
#
|
195
|
+
# Protected Methods
|
196
|
+
# ---------------------------------------------------------------------------------------
|
197
|
+
#
|
198
|
+
#
|
199
|
+
#
|
200
|
+
#
|
201
|
+
|
202
|
+
protected
|
203
|
+
|
204
|
+
#
|
205
|
+
# Private Methods
|
206
|
+
# ---------------------------------------------------------------------------------------
|
207
|
+
#
|
208
|
+
#
|
209
|
+
#
|
210
|
+
#
|
211
|
+
|
212
|
+
private
|
213
|
+
|
214
|
+
def uniqueness_of_email
|
215
|
+
existence = self.class.exists?(email: email, list_id: list_id)
|
216
|
+
|
217
|
+
case existence
|
218
|
+
when TrueClass then errors.add(:email, :taken)
|
219
|
+
when String then errors.add(:email, existence)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Mailfox</title>
|
5
|
+
<%= stylesheet_link_tag "mailfox/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "mailfox/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%= form_for MailService::Customer.new, url: mailfox.newsletter_subscribe_path, as: :newsletter, remote: true, html: { class: 'mailfox-newsletter-form' } do |f| %>
|
2
|
+
<%= f.hidden_field :list_id, value: list_id %>
|
3
|
+
<%= f.text_field :email, placeholder: placeholder, class: 'mailfox-newsletter-input' %>
|
4
|
+
<%= f.submit submit_button_message, class: 'mailfox-newsletter-submit', data: { disable_with: disable_with_message } %>
|
5
|
+
<div class="mailfox-newsletter-msg"></div>
|
6
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render partial: "mailfox/newsletters/form", locals: {placeholder: cms_block_content("newsletter.placeholder"), list_id: cms_block_content("newsletter.list_id"), disable_with_message: cms_block_content("newsletter.disable_with_message"), submit_button_message: cms_block_content("newsletter.button")} %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% if @customer.errors.empty? %>
|
2
|
+
|
3
|
+
$('.mailfox-newsletter-msg').html('<%= t(".success") %>');
|
4
|
+
$('.mailfox-newsletter-input').val('');
|
5
|
+
$('.mailfox-newsletter-form').removeClass('mailfox-newsletter-error').addClass('mailfox-newsletter-success');
|
6
|
+
|
7
|
+
setTimeout(function() {
|
8
|
+
$('.mailfox-newsletter-form').removeClass('mailfox-newsletter-success');
|
9
|
+
}, 5000);
|
10
|
+
|
11
|
+
<% else %>
|
12
|
+
|
13
|
+
$('.mailfox-newsletter-msg').html('<%= error_messages_for(@customer, length: 1).html_safe %>');
|
14
|
+
$('.mailfox-newsletter-form').removeClass('mailfox-newsletter-success').addClass('mailfox-newsletter-error');
|
15
|
+
|
16
|
+
<% end %>
|
data/config/routes.rb
ADDED
data/lib/mailfox.rb
ADDED
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailfox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Bahlke
|
8
|
+
- Michael Rüffer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '4.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sqlite3
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: gibbon
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.1.5
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.1.5
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: jquery-rails
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '4.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '4.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: email_validator
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.6.0
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.6.0
|
84
|
+
description: An easy-to-implement, reusable newsletter subscribe widget that connects
|
85
|
+
with Mailchimp.
|
86
|
+
email:
|
87
|
+
- develop@hitfoxgroup.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- MIT-LICENSE
|
93
|
+
- Rakefile
|
94
|
+
- app/assets/javascripts/mailfox/application.js
|
95
|
+
- app/assets/stylesheets/mailfox/application.css
|
96
|
+
- app/cms/snippets/newsletter_partial.snippet
|
97
|
+
- app/controllers/mailfox/application_controller.rb
|
98
|
+
- app/controllers/mailfox/newsletters_controller.rb
|
99
|
+
- app/helpers/mailfox/application_helper.rb
|
100
|
+
- app/services/mail_service.rb
|
101
|
+
- app/services/mail_service/customer.rb
|
102
|
+
- app/services/mail_service/list.rb
|
103
|
+
- app/services/mail_service/member.rb
|
104
|
+
- app/views/layouts/mailfox/application.html.erb
|
105
|
+
- app/views/mailfox/newsletters/_form.html.erb
|
106
|
+
- app/views/mailfox/newsletters/cms/_form.html.erb
|
107
|
+
- app/views/mailfox/newsletters/create.js.erb
|
108
|
+
- config/routes.rb
|
109
|
+
- lib/mailfox.rb
|
110
|
+
- lib/mailfox/engine.rb
|
111
|
+
- lib/mailfox/gem_version.rb
|
112
|
+
- lib/mailfox/version.rb
|
113
|
+
- lib/tasks/mailfox_tasks.rake
|
114
|
+
homepage: http://hitfoxgroup.com
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.4.8
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Quickly plugin Mailchimp, including a CMS-snippet
|
138
|
+
test_files: []
|