mailkick 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35835a6f8e9f1d62977205c3b4b381dc13baecf7
4
- data.tar.gz: 528cb1cf61a126560de37a2b6dabccc6bc56283a
3
+ metadata.gz: b352637be3b03e2c64e52936662205cf4524aa93
4
+ data.tar.gz: 5c3340840799c56a44c246667f86c13e22ad375c
5
5
  SHA512:
6
- metadata.gz: 635af4e2bfdb8d2dab9c70f2f7f9d5a88c903d42882b9234455d3bc82c7896bd5bb7521a7209b714b2795e7798ad01a2d5f7db40da99ba9cdd00d4c2560931e2
7
- data.tar.gz: dd7bc1dad73ea07ebead206ceba06a48b5a9989f2691f911f238cc2ba33355bc67c5ea8c08885ccae184acbe01062bcbb40a3075924f9e924ba1fd0acdab203a
6
+ metadata.gz: 5a0b3d37bc1d3e883e30518960d486784850ab703ba4a8108cc4d1ca5b0d9d78fe0981bbf130fec0188db53d3011d0e5b9cd8ad8c9832b3491f77eb5263da92f
7
+ data.tar.gz: 1524cf7d6fd3d9a297a1ca9854868cccda35c42bff1ff325ade4f38b37ce6862cca05ce4ab91d00c70a2b0d353f82b9f733e520471e047b385454b1398e87065
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.2
2
+
3
+ - Added support for Mailgun
4
+
1
5
  ## 0.1.1
2
6
 
3
7
  - Fixed tokens with `+` in them
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in mailkick.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -114,6 +114,14 @@ gem 'gibbon'
114
114
 
115
115
  Be sure `ENV["MAILCHIMP_API_KEY"]` and `ENV["MAILCHIMP_LIST_ID"]` are set.
116
116
 
117
+ #### Mailgun
118
+
119
+ ```ruby
120
+ gem 'mailgun-ruby'
121
+ ```
122
+
123
+ Be sure `ENV["MAILGUN_API_KEY"]` is set.
124
+
117
125
  #### Other
118
126
 
119
127
  Will gladly accept pull requests.
@@ -139,7 +147,7 @@ Set the list in the mailer.
139
147
  class UserMailer < ActionMailer::Base
140
148
 
141
149
  def order_reminder(user)
142
- header[:mailkick_list] = "order_reminders"
150
+ headers[:mailkick_list] = "order_reminders"
143
151
  # ...
144
152
  end
145
153
 
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
1
  require "bundler/gem_tasks"
2
-
@@ -53,8 +53,7 @@ module Mailkick
53
53
  private
54
54
 
55
55
  def url_token
56
- @url_token ||= CGI::escape(params[:id])
56
+ @url_token ||= CGI.escape(params[:id])
57
57
  end
58
-
59
58
  end
60
59
  end
@@ -1,6 +1,5 @@
1
1
  module Mailkick
2
2
  module UrlHelper
3
-
4
3
  def mailkick_unsubscribe_url
5
4
  Mailkick::Engine.routes.url_helpers.url_for(
6
5
  (ActionMailer::Base.default_url_options || {}).merge(
@@ -10,6 +9,5 @@ module Mailkick
10
9
  )
11
10
  )
12
11
  end
13
-
14
12
  end
15
13
  end
@@ -24,7 +24,6 @@ module Mailkick
24
24
  def copy_migration
25
25
  migration_template "install.rb", "db/migrate/install_mailkick.rb"
26
26
  end
27
-
28
27
  end
29
28
  end
30
29
  end
@@ -8,7 +8,6 @@ module Mailkick
8
8
  def copy_initializer_file
9
9
  directory "mailkick", "app/views/mailkick"
10
10
  end
11
-
12
11
  end
13
12
  end
14
13
  end
@@ -1,6 +1,5 @@
1
1
  module Mailkick
2
2
  module Mailer
3
-
4
3
  def self.included(base)
5
4
  base.class_eval do
6
5
  alias_method_chain :mail, :mailkick
@@ -14,6 +13,5 @@ module Mailkick
14
13
 
15
14
  message
16
15
  end
17
-
18
16
  end
19
17
  end
@@ -1,6 +1,5 @@
1
1
  module Mailkick
2
2
  module Model
3
-
4
3
  def mailkick_user(options = {})
5
4
  email_key = options[:email_key] || :email
6
5
  class_eval do
@@ -12,7 +11,7 @@ module Mailkick
12
11
  else
13
12
  query = "mailkick_opt_outs.list IS NULL"
14
13
  end
15
- where("#{options[:not] ? "NOT " : ""}EXISTS(SELECT * FROM mailkick_opt_outs WHERE (#{table_name}.#{email_key} = mailkick_opt_outs.email OR (#{table_name}.#{primary_key} = mailkick_opt_outs.user_id AND mailkick_opt_outs.user_type = ?)) AND mailkick_opt_outs.active = ? AND #{query})", *binds)
14
+ where("#{options[:not] ? 'NOT ' : ''}EXISTS(SELECT * FROM mailkick_opt_outs WHERE (#{table_name}.#{email_key} = mailkick_opt_outs.email OR (#{table_name}.#{primary_key} = mailkick_opt_outs.user_id AND mailkick_opt_outs.user_type = ?)) AND mailkick_opt_outs.active = ? AND #{query})", *binds)
16
15
  }
17
16
  scope :not_opted_out, proc {|options = {}|
18
17
  opted_out(options.merge(not: true))
@@ -29,9 +28,7 @@ module Mailkick
29
28
  def opt_in(options = {})
30
29
  Mailkick.opt_in({email: email, user: self}.merge(options))
31
30
  end
32
-
33
31
  end
34
32
  end
35
-
36
33
  end
37
34
  end
@@ -20,9 +20,8 @@ module Mailkick
20
20
 
21
21
  parts = message.parts.any? ? message.parts : [message]
22
22
  parts.each do |part|
23
- part.body.raw_source.gsub!(/%7B%7BMAILKICK_TOKEN%7D%7D/, CGI::escape(token))
23
+ part.body.raw_source.gsub!(/%7B%7BMAILKICK_TOKEN%7D%7D/, CGI.escape(token))
24
24
  end
25
25
  end
26
-
27
26
  end
28
27
  end
@@ -3,7 +3,6 @@
3
3
  module Mailkick
4
4
  class Service
5
5
  class Mailchimp < Mailkick::Service
6
-
7
6
  def initialize(options = {})
8
7
  @gibbon = ::Gibbon::API.new(options[:api_key] || ENV["MAILCHIMP_API_KEY"])
9
8
  @list_id = options[:list_id] || ENV["MAILCHIMP_LIST_ID"]
@@ -37,7 +36,6 @@ module Mailkick
37
36
  }
38
37
  end
39
38
  end
40
-
41
39
  end
42
40
  end
43
41
  end
@@ -0,0 +1,46 @@
1
+ # https://github.com/mailgun/mailgun-ruby
2
+
3
+ module Mailkick
4
+ class Service
5
+ class Mailgun < Mailkick::Service
6
+ def initalize(options = {})
7
+ require 'mailgun'
8
+ mailgun_client = ::Mailgun::Client.new(options[:api_key] || ENV["MAILGUN_API_KEY"])
9
+ domain = options[:domain] || ActionMailer::Base.default_url_options[:host]
10
+ @mailgun_events = ::Mailgun::Events.new(mailgun_client, domain)
11
+ end
12
+
13
+ def opt_outs
14
+ unsubscribes + spam_reports + bounces
15
+ end
16
+
17
+ def unsubscribes
18
+ fetch(@mailgun_events.get({event: 'unsubscribed'}), 'unsubscribe')
19
+ end
20
+
21
+ def spam_reports
22
+ fetch(@mailgun_events.get({event: 'complained'}), 'spam')
23
+ end
24
+
25
+ def bounces
26
+ fetch(@mailgun_events.get({event: 'failed'}), 'bounce')
27
+ end
28
+
29
+ def self.discoverable?
30
+ !!(defined?(::Mailgun) && ENV["MAILGUN_API_KEY"])
31
+ end
32
+
33
+ protected
34
+
35
+ def fetch(response, reason)
36
+ response.to_h['items'].map do |record|
37
+ {
38
+ email: record['recipient'],
39
+ time: ActiveSupport::TimeZone['UTC'].at(record['timestamp']),
40
+ reason: reason
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -29,7 +29,6 @@ module Mailkick
29
29
  def self.discoverable?
30
30
  !!(defined?(::Mandrill::API) && ENV["MANDRILL_APIKEY"])
31
31
  end
32
-
33
32
  end
34
33
  end
35
34
  end
@@ -3,7 +3,6 @@
3
3
  module Mailkick
4
4
  class Service
5
5
  class Sendgrid < Mailkick::Service
6
-
7
6
  def initialize(options = {})
8
7
  @api_user = options[:api_user] || ENV["SENDGRID_USERNAME"]
9
8
  @api_key = options[:api_key] || ENV["SENDGRID_PASSWORD"]
@@ -41,7 +40,6 @@ module Mailkick
41
40
  }
42
41
  end
43
42
  end
44
-
45
43
  end
46
44
  end
47
45
  end
@@ -1,13 +1,12 @@
1
1
  module Mailkick
2
2
  class Service
3
-
4
3
  def fetch_opt_outs
5
4
  opt_outs.each do |api_data|
6
5
  email = api_data[:email]
7
6
  time = api_data[:time]
8
7
 
9
8
  opt_out = Mailkick::OptOut.where(email: email).order("updated_at desc").first
10
- if !opt_out or (time > opt_out.updated_at and !opt_out.active)
9
+ if !opt_out || (time > opt_out.updated_at && !opt_out.active)
11
10
  Mailkick.opt_out(
12
11
  email: email,
13
12
  user: Mailkick.user_method ? Mailkick.user_method.call(email) : nil,
@@ -18,6 +17,5 @@ module Mailkick
18
17
  end
19
18
  true
20
19
  end
21
-
22
20
  end
23
21
  end
@@ -1,3 +1,3 @@
1
1
  module Mailkick
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/mailkick.rb CHANGED
@@ -7,17 +7,16 @@ require "mailkick/service"
7
7
  require "mailkick/service/mailchimp"
8
8
  require "mailkick/service/mandrill"
9
9
  require "mailkick/service/sendgrid"
10
+ require "mailkick/service/mailgun"
10
11
  require "set"
11
12
 
12
13
  module Mailkick
13
14
  mattr_accessor :services, :user_method, :secret_token
14
15
  self.services = []
15
- self.user_method = proc{|email| User.where(email: email).first rescue nil }
16
+ self.user_method = proc { |email| User.where(email: email).first rescue nil }
16
17
 
17
18
  def self.fetch_opt_outs
18
- services.each do |service|
19
- service.fetch_opt_outs
20
- end
19
+ services.each(&:fetch_opt_outs)
21
20
  end
22
21
 
23
22
  def self.discover_services
@@ -33,7 +32,7 @@ module Mailkick
33
32
  end
34
33
 
35
34
  def self.opt_out(options)
36
- if !opted_out?(options)
35
+ unless opted_out?(options)
37
36
  time = options[:time] || Time.now
38
37
  Mailkick::OptOut.create! do |o|
39
38
  o.email = options[:email]
@@ -90,7 +89,6 @@ module Mailkick
90
89
  def self.opted_out_users(options = {})
91
90
  Set.new(opt_outs(options).where("user_id IS NOT NULL").map(&:user))
92
91
  end
93
-
94
92
  end
95
93
 
96
94
  ActionMailer::Base.send :include, Mailkick::Mailer
data/mailkick.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'mailkick/version'
4
+ require "mailkick/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "mailkick"
8
8
  spec.version = Mailkick::VERSION
9
9
  spec.authors = ["Andrew Kane"]
10
10
  spec.email = ["andrew@chartkick.com"]
11
- spec.summary = %q{Email subscriptions made easy}
12
- spec.description = %q{Email subscriptions made easy}
11
+ spec.summary = "Email subscriptions made easy"
12
+ spec.description = "Email subscriptions made easy"
13
13
  spec.homepage = "https://github.com/ankane/mailkick"
14
14
  spec.license = "MIT"
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-31 00:00:00.000000000 Z
11
+ date: 2015-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,7 @@ files:
66
66
  - lib/mailkick/processor.rb
67
67
  - lib/mailkick/service.rb
68
68
  - lib/mailkick/service/mailchimp.rb
69
+ - lib/mailkick/service/mailgun.rb
69
70
  - lib/mailkick/service/mandrill.rb
70
71
  - lib/mailkick/service/sendgrid.rb
71
72
  - lib/mailkick/version.rb
@@ -95,3 +96,4 @@ signing_key:
95
96
  specification_version: 4
96
97
  summary: Email subscriptions made easy
97
98
  test_files: []
99
+ has_rdoc: