slack-ruby-bot-server-mailchimp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +20 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +125 -0
- data/Dangerfile +1 -0
- data/Gemfile +36 -0
- data/LICENSE +21 -0
- data/README.md +56 -0
- data/RELEASING.md +77 -0
- data/Rakefile +14 -0
- data/lib/slack-ruby-bot-server-mailchimp.rb +5 -0
- data/lib/slack-ruby-bot-server/mailchimp/config.rb +33 -0
- data/lib/slack-ruby-bot-server/mailchimp/lifecycle.rb +47 -0
- data/lib/slack-ruby-bot-server/mailchimp/version.rb +5 -0
- data/slack-ruby-bot-server-mailchimp.gemspec +19 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 40656585b497e172f926371881eaf7e72c41fcda402abcf878df85902922f3f5
|
4
|
+
data.tar.gz: c7c09b96b872061811ee730d5ca76100e0f22ed5da25e546f7a6921aef6f953a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 359aa967108d4a5761aeffd70250a06854b617092b21369faf63d14262179a82e2df7eafc801f32ece6d94748ab7c95586a54505e12bf1c80630208221592aa5
|
7
|
+
data.tar.gz: b697c374b469e6f18cbd804b2edd60b5045aea3f4ba4698106e78d9cbc32ad6d8c2747be1e15191d553983f7a9dc06d59b77383dbdd29d40db43d89aecb37ecf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Metrics:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 500
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/FrozenStringLiteralComment:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/ModuleFunction:
|
15
|
+
EnforcedStyle: extend_self
|
16
|
+
|
17
|
+
inherit_from: .rubocop_todo.yml
|
18
|
+
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2019-03-23 14:46:53 -0400 using RuboCop version 0.66.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Lint/NonLocalExitFromIterator:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/slack-ruby-bot-server/mailchimp/lifecycle.rb'
|
13
|
+
|
14
|
+
# Offense count: 2
|
15
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
16
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
17
|
+
Naming/FileName:
|
18
|
+
Exclude:
|
19
|
+
- 'lib/slack-ruby-bot-server-mailchimp.rb'
|
20
|
+
- 'spec/support/slack-ruby-bot-server.rb'
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
cache: bundler
|
4
|
+
|
5
|
+
matrix:
|
6
|
+
include:
|
7
|
+
- rvm: 2.6.2
|
8
|
+
script:
|
9
|
+
- bundle exec danger
|
10
|
+
- rvm: 2.6.2
|
11
|
+
env: DATABASE_ADAPTER=activerecord
|
12
|
+
services:
|
13
|
+
- postgresql
|
14
|
+
- rvm: 2.6.2
|
15
|
+
env: DATABASE_ADAPTER=mongoid
|
16
|
+
services:
|
17
|
+
- mongodb
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Contributing to SlackRubyBotServer::Mailchimp
|
2
|
+
|
3
|
+
This project is work of [many contributors](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp/graphs/contributors).
|
4
|
+
|
5
|
+
You're encouraged to submit [pull requests](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp/pulls), [propose features and discuss issues](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp/issues).
|
6
|
+
|
7
|
+
In the examples below, substitute your Github username for `contributor` in URLs.
|
8
|
+
|
9
|
+
## Fork the Project
|
10
|
+
|
11
|
+
Fork the [project on Github](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp) and check out your copy.
|
12
|
+
|
13
|
+
```
|
14
|
+
git clone https://github.com/contributor/slack-ruby-bot-server-mailchimp.git
|
15
|
+
cd slack-ruby-bot-server
|
16
|
+
git remote add upstream https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp.git
|
17
|
+
```
|
18
|
+
|
19
|
+
## Create a Topic Branch
|
20
|
+
|
21
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
22
|
+
|
23
|
+
```
|
24
|
+
git checkout master
|
25
|
+
git pull upstream master
|
26
|
+
git checkout -b my-feature-branch
|
27
|
+
```
|
28
|
+
|
29
|
+
## Bundle Install and Test
|
30
|
+
|
31
|
+
Ensure that you can build the project and run tests.
|
32
|
+
|
33
|
+
```
|
34
|
+
bundle install
|
35
|
+
bundle exec rake
|
36
|
+
```
|
37
|
+
|
38
|
+
## Write Tests
|
39
|
+
|
40
|
+
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build.
|
41
|
+
Add to [spec](spec).
|
42
|
+
|
43
|
+
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
44
|
+
|
45
|
+
## Write Code
|
46
|
+
|
47
|
+
Implement your feature or bug fix.
|
48
|
+
|
49
|
+
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop).
|
50
|
+
Run `bundle exec rubocop` and fix any style issues highlighted.
|
51
|
+
|
52
|
+
Make sure that `bundle exec rake` completes without errors.
|
53
|
+
|
54
|
+
## Write Documentation
|
55
|
+
|
56
|
+
Document any external behavior in the [README](README.md).
|
57
|
+
|
58
|
+
## Update Changelog
|
59
|
+
|
60
|
+
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*.
|
61
|
+
Make it look like every other line, including your name and link to your Github account.
|
62
|
+
|
63
|
+
## Commit Changes
|
64
|
+
|
65
|
+
Make sure git knows your name and email address:
|
66
|
+
|
67
|
+
```
|
68
|
+
git config --global user.name "Your Name"
|
69
|
+
git config --global user.email "contributor@example.com"
|
70
|
+
```
|
71
|
+
|
72
|
+
Writing good commit logs is important. A commit log should describe what changed and why.
|
73
|
+
|
74
|
+
```
|
75
|
+
git add ...
|
76
|
+
git commit
|
77
|
+
```
|
78
|
+
|
79
|
+
## Push
|
80
|
+
|
81
|
+
```
|
82
|
+
git push origin my-feature-branch
|
83
|
+
```
|
84
|
+
|
85
|
+
## Make a Pull Request
|
86
|
+
|
87
|
+
Go to https://github.com/contributor/slack-ruby-bot-server and select your feature branch.
|
88
|
+
Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
89
|
+
|
90
|
+
## Rebase
|
91
|
+
|
92
|
+
If you've been working on a change for a while, rebase with upstream/master.
|
93
|
+
|
94
|
+
```
|
95
|
+
git fetch upstream
|
96
|
+
git rebase upstream/master
|
97
|
+
git push origin my-feature-branch -f
|
98
|
+
```
|
99
|
+
|
100
|
+
## Update CHANGELOG Again
|
101
|
+
|
102
|
+
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
103
|
+
|
104
|
+
```
|
105
|
+
* [#123](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
106
|
+
```
|
107
|
+
|
108
|
+
Amend your previous commit and force push the changes.
|
109
|
+
|
110
|
+
```
|
111
|
+
git commit --amend
|
112
|
+
git push origin my-feature-branch -f
|
113
|
+
```
|
114
|
+
|
115
|
+
## Check on Your Pull Request
|
116
|
+
|
117
|
+
Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
|
118
|
+
|
119
|
+
## Be Patient
|
120
|
+
|
121
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
122
|
+
|
123
|
+
## Thank You
|
124
|
+
|
125
|
+
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/Dangerfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
danger.import_dangerfile(gem: 'slack-ruby-danger')
|
data/Gemfile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
case ENV['DATABASE_ADAPTER']
|
4
|
+
when 'mongoid' then
|
5
|
+
gem 'kaminari-mongoid'
|
6
|
+
gem 'mongoid'
|
7
|
+
gem 'mongoid-scroll'
|
8
|
+
when 'activerecord' then
|
9
|
+
gem 'activerecord', '~> 5.0.0'
|
10
|
+
gem 'otr-activerecord', '~> 1.2.1'
|
11
|
+
gem 'cursor_pagination' # rubocop:disable Bundler/OrderedGems
|
12
|
+
gem 'pg'
|
13
|
+
when nil then
|
14
|
+
warn "Missing ENV['DATABASE_ADAPTER']."
|
15
|
+
else
|
16
|
+
warn "Invalid ENV['DATABASE_ADAPTER']: #{ENV['DATABASE_ADAPTER']}."
|
17
|
+
end
|
18
|
+
|
19
|
+
gemspec
|
20
|
+
|
21
|
+
group :development, :test do
|
22
|
+
gem 'bundler'
|
23
|
+
gem 'database_cleaner'
|
24
|
+
gem 'fabrication'
|
25
|
+
gem 'faker'
|
26
|
+
gem 'rack-test'
|
27
|
+
gem 'rake'
|
28
|
+
gem 'rspec'
|
29
|
+
gem 'rubocop', '0.66.0'
|
30
|
+
gem 'vcr'
|
31
|
+
gem 'webmock'
|
32
|
+
end
|
33
|
+
|
34
|
+
group :test do
|
35
|
+
gem 'slack-ruby-danger', '~> 0.1.0', require: false
|
36
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Daniel Doubrovkine & Contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Slack Ruby Bot Server Mailchimp Extension
|
2
|
+
=========================================
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/slack-ruby-bot-server-mailchimp.svg)](https://badge.fury.io/rb/slack-ruby-bot-server-mailchimp)
|
5
|
+
[![Build Status](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-mailchimp.svg?branch=master)](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-mailchimp)
|
6
|
+
|
7
|
+
A lifecycle extension to [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server) that subscribes new bot users to a Mailchimp mailing list.
|
8
|
+
|
9
|
+
### Usage
|
10
|
+
|
11
|
+
Add 'slack-ruby-bot-server-mailchimp' to Gemfile.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'slack-ruby-bot-server-mailchimp'
|
15
|
+
```
|
16
|
+
|
17
|
+
Configure.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
SlackRubyBotServer::Mailchimp.configure do |config|
|
21
|
+
config.mailchimp_api_key = ENV['MAILCHIMP_API_KEY'] # defaults to ENV['MAILCHIMP_API_KEY']
|
22
|
+
config.mailchimp_list_id = ENV['MAILCHIMP_LIST_ID'] # defaults to ENV['MAILCHIMP_LIST_ID']
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
Users that install the bot are automatically subscribed via [bot server lifecycle](lib/slack-ruby-bot-server/mailchimp/lifecycle.rb).
|
27
|
+
|
28
|
+
### Additional Member Tags
|
29
|
+
|
30
|
+
If your `Team` model responds to `.tags`, those will be attached to new subscriptions and appear as "tags" in Mailchimp. You can also supplement member tags for new subscriptions through `member_tags` configuration.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
SlackRubyBotServer::Mailchimp.config.member_tags = ['my_bot']
|
34
|
+
```
|
35
|
+
|
36
|
+
### Additional Profile Information
|
37
|
+
|
38
|
+
The default member profile information that appears in Mailchimp under "Profile Information" for each new subscriber contains the user's email address, first and last name from Slack. You can supplement this data with `additional_merge_fields`.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
SlackRubyBotServer::Mailchimp.config.additional_merge_fields = { 'BOT' => 'MyBot' }
|
42
|
+
```
|
43
|
+
|
44
|
+
### Double Opt-In
|
45
|
+
|
46
|
+
This integration subscribes users with double opt-in by default. Configure `member_status` to disable double opt-in. See [this doc](https://developer.mailchimp.com/documentation/mailchimp/guides/manage-subscribers-with-the-mailchimp-api) for more details.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
SlackRubyBotServer::Mailchimp.config.member_status = 'subscribed'
|
50
|
+
```
|
51
|
+
|
52
|
+
### Copyright & License
|
53
|
+
|
54
|
+
Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2019
|
55
|
+
|
56
|
+
[MIT License](LICENSE)
|
data/RELEASING.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Releasing Slack-Ruby-Bot-Server-Mailchimp
|
2
|
+
|
3
|
+
There're no hard rules about when to release slack-ruby-bot-server-mailchimp. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
4
|
+
|
5
|
+
### Release
|
6
|
+
|
7
|
+
Run tests, check that all tests succeed locally.
|
8
|
+
|
9
|
+
```
|
10
|
+
bundle install
|
11
|
+
rake
|
12
|
+
```
|
13
|
+
|
14
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-mailchimp) for all supported platforms.
|
15
|
+
|
16
|
+
Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
|
17
|
+
|
18
|
+
```
|
19
|
+
### 0.2.2 (7/10/2015)
|
20
|
+
```
|
21
|
+
|
22
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
23
|
+
|
24
|
+
Change `**next**` in the "Stable Release" section in README that warns users that they are reading the documentation for an unreleased version with `**stable**`.
|
25
|
+
|
26
|
+
```
|
27
|
+
## Stable Release
|
28
|
+
|
29
|
+
You're reading the documentation for the **stable** release of slack-ruby-bot-server, 0.2.2. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
|
30
|
+
```
|
31
|
+
|
32
|
+
Commit your changes.
|
33
|
+
|
34
|
+
```
|
35
|
+
git add README.md CHANGELOG.md
|
36
|
+
git commit -m "Preparing for release, 0.2.2."
|
37
|
+
git push origin master
|
38
|
+
```
|
39
|
+
|
40
|
+
Release.
|
41
|
+
|
42
|
+
```
|
43
|
+
$ rake release
|
44
|
+
|
45
|
+
slack-ruby-bot-server 0.2.2 built to pkg/slack-ruby-bot-server-0.2.2.gem.
|
46
|
+
Tagged v0.2.2.
|
47
|
+
Pushed git commits and tags.
|
48
|
+
Pushed slack-ruby-bot-server 0.2.2 to rubygems.org.
|
49
|
+
```
|
50
|
+
|
51
|
+
### Prepare for the Next Version
|
52
|
+
|
53
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
54
|
+
|
55
|
+
```
|
56
|
+
### 0.2.3 (Next)
|
57
|
+
|
58
|
+
* Your contribution here.
|
59
|
+
```
|
60
|
+
|
61
|
+
Increment the third version number in [lib/slack-ruby-bot-server-mailchimp/version.rb](lib/slack-ruby-bot-server-mailchimp/version.rb).
|
62
|
+
|
63
|
+
Undo your change in README about the stable release.
|
64
|
+
|
65
|
+
```
|
66
|
+
## Stable Release
|
67
|
+
|
68
|
+
You're reading the documentation for the **next** release of slack-ruby-bot-server. Please see the documentation for the [last stable release, v0.2.2](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp/blob/v0.2.2/README.md) unless you're integrating with HEAD. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
|
69
|
+
```
|
70
|
+
|
71
|
+
Commit your changes.
|
72
|
+
|
73
|
+
```
|
74
|
+
git add README.md CHANGELOG.md lib/slack-ruby-bot-server-mailchimp/version.rb
|
75
|
+
git commit -m "Preparing for next development iteration, 0.2.3."
|
76
|
+
git push origin master
|
77
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
require 'rspec/core'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
|
+
spec.pattern = FileList['spec/**/*_spec.rb'].exclude(%r{ext\/(?!#{ENV['DATABASE_ADAPTER']})})
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rubocop/rake_task'
|
12
|
+
RuboCop::RakeTask.new
|
13
|
+
|
14
|
+
task default: %i[rubocop spec]
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SlackRubyBotServer
|
2
|
+
module Mailchimp
|
3
|
+
module Config
|
4
|
+
extend self
|
5
|
+
|
6
|
+
attr_accessor :mailchimp_api_key
|
7
|
+
attr_accessor :mailchimp_list_id
|
8
|
+
attr_accessor :additional_member_tags
|
9
|
+
attr_accessor :additional_merge_fields
|
10
|
+
attr_accessor :member_status
|
11
|
+
|
12
|
+
def reset!
|
13
|
+
self.mailchimp_list_id = ENV['MAILCHIMP_LIST_ID']
|
14
|
+
self.mailchimp_api_key = ENV['MAILCHIMP_API_KEY']
|
15
|
+
self.additional_member_tags = []
|
16
|
+
self.additional_merge_fields = {}
|
17
|
+
self.member_status = 'pending'
|
18
|
+
end
|
19
|
+
|
20
|
+
reset!
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def configure
|
25
|
+
block_given? ? yield(Config) : Config
|
26
|
+
end
|
27
|
+
|
28
|
+
def config
|
29
|
+
Config
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
SlackRubyBotServer::Config.service_class.instance.on :created do |team, _error, _options|
|
2
|
+
raise 'missing ENV["MAILCHIMP_API_KEY"]' unless SlackRubyBotServer::Mailchimp.config.mailchimp_api_key
|
3
|
+
raise 'missing ENV["MAILCHIMP_LIST_ID"]' unless SlackRubyBotServer::Mailchimp.config.mailchimp_list_id
|
4
|
+
|
5
|
+
mailchimp_client = Mailchimp.connect(SlackRubyBotServer::Mailchimp.config.mailchimp_api_key)
|
6
|
+
mailchimp_list = mailchimp_client.lists(SlackRubyBotServer::Mailchimp.config.mailchimp_list_id)
|
7
|
+
|
8
|
+
slack_client = Slack::Web::Client.new(token: team.token)
|
9
|
+
|
10
|
+
# fetch profile of the user installing the bot
|
11
|
+
raise 'missing team.activated_user_id' unless team.activated_user_id
|
12
|
+
|
13
|
+
profile = Hashie::Mash.new(slack_client.users_info(user: team.activated_user_id)).user.profile
|
14
|
+
raise "error fetching user profile for #{team.activated_user_id}" unless profile
|
15
|
+
|
16
|
+
# fetch and merge member tags
|
17
|
+
tags = SlackRubyBotServer::Mailchimp.config.additional_member_tags
|
18
|
+
tags = (tags + team.tags).uniq if team.respond_to?(:tags)
|
19
|
+
|
20
|
+
member = mailchimp_list.members.where(email_address: profile.email).first
|
21
|
+
if member
|
22
|
+
member_tags = member.tags.map { |tag| tag['name'] }.sort
|
23
|
+
tags = (member_tags + tags).uniq
|
24
|
+
if tags == member_tags
|
25
|
+
SlackRubyBot::Client.logger.debug "Skipping #{profile.email} with identical tags (#{tags.join(', ')}), will not be added to #{SlackRubyBotServer::Mailchimp.config.mailchimp_list_id}, #{team}."
|
26
|
+
next
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# merge fields
|
31
|
+
merge_fields = SlackRubyBotServer::Mailchimp.config.additional_merge_fields.merge(
|
32
|
+
'FNAME' => profile.first_name.to_s,
|
33
|
+
'LNAME' => profile.last_name.to_s
|
34
|
+
)
|
35
|
+
|
36
|
+
# subscribe
|
37
|
+
mailchimp_list.members.create_or_update(
|
38
|
+
name: profile.name,
|
39
|
+
email_address: profile.email,
|
40
|
+
unique_email_id: "#{team.team_id}-#{team.activated_user_id}",
|
41
|
+
status: member ? member.status : SlackRubyBotServer::Mailchimp.config.member_status,
|
42
|
+
tags: tags,
|
43
|
+
merge_fields: merge_fields
|
44
|
+
)
|
45
|
+
|
46
|
+
SlackRubyBot::Client.logger.info "Subscribed #{profile.email} to #{SlackRubyBotServer::Mailchimp.config.mailchimp_list_id}, #{team}."
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'slack-ruby-bot-server/mailchimp/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'slack-ruby-bot-server-mailchimp'
|
7
|
+
spec.version = SlackRubyBotServer::Mailchimp::VERSION
|
8
|
+
spec.authors = ['Daniel Doubrovkine']
|
9
|
+
spec.email = ['dblock@dblock.org']
|
10
|
+
|
11
|
+
spec.summary = 'Mailchimp extension for slack-ruby-bot-server.'
|
12
|
+
spec.homepage = 'https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.add_dependency 'mailchimp_api_v3'
|
18
|
+
spec.add_dependency 'slack-ruby-bot-server', '>= 0.10.0'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack-ruby-bot-server-mailchimp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Doubrovkine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mailchimp_api_v3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: slack-ruby-bot-server
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.10.0
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- dblock@dblock.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- ".rubocop_todo.yml"
|
52
|
+
- ".travis.yml"
|
53
|
+
- CHANGELOG.md
|
54
|
+
- CONTRIBUTING.md
|
55
|
+
- Dangerfile
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
59
|
+
- RELEASING.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/slack-ruby-bot-server-mailchimp.rb
|
62
|
+
- lib/slack-ruby-bot-server/mailchimp/config.rb
|
63
|
+
- lib/slack-ruby-bot-server/mailchimp/lifecycle.rb
|
64
|
+
- lib/slack-ruby-bot-server/mailchimp/version.rb
|
65
|
+
- slack-ruby-bot-server-mailchimp.gemspec
|
66
|
+
homepage: https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp
|
67
|
+
licenses: []
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.7.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Mailchimp extension for slack-ruby-bot-server.
|
89
|
+
test_files: []
|