talktome 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/talktome.rb +50 -0
- data/lib/talktome/client.rb +12 -4
- data/lib/talktome/client/local.rb +6 -11
- data/lib/talktome/message.rb +1 -1
- data/lib/talktome/strategy/debug.rb +2 -0
- data/lib/talktome/strategy/email.rb +2 -0
- data/lib/talktome/version.rb +1 -1
- data/spec/client/test_local.rb +8 -0
- metadata +3 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2817b7e3a3e6d077e889d0d53ac368195785af09
|
4
|
+
data.tar.gz: e5d9c60306e644301a1029739f16041f3b740be2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf1e843cfd0ce3187bc693889ed5baf7e0deeddff436cf483ec0af6f20f6698e5d91eea60717f990b270f274bddd1ff959e75a1dca8fc7e5ad7325873c31f56
|
7
|
+
data.tar.gz: f312d5300c8eeacee34bd90097d61bd996246081b0400e013f59a63147a374719a59c904b3bd191481fc9d08e1417c5eebf266374931273a448e05b047ff0c8f
|
data/lib/talktome.rb
CHANGED
@@ -9,6 +9,56 @@ module Talktome
|
|
9
9
|
end
|
10
10
|
module_function :redcarpet
|
11
11
|
|
12
|
+
#
|
13
|
+
# Infer all client and strategy options from environment variables.
|
14
|
+
# The following ones are recognized:
|
15
|
+
#
|
16
|
+
# - TALKTOME_DEBUG: when set (to anything) enables the dumping of sent
|
17
|
+
# messages to the debug folder
|
18
|
+
# - TALKTOME_EMAIL_DELIVERY: "smtp", "file" or "test"
|
19
|
+
# - TALKTOME_EMAIL_DEFAULT_FROM: default from address to use for email sending
|
20
|
+
# - TALKTOME_SMTP_ADDRESS: host address for smtp sending
|
21
|
+
# - TALKTOME_SMTP_PORT: port of smtp server to use
|
22
|
+
# - TALKTOME_SMTP_DOMAIN: sending domain
|
23
|
+
# - TALKTOME_SMTP_USER: user for smtp authentication
|
24
|
+
# - TALKTOME_SMTP_PASSWORD: user for smtp authentication
|
25
|
+
#
|
26
|
+
def auto_options(folder)
|
27
|
+
options = {}
|
28
|
+
debug_folder = folder/"tmp"
|
29
|
+
|
30
|
+
options[:debugger] = ->(message, user, handler) {
|
31
|
+
debug_folder.mkdir_p unless debug_folder.exists?
|
32
|
+
(debug_folder/"#{user[:email]}.html").write(message.to_html)
|
33
|
+
(debug_folder/"#{user[:email]}.txt").write(message.to_text)
|
34
|
+
} if ENV['TALKTOME_DEBUG']
|
35
|
+
|
36
|
+
options[:strategies] = {}
|
37
|
+
|
38
|
+
email_delivery = (ENV['TALKTOME_EMAIL_DELIVERY'] || "test").to_sym
|
39
|
+
email_config = {}
|
40
|
+
|
41
|
+
email_config.merge!({
|
42
|
+
address: ENV['TALKTOME_SMTP_ADDRESS'],
|
43
|
+
port: ENV['TALKTOME_SMTP_PORT'],
|
44
|
+
domain: ENV['TALKTOME_SMTP_DOMAIN'],
|
45
|
+
user_name: ENV['TALKTOME_SMTP_USER'],
|
46
|
+
password: ENV['TALKTOME_SMTP_PASSWORD']
|
47
|
+
}) if email_delivery == :smtp
|
48
|
+
|
49
|
+
email_config.merge!({
|
50
|
+
location: debug_folder.mkdir_p
|
51
|
+
}) if email_delivery == :file
|
52
|
+
|
53
|
+
options[:strategies][:email] = ::Talktome::Strategy::Email.new{|email|
|
54
|
+
email.delivery_method(email_delivery, email_config)
|
55
|
+
email.from(ENV['TALKTOME_EMAIL_DEFAULT_FROM']) if ENV['TALKTOME_EMAIL_DEFAULT_FROM']
|
56
|
+
}
|
57
|
+
|
58
|
+
options
|
59
|
+
end
|
60
|
+
module_function :auto_options
|
61
|
+
|
12
62
|
end
|
13
63
|
require 'talktome/version'
|
14
64
|
require 'talktome/error'
|
data/lib/talktome/client.rb
CHANGED
@@ -1,19 +1,27 @@
|
|
1
1
|
module Talktome
|
2
2
|
class Client
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
|
4
|
+
def initialize(folder, options = {})
|
5
|
+
raise ArgumentError, "Missing root folder" unless folder
|
6
|
+
raise ArgumentError, "Invalid root folder" unless Path(folder).directory?
|
7
|
+
@folder = folder
|
8
|
+
@options = Talktome.auto_options(folder).merge(options)
|
6
9
|
yield self if block_given?
|
7
10
|
end
|
11
|
+
attr_reader :folder, :options
|
8
12
|
|
9
13
|
def strategy(name, stragegy)
|
10
|
-
|
14
|
+
strategies[name] = stragegy
|
11
15
|
end
|
12
16
|
|
13
17
|
protected
|
14
18
|
|
19
|
+
def strategies
|
20
|
+
options[:strategies]
|
21
|
+
end
|
22
|
+
|
15
23
|
def get_handler(strategy)
|
16
|
-
|
24
|
+
strategies[strategy]
|
17
25
|
end
|
18
26
|
|
19
27
|
end # class Client
|
@@ -1,21 +1,16 @@
|
|
1
1
|
module Talktome
|
2
2
|
class Client
|
3
|
+
#
|
4
|
+
# Builds a local client, that applies strategies synchronously and runs
|
5
|
+
# locally
|
6
|
+
#
|
3
7
|
class Local < Client
|
4
8
|
|
5
|
-
def
|
6
|
-
raise ArgumentError, "Missing messages folder" unless folder
|
7
|
-
raise ArgumentError, "Invalid messages folder" unless Path(folder).directory?
|
8
|
-
@folder = folder
|
9
|
-
@options = options
|
10
|
-
super()
|
11
|
-
end
|
12
|
-
attr_reader :folder, :options
|
13
|
-
|
14
|
-
def talktome(message, user, tpldata, strategies)
|
9
|
+
def talktome(message, user, tpldata, strategies, &callback)
|
15
10
|
message, handler = load_message!(message, strategies)
|
16
11
|
message = message.instantiate(tpldata)
|
17
12
|
options[:debugger].call(message, user, handler) if options[:debugger]
|
18
|
-
handler.send_message message, user
|
13
|
+
handler.send_message message, user, &callback
|
19
14
|
end
|
20
15
|
|
21
16
|
protected
|
data/lib/talktome/message.rb
CHANGED
data/lib/talktome/version.rb
CHANGED
data/spec/client/test_local.rb
CHANGED
@@ -53,6 +53,14 @@ module Talktome
|
|
53
53
|
expect(strategy.last.message).not_to be_nil
|
54
54
|
expect(strategy.last.message.to_html).to eql("<html><title>Hello Test user</title><body><h1>Hello Test user</h1>\n\n<p>Welcome to this email example!</p>\n\n<h3>Test user</h3>\n</body></html>\n")
|
55
55
|
end
|
56
|
+
|
57
|
+
it 'yields the callback with the email' do
|
58
|
+
seen = nil
|
59
|
+
client.talktome("welcome", user, tpldata, [:email]){|m|
|
60
|
+
seen = m
|
61
|
+
}
|
62
|
+
expect(seen).not_to be_nil
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talktome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -79,9 +79,6 @@ dependencies:
|
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '1'
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: 1.0.5
|
85
82
|
type: :runtime
|
86
83
|
prerelease: false
|
87
84
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -89,9 +86,6 @@ dependencies:
|
|
89
86
|
- - "~>"
|
90
87
|
- !ruby/object:Gem::Version
|
91
88
|
version: '1'
|
92
|
-
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: 1.0.5
|
95
89
|
- !ruby/object:Gem::Dependency
|
96
90
|
name: redcarpet
|
97
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,9 +93,6 @@ dependencies:
|
|
99
93
|
- - "~>"
|
100
94
|
- !ruby/object:Gem::Version
|
101
95
|
version: '3'
|
102
|
-
- - ">="
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: '3.4'
|
105
96
|
type: :runtime
|
106
97
|
prerelease: false
|
107
98
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -109,9 +100,6 @@ dependencies:
|
|
109
100
|
- - "~>"
|
110
101
|
- !ruby/object:Gem::Version
|
111
102
|
version: '3'
|
112
|
-
- - ">="
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
version: '3.4'
|
115
103
|
description: Talktome helps you talk to users by email, messaging, sms, etc. It abstracts
|
116
104
|
the messaging mechanisms and lets you manage message templates easily.
|
117
105
|
email: blambeau@gmail.com
|
@@ -163,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
151
|
version: '0'
|
164
152
|
requirements: []
|
165
153
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
154
|
+
rubygems_version: 2.6.11
|
167
155
|
signing_key:
|
168
156
|
specification_version: 4
|
169
157
|
summary: Talktome helps you talk to users by email, messaging, sms, etc.
|