mailkick 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 716fa3a1fdcc00415b50a343d0d38eb434bece3f
4
- data.tar.gz: 35649c58e33998450e8494620619720aa02b9448
3
+ metadata.gz: 902719cffa741b74a8efa92f326e98c5d359d610
4
+ data.tar.gz: 0a15d25bf9ea0201eabc5eeace46cba06b878596
5
5
  SHA512:
6
- metadata.gz: fe3729d2ec69f27b1216ad302770560b826363b23ded849b694694e321e33938cea3d9bff5926d47b488b891fe19af1e53ffc3becfdcf360c65d6877475c7555
7
- data.tar.gz: 1ba653ab1c80211110aa177179f16e020a01361c2c4ec48fbb7e7399d303d5165de8fe38628aee2181c585d98359407d6499796644ceb998c543ca62e4093e10
6
+ metadata.gz: b9e635f1f60c3eb5043450aea43133e6a9feb3cccaa1116ca4dfc769c73e1d0f51ecd7dec73d7fc5793f2893e08c4b66f8d774774ac5e2fd8326d890286a9b8b
7
+ data.tar.gz: f21ad8fed634b2e4bec5801df0a5d8b305656e4ff4922894461df36700fedb5f2f8704ad00c42e6b11ee2f2b6cd2f85affd3235038e0ff1ef2cd5a9600ceb1c2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.0.2
2
+
3
+ - Added Mailchimp service
4
+ - Fixed Mandrill service
5
+ - Added `uniq` to `subscribed` scope
6
+
1
7
  ## 0.0.1
2
8
 
3
9
  - First release
data/README.md CHANGED
@@ -104,7 +104,7 @@ gem 'sendgrid_toolkit'
104
104
 
105
105
  Be sure `ENV["SENDGRID_USERNAME"]` and `ENV["SENDGRID_PASSWORD"]` are set.
106
106
 
107
- #### Mandrill [broken]
107
+ #### Mandrill
108
108
 
109
109
  ```ruby
110
110
  gem 'mandrill-api'
@@ -112,9 +112,17 @@ gem 'mandrill-api'
112
112
 
113
113
  Be sure `ENV["MANDRILL_APIKEY"]` is set.
114
114
 
115
+ #### Mailchimp
116
+
117
+ ```ruby
118
+ gem 'gibbon'
119
+ ```
120
+
121
+ Be sure `ENV["MAILCHIMP_API_KEY"]` and `ENV["MAILCHIMP_LIST_ID"]` are set.
122
+
115
123
  #### Other
116
124
 
117
- Send a pull request.
125
+ Will gladly accept pull requests.
118
126
 
119
127
  ### Advanced
120
128
 
@@ -136,6 +144,7 @@ Coming soon
136
144
  More great gems for email
137
145
 
138
146
  - [Roadie](https://github.com/Mange/roadie) - inline CSS
147
+ - [Letter Opener](https://github.com/ryanb/letter_opener) - preview email in development
139
148
 
140
149
  ## Reference
141
150
 
@@ -53,13 +53,13 @@ module Mailkick
53
53
  end
54
54
  helper_method :subscribed?
55
55
 
56
- def subscribe_url
57
- subscribe_subscription_path(params[:id])
56
+ def subscribe_url(options = {})
57
+ subscribe_subscription_path(params[:id], options)
58
58
  end
59
59
  helper_method :subscribe_url
60
60
 
61
- def unsubscribe_url
62
- unsubscribe_subscription_path(params[:id])
61
+ def unsubscribe_url(options = {})
62
+ unsubscribe_subscription_path(params[:id], options)
63
63
  end
64
64
  helper_method :unsubscribe_url
65
65
 
@@ -1,9 +1,9 @@
1
1
  module Mailkick
2
2
  module UrlHelper
3
3
 
4
- def mailkick_unsubscribe_url
4
+ def mailkick_unsubscribe_url(options = {})
5
5
  Mailkick::Engine.routes.url_helpers.url_for(
6
- Rails.application.config.action_mailer.default_url_options.merge(
6
+ Rails.application.config.action_mailer.default_url_options.merge(options).merge(
7
7
  controller: "mailkick/subscriptions",
8
8
  action: "unsubscribe",
9
9
  id: "{{MAILKICK_TOKEN}}"
@@ -3,7 +3,7 @@ module Mailkick
3
3
 
4
4
  def mailkick_user(options = {})
5
5
  class_eval do
6
- scope :subscribed, proc{ joins(sanitize_sql_array(["LEFT JOIN mailkick_opt_outs ON #{table_name}.email = mailkick_opt_outs.email OR (#{table_name}.id = mailkick_opt_outs.user_id AND mailkick_opt_outs.user_type = ?)", name])).where("active != ?", true) }
6
+ scope :subscribed, proc{ joins(sanitize_sql_array(["LEFT JOIN mailkick_opt_outs ON #{table_name}.email = mailkick_opt_outs.email OR (#{table_name}.id = mailkick_opt_outs.user_id AND mailkick_opt_outs.user_type = ?)", name])).where("active != ?", true).uniq }
7
7
 
8
8
  def opt_outs
9
9
  Mailkick::OptOut.where("email = ? OR (user_id = ? AND user_type = ?)", email, id, self.class.name)
@@ -0,0 +1,43 @@
1
+ # https://github.com/amro/gibbon
2
+
3
+ module Mailkick
4
+ class Service
5
+ class Mailchimp < Mailkick::Service
6
+
7
+ def initialize(options = {})
8
+ @gibbon = ::Gibbon::API.new(options[:api_key] || ENV["MAILCHIMP_API_KEY"])
9
+ @list_id = options[:list_id] || ENV["MAILCHIMP_LIST_ID"]
10
+ end
11
+
12
+ # TODO paginate
13
+ def opt_outs
14
+ unsubscribes + spam_reports
15
+ end
16
+
17
+ def unsubscribes
18
+ fetch(@gibbon.lists.members(id: @list_id, status: "unsubscribed"), "unsubscribe")
19
+ end
20
+
21
+ def spam_reports
22
+ fetch(@gibbon.lists.abuse_reports(id: @list_id), "spam")
23
+ end
24
+
25
+ def self.discoverable?
26
+ !!(defined?(::Gibbon) && ENV["MAILCHIMP_API_KEY"] && ENV["MAILCHIMP_LIST_ID"])
27
+ end
28
+
29
+ protected
30
+
31
+ def fetch(response, reason)
32
+ response["data"].map do |record|
33
+ {
34
+ email: record["email"],
35
+ time: ActiveSupport::TimeZone["UTC"].parse(record["timestamp_opt"] || record["date"]),
36
+ reason: reason
37
+ }
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -3,17 +3,27 @@
3
3
  module Mailkick
4
4
  class Service
5
5
  class Mandrill < Mailkick::Service
6
+ REASONS_MAP = {
7
+ "hard-bounce" => "bounce",
8
+ "soft-bounce" => "bounce",
9
+ "spam" => "spam",
10
+ "unsub" => "unsubscribe"
11
+ }
6
12
 
7
13
  def initialize(options = {})
8
14
  require "mandrill"
9
15
  @mandrill = ::Mandrill::API.new(options[:api_key] || ENV["MANDRILL_APIKEY"])
10
16
  end
11
17
 
18
+ # TODO paginate
12
19
  def opt_outs
13
- # @mandrill.rejects.list.map do |record|
14
- # record
15
- # end
16
- []
20
+ @mandrill.rejects.list.map do |record|
21
+ {
22
+ email: record["email"],
23
+ time: ActiveSupport::TimeZone["UTC"].parse(record["created_at"]),
24
+ reason: REASONS_MAP[record["reason"]]
25
+ }
26
+ end
17
27
  end
18
28
 
19
29
  def self.discoverable?
@@ -9,6 +9,7 @@ module Mailkick
9
9
  @api_key = options[:api_key] || ENV["SENDGRID_PASSWORD"]
10
10
  end
11
11
 
12
+ # TODO paginate
12
13
  def opt_outs
13
14
  unsubscribes + spam_reports + bounces
14
15
  end
@@ -1,3 +1,3 @@
1
1
  module Mailkick
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/mailkick.rb CHANGED
@@ -4,6 +4,7 @@ require "mailkick/processor"
4
4
  require "mailkick/mailer"
5
5
  require "mailkick/model"
6
6
  require "mailkick/service"
7
+ require "mailkick/service/mailchimp"
7
8
  require "mailkick/service/mandrill"
8
9
  require "mailkick/service/sendgrid"
9
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -65,6 +65,7 @@ files:
65
65
  - lib/mailkick/model.rb
66
66
  - lib/mailkick/processor.rb
67
67
  - lib/mailkick/service.rb
68
+ - lib/mailkick/service/mailchimp.rb
68
69
  - lib/mailkick/service/mandrill.rb
69
70
  - lib/mailkick/service/sendgrid.rb
70
71
  - lib/mailkick/version.rb