multi_notifier 0.0.1 → 0.2.0

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: 242f1682aeef6370a9462a404e0958e00fbf675d
4
- data.tar.gz: 6d89c616166db72999c83ee68c364281a59078ff
3
+ metadata.gz: 18b7272fe9939ff98ed918124e371a36c7578a4d
4
+ data.tar.gz: 59486d4edfcbd4ae618480405cd45837e387dc8c
5
5
  SHA512:
6
- metadata.gz: 458a7da9a429f0751b103e3a6f100d5d060132576609ccf4465e4a68e2b29753daf0d5b9b53db56f5b26d34d7f6482518ae0eaf4e4ae19de091178e4dad62c94
7
- data.tar.gz: 9b12e09f5ddbfdd266940cda7d2423ad64098eaec4de5c37551744e992d07a0879a44b385f3ba25254bd452c96e773ad2d55f0324de7a581cf273cfd2f56c8a9
6
+ metadata.gz: 96d5a244e31af51af0247be7b2237ea145fd75ebb72f3720f021246bd40053c02266e389ee5c0142e99c6bac3bf4bc2b69f002c24b3f421c7fce2852f252005b
7
+ data.tar.gz: 0b30d55e430443b34929413251abfd2ef2a37510d50c0cd5e2a1751429a349cb24e4d834eed27a3cf862e55d5966d1df68e013ffef156b605a89c34ef1889104
data/Gemfile CHANGED
@@ -8,4 +8,5 @@ gem "rake"
8
8
  group :test do
9
9
  gem "rspec"
10
10
  gem "actionmailer"
11
+ gem "travis"
11
12
  end
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # MultiNotifier
2
2
 
3
- TODO: Write a gem description
3
+ MultiNotifier provides a minimal, modular and adaptable interface for sending notifications in Ruby.
4
+ It unifies and distills the API for sending notifications to multiple sources with [middlewares](http://en.wikipedia.org/wiki/Middleware).
4
5
 
5
6
  ## Installation
6
7
 
@@ -18,7 +19,42 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
+ ```ruby
23
+ MultiNotifier.build do |builder|
24
+ builder.use :mail, :from => "from@owenou.com", :to => "to@owenou.com", :subject => "MultiNotifier notification"
25
+ builder.use :campfire, :access_token => "123", :room => "123", :message => "Hello world"
26
+ end.notify_all!
27
+ ```
28
+
29
+ ## Middlewares
30
+
31
+ ### Mail
32
+
33
+ The [mail middleware](https://github.com/jingweno/multi_notifier/blob/master/lib/multi_notifier/middlewares/mail.rb) sends email with the provided settings.
34
+
35
+ ```ruby
36
+ builder.adapter :mail,
37
+ :delivery => {
38
+ :method => Rails.configuration.action_mailer.delivery_method, # delivery method
39
+ :settings => Rails.configuration.action_mailer.send("#{Rails.configuration.action_mailer.delivery_method}_settings") # deivery settings
40
+ },
41
+ :from => "notifications@aclgrc.com", # from email
42
+ :to => "devs@workpapers.com", # to email
43
+ :subject => "subject", # email subject
44
+ :text_body => mail_text_body, # email body in text
45
+ :html_body => mail_html_body # email body in html
46
+ ```
47
+
48
+ ### Travis
49
+
50
+ The [travis middleware](https://github.com/jingweno/multi_notifier/blob/master/lib/multi_notifier/middlewares/travis.rb) restart the latest build with the provided repo.
51
+
52
+ ```ruby
53
+ builder.adapter :travis,
54
+ :access_token => "123", # travis-ci access token
55
+ :repo => "jingweno/multiple_notifier", # travis-ci repo in the format of OWNER/REPO
56
+ :travis_pro => true # whether this repo is built in travis-ci pro
57
+ ```
22
58
 
23
59
  ## Contributing
24
60
 
@@ -8,9 +8,9 @@ module MultiNotifier
8
8
  @adapters = []
9
9
  end
10
10
 
11
- def adapter(type, configs = {})
12
- require "multi_notifier/adapters/#{type}"
13
- adapter = "MultiNotifier::Adapters::#{type.to_s.classify}".constantize
11
+ def use(type, configs = {})
12
+ require "multi_notifier/middlewares/#{type}"
13
+ adapter = "MultiNotifier::Middlewares::#{type.to_s.classify}".constantize
14
14
  adapters << adapter.new(configs)
15
15
 
16
16
  adapter
@@ -2,7 +2,7 @@ require "active_model"
2
2
  require_relative "model" unless defined?(ActiveModel::Model)
3
3
 
4
4
  module MultiNotifier
5
- class Adapter
5
+ class Middleware
6
6
  include ActiveModel::Model
7
7
 
8
8
  def notify
@@ -1,9 +1,9 @@
1
1
  require "action_mailer" unless defined?(::ActionMailer)
2
- require "multi_notifier/adapter"
2
+ require "multi_notifier/middleware"
3
3
 
4
4
  module MultiNotifier
5
- module Adapters
6
- class Mail < Adapter
5
+ module Middlewares
6
+ class Mail < Middleware
7
7
  class DeliveryValidator < ::ActiveModel::Validator
8
8
  def validate(model)
9
9
  if model.delivery.present?
@@ -0,0 +1,29 @@
1
+ require "travis" unless defined?(::Travis)
2
+ require "multi_notifier/middleware"
3
+
4
+ module MultiNotifier
5
+ module Middlewares
6
+ class Travis < Middleware
7
+ attr_accessor :access_token, :repo, :travis_pro
8
+
9
+ validates_presence_of :access_token, :repo
10
+
11
+ def notify
12
+ host = travis_pro? ? ::Travis::Client::PRO_URI : ::Travis::Client::ORG_URI
13
+ client = travis_client(host, access_token)
14
+ repo = client.repo(repo)
15
+ repo.last_build.restart
16
+ end
17
+
18
+ def travis_pro?
19
+ !!travis_pro
20
+ end
21
+
22
+ private
23
+
24
+ def travis_client(host, access_token)
25
+ ::Travis::Client.new "uri" => host, "access_token" => access_token
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module MultiNotifier
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,10 +3,10 @@ require "spec_helper"
3
3
  describe MultiNotifier::Builder do
4
4
  it "builds adapter by types" do
5
5
  builder = described_class.new
6
- builder.adapter :mail
6
+ builder.use :mail
7
7
 
8
8
  builder.adapters.size.should == 1
9
9
  adapter = builder.adapters.first
10
- adapter.class.name.should == "MultiNotifier::Adapters::Mail"
10
+ adapter.class.name.should == "MultiNotifier::Middlewares::Mail"
11
11
  end
12
12
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
- require "multi_notifier/adapters/mail"
2
+ require "multi_notifier/middlewares/mail"
3
3
 
4
- describe MultiNotifier::Adapters::Mail do
4
+ describe MultiNotifier::Middlewares::Mail do
5
5
  context "validations" do
6
6
  [:delivery, :from, :to, :subject, :text_body].each do |field|
7
7
  it "#{field} can't be blank" do
@@ -22,7 +22,7 @@ describe MultiNotifier::Adapters::Mail do
22
22
 
23
23
  context "notify" do
24
24
  it "sends email" do
25
- mail = MultiNotifier::Adapters::Mail.new
25
+ mail = MultiNotifier::Middlewares::Mail.new
26
26
  mail.delivery = {
27
27
  :method => :test
28
28
  }
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+ require "multi_notifier/middlewares/travis"
3
+
4
+ describe MultiNotifier::Middlewares::Travis do
5
+ context "validations" do
6
+ [:access_token, :repo].each do |field|
7
+ it "#{field} can't be blank" do
8
+ instance = described_class.new
9
+ instance.should be_invalid
10
+ instance.errors[field].should include("can't be blank")
11
+ end
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jingwen Owen Ou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-16 00:00:00.000000000 Z
11
+ date: 2013-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -37,14 +37,16 @@ files:
37
37
  - README.md
38
38
  - Rakefile
39
39
  - lib/multi_notifier.rb
40
- - lib/multi_notifier/adapter.rb
41
- - lib/multi_notifier/adapters/mail.rb
42
40
  - lib/multi_notifier/builder.rb
41
+ - lib/multi_notifier/middleware.rb
42
+ - lib/multi_notifier/middlewares/mail.rb
43
+ - lib/multi_notifier/middlewares/travis.rb
43
44
  - lib/multi_notifier/model.rb
44
45
  - lib/multi_notifier/version.rb
45
46
  - multi_notifier.gemspec
46
- - spec/multi_notifier/adapters/mail_spec.rb
47
47
  - spec/multi_notifier/builder_spec.rb
48
+ - spec/multi_notifier/middleware/mail_spec.rb
49
+ - spec/multi_notifier/middleware/travis_spec.rb
48
50
  - spec/spec_helper.rb
49
51
  homepage: ''
50
52
  licenses:
@@ -66,11 +68,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
68
  version: '0'
67
69
  requirements: []
68
70
  rubyforge_project:
69
- rubygems_version: 2.0.2
71
+ rubygems_version: 2.0.3
70
72
  signing_key:
71
73
  specification_version: 4
72
74
  summary: Simple and flexbile library for sending notifications
73
75
  test_files:
74
- - spec/multi_notifier/adapters/mail_spec.rb
75
76
  - spec/multi_notifier/builder_spec.rb
77
+ - spec/multi_notifier/middleware/mail_spec.rb
78
+ - spec/multi_notifier/middleware/travis_spec.rb
76
79
  - spec/spec_helper.rb