flowdock-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flowdock-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Björn Wolf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Flowdock::Rails
2
+
3
+ This gem adds a class method to send notifications to specific flows for create and update events on the enabled resource
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'flowdock-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install flowdock-rails
18
+
19
+ ## Usage
20
+
21
+ Just put the `notify_flow` method to your model
22
+
23
+ class Model < ActiveRecord::Base
24
+ notify_flow
25
+ end
26
+
27
+ and dont forget to set the ENV:
28
+
29
+ FLOWDOCK_RAILS_API_TOKEN=__FLOW_API_TOKEN__
30
+
31
+ You can also set the API token directly in your model:
32
+
33
+ class Model < ActiveRecord::Base
34
+ notify_flow api_token: "__FLOW_API_TOKEN__"
35
+ end
36
+
37
+ and of course your are able to notify multiple flows:
38
+
39
+ class Model < ActiveRecord::Base
40
+ notify_flow api_token: ["__FLOW_API_TOKEN__1", "__FLOW_API_TOKEN__2"]
41
+ end
42
+
43
+ or as ENV:
44
+
45
+ FLOWDOCK_RAILS_API_TOKEN=__FLOW_API_TOKEN__1,__FLOW_API_TOKEN__2
46
+
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flowdock/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flowdock-rails"
8
+ spec.version = Flowdock::Rails::VERSION
9
+ spec.authors = ["Björn Wolf"]
10
+ spec.email = ["bjoern@dreimannzelt.de"]
11
+ spec.description = "Gem for notifying flows about the creation and updating of ActiveRecord models."
12
+ spec.summary = "Notify flows of model creations and updates"
13
+ spec.homepage = "http://github.com/dreimannzelt/flowdock-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "flowdock", "~> 0.5"
25
+ spec.add_dependency "activerecord", "> 3.0"
26
+ spec.add_dependency "activesupport", "> 3.0"
27
+ end
@@ -0,0 +1,5 @@
1
+ module Flowdock
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require "flowdock/rails/version"
2
+ require "flowdock"
3
+
4
+ module Flowdock
5
+ module Rails
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ def push_create_notification_to_flow
10
+ self.class.flow.push_to_team_inbox(
11
+ subject: "#{self.class.model_name.human} created",
12
+ content: %Q{
13
+ <h2>#{self.class.model_name.human} created</h2>
14
+ <blockquote>
15
+ #{self.inspect}
16
+ </blockquote>
17
+ },
18
+ tags: [self.class.model_name.param_key, "resource", "created"]
19
+ )
20
+ end
21
+
22
+ def push_update_notification_to_flow
23
+ self.class.flow.push_to_team_inbox(
24
+ subject: "#{self.class.model_name.human} updated",
25
+ content: %Q{
26
+ <h2>#{self.class.model_name.human} updated</h2>
27
+ <blockquote>
28
+ #{self.changes}
29
+ </blockquote>
30
+ },
31
+ tags: [self.class.model_name.param_key, "resource", "updated"]
32
+ )
33
+ end
34
+ end
35
+
36
+ module ClassMethods
37
+ def flow
38
+ api_token = (ENV["FLOWDOCK_RAILS_API_TOKEN"].try(:split, ",") || []).map(&:strip)
39
+
40
+ @flow ||= Flowdock::Flow.new(
41
+ flowdock_rails_options.reverse_merge(
42
+ api_token: api_token,
43
+ source: "Flowdock Notifier",
44
+ from: {
45
+ name: "Marv",
46
+ address: "marv@dreimannzelt.de"
47
+ }
48
+ )
49
+ )
50
+ end
51
+
52
+ def notify_flow(options = {})
53
+ cattr_accessor :flowdock_rails_options
54
+ self.flowdock_rails_options = options
55
+
56
+ after_create :push_create_notification_to_flow
57
+ after_update :push_update_notification_to_flow
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+ ActiveRecord::Base.send :include, Flowdock::Rails
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flowdock-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Björn Wolf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70105221004800 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70105221004800
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70105221004380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70105221004380
36
+ - !ruby/object:Gem::Dependency
37
+ name: flowdock
38
+ requirement: &70105221003820 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.5'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70105221003820
47
+ - !ruby/object:Gem::Dependency
48
+ name: activerecord
49
+ requirement: &70105221003160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>'
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70105221003160
58
+ - !ruby/object:Gem::Dependency
59
+ name: activesupport
60
+ requirement: &70105221002700 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>'
64
+ - !ruby/object:Gem::Version
65
+ version: '3.0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70105221002700
69
+ description: Gem for notifying flows about the creation and updating of ActiveRecord
70
+ models.
71
+ email:
72
+ - bjoern@dreimannzelt.de
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - flowdock-rails.gemspec
83
+ - lib/flowdock/rails.rb
84
+ - lib/flowdock/rails/version.rb
85
+ homepage: http://github.com/dreimannzelt/flowdock-rails
86
+ licenses:
87
+ - MIT
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.10
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Notify flows of model creations and updates
110
+ test_files: []