recoil 0.1.0 → 0.1.1

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: 87e82d8f7f24b7d3335c5bd3e7291f1ff80493c9
4
- data.tar.gz: dc33eaacc67cd5ce873b4ce15a4d64727a03eda4
3
+ metadata.gz: 3269c4c5c6231717a8a492750c188db9e1350bff
4
+ data.tar.gz: a9d986089b643cb8919e37f8bd1c1b4ba9ea2701
5
5
  SHA512:
6
- metadata.gz: 5d4757afa6e0e1923eb3de8f1a191d22b69283bf0cee1c0c1b78680195db9fd8300fc9c8d7f649cbdccee7dfe23e4c7caa203a8d6971106eb12910662feb3c1b
7
- data.tar.gz: d5e023713d948071fd7b0abe3119b88e1673e0033e6f2e4b0199e080712ab3754e4fc4d058335ab931211e3cb159372f06f1dd17fba7595c5387fbb626cbb976
6
+ metadata.gz: 82262082b4d30016229756467c6677ee1c9ec871afab8ebb7160f033e1d1b624d757e30e9b2bca1acb1c801ca54ca9cb83a310abfb983ac043fdd0a7b924f25d
7
+ data.tar.gz: a160355df3843dc90698bb8aadea7ea41bad0f713e0e1614e07705b9d3cc0b233a9c25bc4d8d2c7a6ca96a4c52f8c90126a29febd48ac6f7f938867da503d12c
data/.travis.yml CHANGED
@@ -4,7 +4,7 @@ rvm:
4
4
  - 2.1.6
5
5
  - 2.2.2
6
6
  env:
7
- - COVERAGE=true
7
+ - CODECLIMATE_REPO_TOKEN=8320e6374064729f72e516cbad8c8103ba96ceed1f37b00137c8b81f7cc83e5e
8
8
  script:
9
9
  - ./bin/rubocop
10
10
  - ./bin/brakeman
data/README.md CHANGED
@@ -1,36 +1,56 @@
1
1
  # Recoil
2
2
  [![Gem Version](https://badge.fury.io/rb/recoil.svg)](http://badge.fury.io/rb/recoil)
3
3
  [![Build Status](https://travis-ci.org/brightin/recoil.svg?branch=master)](https://travis-ci.org/brightin/recoil)
4
+ [![Code Climate](https://codeclimate.com/github/brightin/recoil/badges/gpa.svg)](https://codeclimate.com/github/brightin/recoil)
5
+ [![Test Coverage](https://codeclimate.com/github/brightin/recoil/badges/coverage.svg)](https://codeclimate.com/github/brightin/recoil/coverage)
4
6
 
5
- Rails delivery method. Send via Amazon SES, but with local blacklist.
7
+ Recoil makes sure you're Amazon SES reputation is preserved by blacklisting emails with a bad reputation. Recoil does this with two simple tools:
6
8
 
7
- Warning: This is an early version of the gem. If you're sending an email to multiple receivers this gem might break in unexpected ways.
9
+ 1. A HTTP-endpoint to receive bounce notifications and saves them in the database.
10
+ 2. A ActionMailer interceptor which is able to filter emails with high-bounce rates.
8
11
 
9
- ## Installation
12
+ ## Getting started
10
13
 
11
- Add this line to your application's Gemfile and run `bundle install`:
14
+ Recoil works with Rails 4.0 onward. You can add it to you Gemfile with:
12
15
 
13
16
  ```ruby
14
17
  gem 'recoil'
15
18
  ```
16
19
 
17
- Copy migrations and run
20
+ Run the bundle command to install it. After you've installed Recoil you need to copy the migrations and migrate the database:
21
+
18
22
  ```ruby
19
23
  rake recoil:install:migrations
20
24
  rake db:migrate
21
25
  ```
22
26
 
23
- Add an initializer: `config/initializers/recoil.rb` with the following content:
27
+ Add the endpoint to your `routes.rb`:
28
+ ```ruby
29
+ mount Recoil::Engine => '/ses'
30
+ ```
31
+
32
+ Add an initializer: `config/initializers/recoil.rb` to initialize the interceptor:
24
33
  ```ruby
25
34
  ActionMailer::Base.register_interceptor(Recoil::Interceptor)
26
35
  ```
27
36
 
28
- Add endpoint to routes:
37
+ You're now ready to subscribe to SNS-notifications. Go to the SES-dashboard > Topics > Create new topic, give it a name and save it. Create a new http/https subscription for this topic with the Recoil-URL as endpoint. Make sure Recoil is mounted to this URL because SNS wil send a verification request as soon as you add the subscription. Lastly, when the subscription is added and verified, you're able to let SES send notifications to the SNS topic. This is configurable in the SES-dashboard.
38
+
39
+ ## Configuration
40
+
41
+ There is just a single configuration option for recoil: `blacklist_threshold`. This is a lamdba with an ActiveRecord-scope as argument. The default configuration is do blacklist all email with 10+ bounces in the last two weeks. This is a very loose policy, but it's easy to change:
42
+
29
43
  ```ruby
30
- mount Recoil::Engine => '/ses'
44
+ # config/initializers/recoil.rb
45
+ Recoil.blacklist_threshold = ->(scope) { scope.where('created_at > ?', 1.week.ago).count > 10 }
31
46
  ```
32
47
 
33
- Subscribe to SES notifications... and profit!
48
+ ##RDocs
49
+
50
+ You can view the Recoil documentation in RDoc format here:
51
+
52
+ http://rubydoc.info/github/brightin/recoil
53
+
34
54
 
35
55
  ## Contributing
36
56
 
data/lib/recoil.rb CHANGED
@@ -6,8 +6,4 @@ require 'recoil/message'
6
6
  module Recoil
7
7
  mattr_accessor :blacklist_threshold
8
8
  @@blacklist_threshold = ->(scope) { scope.where('created_at > ?', 2.weeks.ago).count > 10 }
9
-
10
- def self.setup
11
- yield self
12
- end
13
9
  end
@@ -1,9 +1,8 @@
1
1
  module Recoil
2
2
  class Interceptor
3
3
  def self.delivering_email(message)
4
- if message.to.any? { |email| Email.new(email).blacklisted? }
5
- message.perform_deliveries = false
6
- end
4
+ # cannot use reject! because .to is not a plain ruby-array.
5
+ message.to = message.to.reject { |email| Email.new(email).blacklisted? }
7
6
  end
8
7
  end
9
8
  end
@@ -1,3 +1,3 @@
1
1
  module Recoil
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/recoil.gemspec CHANGED
@@ -21,11 +21,11 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency 'aws-sdk', '< 2'
22
22
 
23
23
  s.add_development_dependency 'brakeman'
24
+ s.add_development_dependency 'codeclimate-test-reporter'
24
25
  s.add_development_dependency 'rspec'
25
26
  s.add_development_dependency 'rspec-rails'
26
27
  s.add_development_dependency 'rubocop'
27
28
  s.add_development_dependency 'rubocop-rspec'
28
- s.add_development_dependency 'simplecov'
29
29
  s.add_development_dependency 'sqlite3'
30
30
  s.add_development_dependency 'vcr', '~> 2.9.0'
31
31
  s.add_development_dependency 'webmock', '~> 1.20.0'
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Recoil
4
+ RSpec.describe Interceptor do
5
+ FakeMessage = Struct.new(:to)
6
+
7
+ describe '.delivering_email' do
8
+ it 'does send all email' do
9
+ message = FakeMessage.new(['example@example.com', 'example2@example.com'])
10
+ Interceptor.delivering_email(message)
11
+ expect(message.to).to eq ['example@example.com', 'example2@example.com']
12
+ end
13
+
14
+ it 'does not send email which are blacklisted' do
15
+ message = FakeMessage.new(['example@example.com', 'example2@example.com'])
16
+
17
+ email_instance = double(:email, blacklisted?: true)
18
+ email_instance2 = double(:email, blacklisted?: false)
19
+
20
+ allow(Email).to receive(:new).with('example@example.com') { email_instance }
21
+ allow(Email).to receive(:new).with('example2@example.com') { email_instance2 }
22
+
23
+ Interceptor.delivering_email(message)
24
+
25
+ expect(message.to).to eq ['example2@example.com']
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'recoil/message/abstract'
3
+
4
+ RSpec.describe Recoil::Message::Abstract do
5
+ it 'performs a http get on the url' do
6
+ expect {
7
+ described_class.new({}).process!
8
+ }.to raise_error(NotImplementedError)
9
+ end
10
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
2
  ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
3
3
 
4
- if ENV['COVERAGE']
5
- require 'simplecov'
6
- SimpleCov.start do
7
- minimum_coverage 90
8
- add_filter '/spec/'
9
- end
4
+ if ENV['CODECLIMATE_REPO_TOKEN']
5
+ require 'codeclimate-test-reporter'
6
+ CodeClimate::TestReporter.start
10
7
  end
11
8
 
12
9
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
@@ -41,4 +38,5 @@ VCR.configure do |c|
41
38
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
42
39
  c.hook_into :webmock
43
40
  c.configure_rspec_metadata!
41
+ c.ignore_hosts 'codeclimate.com'
44
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recoil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brightin
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec-rails
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rubocop
84
+ name: rspec-rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rubocop-rspec
98
+ name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: simplecov
112
+ name: rubocop-rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -242,6 +242,8 @@ files:
242
242
  - spec/dummy/public/favicon.ico
243
243
  - spec/fixtures/vcr_cassettes/Recoil_Message_SubscriptionConfirmation/performs_a_http_get_on_the_url.yml
244
244
  - spec/recoil/email_spec.rb
245
+ - spec/recoil/interceptor_spec.rb
246
+ - spec/recoil/message/abstract_spec.rb
245
247
  - spec/recoil/message/notification_spec.rb
246
248
  - spec/recoil/message/subscription_confirmation_spec.rb
247
249
  - spec/recoil/message_spec.rb
@@ -316,6 +318,8 @@ test_files:
316
318
  - spec/dummy/public/favicon.ico
317
319
  - spec/fixtures/vcr_cassettes/Recoil_Message_SubscriptionConfirmation/performs_a_http_get_on_the_url.yml
318
320
  - spec/recoil/email_spec.rb
321
+ - spec/recoil/interceptor_spec.rb
322
+ - spec/recoil/message/abstract_spec.rb
319
323
  - spec/recoil/message/notification_spec.rb
320
324
  - spec/recoil/message/subscription_confirmation_spec.rb
321
325
  - spec/recoil/message_spec.rb