correole 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/correole +3 -0
- data/config/configuration.rb +11 -5
- data/config/dependencies.rb +1 -0
- data/config/example.config.yml +3 -0
- data/config/test.config.yml +4 -1
- data/lib/correole/api.rb +6 -2
- data/lib/correole/send.rb +27 -17
- data/lib/correole/version.rb +2 -2
- metadata +20 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f8f2fe3a7de80d7791152fd8a3763666393e9126af594aa3f67b4cba3e468342
|
4
|
+
data.tar.gz: beb208a8c5f5798cd60f8ace8a62b7b949f1c363a2c85e8e2bc85267fb22de6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3b3d63f74a0be04f81a0ccee3cb48d467f3920701e6cc3cd0bf8a1e516effc8a0c8cecb3c3725e8e0d410d987811a38267dd26702abf06d2d412311a6deddb2
|
7
|
+
data.tar.gz: 32bdbf7124e7aed3474111af567c7cb8b1390d92807764285af43efe19be0c562c2dc8079667edaf07a7a3dd2857a1559ecbd5276dbb52a1d5b0086957604691
|
data/bin/correole
CHANGED
data/config/configuration.rb
CHANGED
@@ -6,9 +6,15 @@ ENV['CONFIG_FILE'] ||= File.expand_path "../#{DEFAULT_CONFIG_FILE}", __FILE__
|
|
6
6
|
|
7
7
|
class Configuration
|
8
8
|
|
9
|
-
|
9
|
+
BOOLEAN_KEYS = [
|
10
10
|
'QUIET',
|
11
|
+
'DRY_RUN',
|
12
|
+
'SMTP_TTLS'
|
13
|
+
]
|
14
|
+
CONFIG_KEYS = [
|
15
|
+
'DRY_RUN_EMAIL',
|
11
16
|
'FEED',
|
17
|
+
'UNSUBSCRIBE_URI',
|
12
18
|
'CONFIRMATION_URI',
|
13
19
|
'BASE_URI',
|
14
20
|
'SUBJECT',
|
@@ -20,7 +26,7 @@ class Configuration
|
|
20
26
|
'SMTP_USER',
|
21
27
|
'SMTP_PASS',
|
22
28
|
'SMTP_AUTH',
|
23
|
-
|
29
|
+
] + BOOLEAN_KEYS
|
24
30
|
|
25
31
|
class << self
|
26
32
|
CONFIG_KEYS.each do |k|
|
@@ -31,12 +37,12 @@ class Configuration
|
|
31
37
|
def self.load!
|
32
38
|
|
33
39
|
YAML.load_file(ENV['CONFIG_FILE'])[ENV['RACK_ENV']].each_pair do |k, v|
|
34
|
-
ENV[k.upcase] ||= v.to_s rescue abort
|
35
|
-
end rescue qputs "
|
40
|
+
ENV[k.upcase] ||= v.to_s rescue abort("Cannot load configuration key #{k}.")
|
41
|
+
end rescue qputs "Cannot load configuration file #{ENV['CONFIG_FILE']}. Using configuration given by environment."
|
36
42
|
|
37
43
|
CONFIG_KEYS.each do |k|
|
38
44
|
case k
|
39
|
-
when
|
45
|
+
when *BOOLEAN_KEYS
|
40
46
|
# Cannot store boolean values in ENV, thus this.
|
41
47
|
self.send("#{k.downcase}=".to_sym, ENV[k] == 'true')
|
42
48
|
when 'HTML_TEMPLATE', 'PLAIN_TEMPLATE'
|
data/config/dependencies.rb
CHANGED
data/config/example.config.yml
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
production: &prod
|
2
2
|
quiet: false
|
3
|
+
dry_run: false
|
4
|
+
dry_run_email: your.email@mail.com
|
3
5
|
base_uri: http://newsletter.ruslanledesma.com
|
4
6
|
feed: http://ruslanledesma.com/feed.xml
|
7
|
+
unsubscribe_uri: 'http://ruslanledesma.com/unsubscribe/?email=<%= recipient %>'
|
5
8
|
confirmation_uri: http://ruslanledesma.com/unsubscribed/
|
6
9
|
subject: '<%= title %>: newsletter for <%= date %>'
|
7
10
|
from: '<%= title %> <no-reply@ruslanledesma.com>'
|
data/config/test.config.yml
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
test:
|
2
2
|
quiet: true
|
3
|
+
dry_run: false
|
4
|
+
dry_run_email: test@mail.com
|
3
5
|
base_uri: http://test.ruslanledesma.com
|
4
6
|
feed: http://ruslanledesma.com/feed.xml # reset by env for end-to-end test
|
5
|
-
|
7
|
+
unsubscribe_uri: 'http://newsletter.ruslanledesma.com/unsubscribe/?email=<%= recipient %>'
|
8
|
+
confirmation_uri: http://newsletter.ruslanledesma.com/unsubscribed/
|
6
9
|
subject: 'Test <%= title %> - <%= date %>'
|
7
10
|
from: '<%= title %> <no-reply@ruslanledesma.com>'
|
8
11
|
html_template: test.html.erb
|
data/lib/correole/api.rb
CHANGED
@@ -9,7 +9,7 @@ class Api < Sinatra::Base
|
|
9
9
|
set :server, :thin
|
10
10
|
enable :logging
|
11
11
|
disable :show_exceptions
|
12
|
-
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
12
|
+
# use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
13
13
|
|
14
14
|
before do
|
15
15
|
content_type 'text/plain'
|
@@ -26,7 +26,7 @@ class Api < Sinatra::Base
|
|
26
26
|
logger.info("Already subscribed #{params[:email]}.")
|
27
27
|
Subscriber.find_by_email(params[:email]).touch
|
28
28
|
end
|
29
|
-
"#{params[:email]}\n"
|
29
|
+
[201, "#{params[:email]}\n"]
|
30
30
|
end
|
31
31
|
|
32
32
|
def unsubscribe(params)
|
@@ -44,16 +44,19 @@ class Api < Sinatra::Base
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def subscribers_method_not_allowed
|
47
|
+
response.headers['Allow'] = SUBSCRIBERS_ALLOWED_METHODS
|
47
48
|
response.headers['Access-Control-Allow-Methods'] = SUBSCRIBERS_ALLOWED_METHODS
|
48
49
|
405
|
49
50
|
end
|
50
51
|
|
51
52
|
def unsubscribe_method_not_allowed
|
53
|
+
response.headers['Allow'] = UNSUBSCRIBE_ALLOWED_METHODS
|
52
54
|
response.headers['Access-Control-Allow-Methods'] = UNSUBSCRIBE_ALLOWED_METHODS
|
53
55
|
405
|
54
56
|
end
|
55
57
|
|
56
58
|
options '/subscribers/:email' do
|
59
|
+
response.headers['Allow'] = SUBSCRIBERS_ALLOWED_METHODS
|
57
60
|
response.headers['Access-Control-Allow-Methods'] = SUBSCRIBERS_ALLOWED_METHODS
|
58
61
|
response.headers['Access-Control-Allow-Origin'] = SUBSCRIBERS_ALLOWED_ORIGIN
|
59
62
|
200
|
@@ -77,6 +80,7 @@ class Api < Sinatra::Base
|
|
77
80
|
end
|
78
81
|
|
79
82
|
options "#{UNSUBSCRIBE_PATH}/:email" do
|
83
|
+
response.headers['Allow'] = UNSUBSCRIBE_ALLOWED_METHODS
|
80
84
|
response.headers['Access-Control-Allow-Methods'] = UNSUBSCRIBE_ALLOWED_METHODS
|
81
85
|
response.headers['Access-Control-Allow-Origin'] = UNSUBSCRIBE_ALLOWED_ORIGIN
|
82
86
|
200
|
data/lib/correole/send.rb
CHANGED
@@ -12,47 +12,57 @@ class Send
|
|
12
12
|
split_feed[:unsent_item].each_with_index { |i, j| qputs "[#{j+1}] #{i.link}" }
|
13
13
|
html = compose_html split_feed
|
14
14
|
plain = compose_plain split_feed
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
qputs "[#{i+1}/#{
|
15
|
+
rr = recipients
|
16
|
+
rr.each_with_index do |r, i|
|
17
|
+
html_r = personalize html, r.email
|
18
|
+
plain_r = personalize plain, r.email
|
19
|
+
qputs "[#{i+1}/#{rr.size}] Send newsletter to #{r.email}."
|
20
20
|
begin
|
21
|
-
send_out feed[:title],
|
21
|
+
send_out feed[:title], html_r, plain_r, r.email
|
22
22
|
rescue => exc
|
23
|
-
qputs "Could not send newsletter to #{
|
23
|
+
qputs "Could not send newsletter to #{r.email} for the following reason."
|
24
24
|
qputs exc.message
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
28
|
-
|
27
|
+
if not Configuration.dry_run
|
28
|
+
qputs 'Remember new items.'
|
29
|
+
split_feed[:unsent_item].each { |i| i.save }
|
30
|
+
end
|
29
31
|
qputs 'Done.'
|
30
32
|
end
|
31
33
|
|
32
34
|
private
|
33
35
|
|
36
|
+
def self.recipients
|
37
|
+
if Configuration.dry_run
|
38
|
+
s = Subscriber.new(email: Configuration.dry_run_email)
|
39
|
+
return [s].each
|
40
|
+
end
|
41
|
+
return Subscriber.find_each
|
42
|
+
end
|
43
|
+
|
34
44
|
def self.template_bindings(split_feed)
|
35
45
|
title = split_feed[:title]
|
36
|
-
unsent_items = split_feed[:unsent_item]
|
37
|
-
sent_items = split_feed[:sent_item]
|
38
|
-
unsubscribe_uri = nil # supress unused variable warning
|
39
|
-
unsubscribe_uri = "#{Configuration.base_uri}#{Api::UNSUBSCRIBE_PATH}/<%= recipient %>"
|
40
46
|
title = '' if !title.is_a?(String)
|
47
|
+
unsent_items = split_feed[:unsent_item]
|
41
48
|
unsent_items = [] if !unsent_items.is_a?(Array)
|
42
|
-
sent_items = []
|
49
|
+
sent_items = split_feed[:sent_item]
|
50
|
+
sent_items = [] if !sent_items.is_a?(Array)
|
51
|
+
unsubscribe_uri = Configuration.unsubscribe_uri
|
52
|
+
if false then unsubscribe_uri end # suppress unused variable warning
|
43
53
|
return binding
|
44
54
|
end
|
45
55
|
|
46
56
|
def self.compose_html(split_feed)
|
47
57
|
template = Configuration.html_template
|
48
58
|
bindings = template_bindings(split_feed)
|
49
|
-
return ERB.new(template,
|
59
|
+
return ERB.new(template, trim_mode: '-').result(bindings)
|
50
60
|
end
|
51
61
|
|
52
62
|
def self.compose_plain(split_feed)
|
53
63
|
template = Configuration.plain_template
|
54
64
|
bindings = template_bindings(split_feed)
|
55
|
-
return ERB.new(template,
|
65
|
+
return ERB.new(template, trim_mode: '-').result(bindings)
|
56
66
|
end
|
57
67
|
|
58
68
|
def self.personalize(message, recipient)
|
@@ -60,8 +70,8 @@ class Send
|
|
60
70
|
end
|
61
71
|
|
62
72
|
def self.send_out(title, html, plain, recipient)
|
63
|
-
date = nil # supress unused variable warning
|
64
73
|
date = Date.today.strftime('%a, %d %b %Y')
|
74
|
+
if false then date end # suppress unused variable warning
|
65
75
|
Mail.deliver do
|
66
76
|
to recipient
|
67
77
|
from ERB.new(Configuration.from).result(binding)
|
data/lib/correole/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: correole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Ledesma Garza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: thin
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +58,42 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '6.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '6.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activesupport
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '6.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '6.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: mail
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '2.
|
89
|
+
version: '2.7'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '2.
|
96
|
+
version: '2.7'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: pg
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,42 +114,42 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '1.
|
117
|
+
version: '1.4'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '1.
|
124
|
+
version: '1.4'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: minitest
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '5.
|
131
|
+
version: '5.14'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '5.
|
138
|
+
version: '5.14'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rack-test
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '1.1'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
152
|
+
version: '1.1'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: mini-smtp-server
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '
|
187
|
+
version: '13.0'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '
|
194
|
+
version: '13.0'
|
195
195
|
description: |
|
196
196
|
Correole is a webservice that subscribes and unsubscribes readers from
|
197
197
|
a newsletter.
|
@@ -234,15 +234,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
234
234
|
requirements:
|
235
235
|
- - "~>"
|
236
236
|
- !ruby/object:Gem::Version
|
237
|
-
version: 2.
|
237
|
+
version: 2.7.1
|
238
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
239
|
requirements:
|
240
240
|
- - ">="
|
241
241
|
- !ruby/object:Gem::Version
|
242
242
|
version: '0'
|
243
243
|
requirements: []
|
244
|
-
|
245
|
-
rubygems_version: 2.5.1
|
244
|
+
rubygems_version: 3.1.2
|
246
245
|
signing_key:
|
247
246
|
specification_version: 4
|
248
247
|
summary: A newsletter webservice
|