communique 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4282da96cb9a61a9691507909e8d511f2da8fa4b
4
+ data.tar.gz: 09dc4429a835f01447c008e1e4e23db770cff6ea
5
+ SHA512:
6
+ metadata.gz: 2bf8e0dbfe3afe81ed803695cc0ffc30e492f8af1ee81e1e320556ac16d125aeef5efed70220e56559f0048e6155d1730c818ef0b372c6a55e5771c78c4fdd0c
7
+ data.tar.gz: ac9c69e09463481bda95285af9252836ad71481238f977f11e8292034bc054b64383e39a263e49a2a038d7fdda04109e83ca7ec847cccc38b96201aed44ee251
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in communique.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Vestorly
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,34 @@
1
+ # Communiqué
2
+
3
+ Simple way to store warnings and errors affecting users as messages. Stored
4
+ messages can be linked to a helpful link so they can read more about the problem
5
+
6
+ to test it out without a rails environment
7
+ `irb -Ilib -rcommunique`
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'communique'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install communique
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/Vestorly/communique/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'communique/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "communique"
8
+ spec.version = Communique::VERSION
9
+ spec.authors = ["Michael Polycarpou"]
10
+ spec.email = ["michaelpolycarpou@gmail.com"]
11
+ spec.summary = %q{
12
+ Simple way to store warnings and errors affecting users as messages. Stored
13
+ messages can be linked to a helpful link so they can read more about the problem
14
+ }
15
+ spec.description = %q{
16
+ Includes a couple models and an api to make it easy to create notifications and
17
+ the actions associated with them.
18
+ }
19
+ spec.homepage = "https://www.vestorly.com/"
20
+ spec.license = "MIT"
21
+
22
+ spec.files = `git ls-files -z`.split("\x0")
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.7"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "mongoid", "~> 4.0"
30
+ spec.add_development_dependency 'rspec', "~> 3.2"
31
+ spec.add_development_dependency "database_cleaner", "~> 1.4"
32
+ end
@@ -0,0 +1,12 @@
1
+ development:
2
+ sessions:
3
+ default:
4
+ database: communique_development
5
+ hosts:
6
+ - localhost:27017
7
+ test:
8
+ sessions:
9
+ default:
10
+ database: communique_test
11
+ hosts:
12
+ - localhost:27017
data/lib/communique.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "communique/version"
2
+ require "communique/configuration"
3
+ require "communique/models/action"
4
+ require "communique/models/notifiable"
5
+ require "communique/models/notification"
6
+ require "communique/handler"
7
+
8
+ module Communique
9
+ def self.notify(notifiable, action_key, context_info=nil)
10
+ action = Action.find_or_create_by(key: action_key)
11
+
12
+ notification = Notification.create(
13
+ notifiable: notifiable,
14
+ context_info: context_info,
15
+ action_key: action_key,
16
+ action: action
17
+ )
18
+
19
+ Handler.external_services notification
20
+
21
+ notification.id.to_s
22
+ end
23
+
24
+ def self.actions
25
+ Action.all.to_a
26
+ end
27
+
28
+ def self.viewed_all! notifiable
29
+ Notification.viewed_all! notifiable
30
+ end
31
+
32
+ end
@@ -0,0 +1,19 @@
1
+ module Communique
2
+ class << self
3
+ attr_accessor :config
4
+ end
5
+
6
+ def self.configure(&block)
7
+ self.config ||= Configuration.new
8
+ yield config if block_given?
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :user_klass
13
+ attr_accessor :notification_handler
14
+
15
+ def set_notification_handler(&block)
16
+ @notification_handler = block
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module Communique
2
+ class NotificationHandlerNotCallable < StandardError; end
3
+ class Handler
4
+ def self.external_services notification
5
+ config = Communique.config
6
+ return if config.nil?
7
+ return if config.notification_handler.nil?
8
+
9
+ validate_notification_handler!(config.notification_handler)
10
+ config.notification_handler.call(
11
+ notification,
12
+ notification.action,
13
+ notification.notifiable
14
+ )
15
+ end
16
+
17
+ def self.validate_notification_handler!(handler)
18
+ if !handler.respond_to? :call
19
+ raise NotificationHandlerNotCallable.new(
20
+ "notification_handler needs to be nil or a callable block"
21
+ )
22
+ end
23
+ end
24
+
25
+ private_class_method :validate_notification_handler!
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'mongoid'
2
+ module Communique
3
+ class Action
4
+ include ::Mongoid::Document
5
+ include ::Mongoid::Timestamps
6
+
7
+ field :key
8
+ field :name
9
+ field :url
10
+ field :description
11
+ field :image_url
12
+ field :level
13
+ field :send_email, type: Boolean, default: false
14
+ has_many :notifications
15
+
16
+ def act
17
+ 'lets act on this'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ module Communique
2
+ module Notifiable
3
+
4
+ extend ActiveSupport::Concern
5
+ included do
6
+ has_many :notifications,
7
+ class_name: 'Communique::Notification',
8
+ as: :notifiable
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ require 'mongoid'
2
+ module Communique
3
+ class Notification
4
+ include ::Mongoid::Document
5
+ include ::Mongoid::Timestamps
6
+
7
+ field :seen, type: Boolean, default: false
8
+ field :action_key
9
+ field :context_info, type: Hash
10
+
11
+ belongs_to :notifiable, polymorphic: true
12
+ belongs_to :action
13
+
14
+ def notify
15
+ 'successful notification'
16
+ end
17
+
18
+ def self.viewed_all! notifiable
19
+ notifiable.notifications.update_all(seen: true)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Communique
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+ describe Communique do
3
+
4
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+ describe Communique::Handler do
3
+ describe '#external_services' do
4
+ context 'no config block' do
5
+
6
+ it 'works with no config block' do
7
+ expect(Communique::Handler).to receive(:external_services).and_return nil
8
+
9
+ dummy = NotifiableDummy.create
10
+ Communique.notify(
11
+ dummy,
12
+ 'death_star_deadlock',
13
+ name: 'locked star',
14
+ location: 'it moves really fast'
15
+ )
16
+ end
17
+ end
18
+
19
+ context 'with config block' do
20
+ let(:dummy_handler){HandlerDummy.new}
21
+ before(:each) do
22
+
23
+ Communique.configure do |config|
24
+ config.set_notification_handler do |notification, action, dummy|
25
+ dummy_handler.push_notification(notification, action, dummy)
26
+ end
27
+ end
28
+ end
29
+
30
+ it 'external block gets called' do
31
+ dummy = NotifiableDummy.create
32
+ Communique.notify(
33
+ dummy,
34
+ 'death_star_deadlock',
35
+ name: 'locked star',
36
+ location: 'it moves really fast'
37
+ )
38
+
39
+ expect(dummy_handler.notification.context_info[:name]).to eq('locked star')
40
+ expect(dummy_handler.action.key).to eq('death_star_deadlock')
41
+ expect(dummy_handler.notifiable.class.name).to eq('NotifiableDummy')
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+ describe Communique::Notification do
3
+ describe '#viewed_all' do
4
+ it 'makes all notifications seen' do
5
+ dummy = NotifiableDummy.create
6
+ Communique.notify(
7
+ dummy,
8
+ 'r2d2_broke_with_a_500',
9
+ name: 'broken robot',
10
+ location: 'proxy issue'
11
+ )
12
+ Communique.notify(
13
+ dummy,
14
+ '3CPO_fell_down_and_hit_his_head',
15
+ name: 'broken robot',
16
+ location: 'nginx caching issue'
17
+ )
18
+ expect(dummy.notifications.count).to be 2
19
+
20
+ expect(dummy.notifications.first.seen).to be false
21
+ expect(dummy.notifications.last.seen).to be false
22
+
23
+ Communique.viewed_all! dummy
24
+ dummy.reload
25
+
26
+ expect(dummy.notifications.first.seen).to be true
27
+ expect(dummy.notifications.last.seen).to be true
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
2
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), './models'))
3
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../config'))
4
+
5
+ require 'database_cleaner'
6
+ require 'mongoid'
7
+ require 'communique'
8
+ require "support/dummy/notifiable_dummy.rb"
9
+ require "support/dummy/handler_dummy.rb"
10
+ require "models/notification_spec.rb"
11
+
12
+ Mongoid.load!("./config/mongoid.yml", :test)
13
+
14
+ RSpec.configure do |config|
15
+ config.before(:suite) do
16
+ DatabaseCleaner.strategy = :truncation
17
+ DatabaseCleaner.clean_with(:truncation)
18
+ end
19
+
20
+ config.around(:each) do |example|
21
+ DatabaseCleaner.cleaning do
22
+ example.run
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ class HandlerDummy
2
+ attr_reader :notification
3
+ attr_reader :action
4
+ attr_reader :notifiable
5
+
6
+ def push_notification notification, action, notifiable
7
+ @notification = notification
8
+ @action = action
9
+ @notifiable = notifiable
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ require 'mongoid'
2
+ class NotifiableDummy
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ include Communique::Notifiable
6
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+ require 'pry'
3
+ describe NotifiableDummy do
4
+ # it 'has a configuration already set' do
5
+ # expect(Communique.config).to_not be_nil
6
+ # end
7
+
8
+ it 'has notifications' do
9
+ dummy = NotifiableDummy.new
10
+
11
+ Communique.notify(
12
+ dummy,
13
+ 'pleasant_day',
14
+ name: 'hello',
15
+ problem: 'beautiful day'
16
+
17
+ )
18
+ expect(dummy.notifications.first.context_info[:name]).to eq('hello')
19
+
20
+ end
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: communique
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Polycarpou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongoid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.4'
83
+ description: "\n Includes a couple models and an api to make it easy to create
84
+ notifications and\n the actions associated with them.\n "
85
+ email:
86
+ - michaelpolycarpou@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - communique.gemspec
97
+ - config/mongoid.yml
98
+ - lib/communique.rb
99
+ - lib/communique/configuration.rb
100
+ - lib/communique/handler.rb
101
+ - lib/communique/models/action.rb
102
+ - lib/communique/models/notifiable.rb
103
+ - lib/communique/models/notification.rb
104
+ - lib/communique/version.rb
105
+ - spec/communique_spec.rb
106
+ - spec/models/handler_spec.rb
107
+ - spec/models/notification_spec.rb
108
+ - spec/spec_helper.rb
109
+ - spec/support/dummy/handler_dummy.rb
110
+ - spec/support/dummy/notifiable_dummy.rb
111
+ - spec/support/dummy/notifiable_dummy_spec.rb
112
+ homepage: https://www.vestorly.com/
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.3
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Simple way to store warnings and errors affecting users as messages. Stored
136
+ messages can be linked to a helpful link so they can read more about the problem
137
+ test_files:
138
+ - spec/communique_spec.rb
139
+ - spec/models/handler_spec.rb
140
+ - spec/models/notification_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/support/dummy/handler_dummy.rb
143
+ - spec/support/dummy/notifiable_dummy.rb
144
+ - spec/support/dummy/notifiable_dummy_spec.rb
145
+ has_rdoc: