actionnotifier 0.1.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: f614704dc7c834cd79f6573d7a8fbac0526c3296
4
+ data.tar.gz: 11bd1305ab35164bb4ab30472c0a7f3e2f4cb1cc
5
+ SHA512:
6
+ metadata.gz: cee7c0f659e723df4b195f304118e5211e8a84ce97a4eac1de99b775d4e5551dd63130dce204ad16b8a365b2074732a4b9800e0f04c3bfba37879f5c9907884b
7
+ data.tar.gz: 4fd4e28b37907e24068967e628cd7291074888dc30f6ce7680bf46c46a16d5abfa163bfaea3568c093760c2512bef8d376b6743b5342997bf5011ef232c6ec98
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_script:
6
+ - "(cd test/dummy && bundle exec rake db:migrate RAILS_ENV=test)"
7
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mail_assertions.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Magnus Hult
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Action Notifier
2
+
3
+ Action Notifier is a small framework for sending push notifications in a way very
4
+ similar to [Action Mailer](https://github.com/rails/rails/tree/master/actionmailer).
5
+
6
+ ## Sending push notifications
7
+
8
+ Analogous to Action Mailer, start by creating an `ApplicationNotifier` in a new
9
+ `app/notifiers` directory in your Rails project.
10
+
11
+ ```ruby
12
+ class ApplicationNotifier < ActionNotifier::Base
13
+ # ActionNotifier::Base has a method notify(app, device_token, message, custom = {})
14
+ # so you will probably need a method that finds the (Rpush) app and the
15
+ # device token (could also be several) to notify a given user. ActionNotifier
16
+ # doesn't know how you store your device tokens, so you need to do the
17
+ # translation yourself.
18
+ #
19
+ # The below implementation is an example where device tokens are stored in
20
+ # a table devices(user_id, type, token) where type is the Rpush app name.
21
+ # In the example we notify all of a user's registered devices.
22
+ def notify(user, message, custom = {})
23
+ user.devices.find_each do |device|
24
+ super(Rpush::App.find_by(name: device.type), device.token, message, custom)
25
+ end
26
+ end
27
+ end
28
+ ```
29
+
30
+ Then create notifiers much as you would mailers in Action Mailer. For example,
31
+ a social networking app may have an `app/notifiers/friend_notifier.rb`:
32
+
33
+ ```ruby
34
+ class FriendNotifier < ApplicationNotifier
35
+ def new_friend(user, friend)
36
+ notify(user, "#{friend.name} added you as a friend!")
37
+ end
38
+ end
39
+ ```
40
+
41
+ Whenever you then want to notify the user, you do
42
+
43
+ ```ruby
44
+ FriendNotifier.new_friend(user, friend)
45
+ ```
46
+
47
+ ## Installation
48
+
49
+ Add this line to your application's Gemfile:
50
+
51
+ ```ruby
52
+ gem 'actionnotifier'
53
+ ```
54
+
55
+ And then execute:
56
+
57
+ $ bundle
58
+
59
+ Or install it yourself as:
60
+
61
+ $ gem install actionnotifer
62
+
63
+ ## Development
64
+
65
+ This section is for people who want to do development work on Action Notifier
66
+ (highly encouraged!).
67
+
68
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
69
+
70
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hult/actionnotifier.
75
+
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -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 'action_notifier/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "actionnotifier"
8
+ spec.version = ActionNotifier::VERSION
9
+ spec.authors = ["Magnus Hult"]
10
+ spec.email = ["magnus@magnushult.se"]
11
+
12
+ spec.summary = %q{Bla bla bla}
13
+ spec.homepage = "https://github.com/hult/actionnotifier"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "rpush", "~> 3.0.0"
24
+ spec.add_dependency "actionpack", "~> 5.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_development_dependency "rails", "~> 5.0", ">= 5.0.0.1"
30
+ spec.add_development_dependency "sqlite3"
31
+ spec.add_development_dependency "mocha"
32
+ end
@@ -0,0 +1,2 @@
1
+ require "action_notifier/version"
2
+ require 'action_notifier/action_notifier'
@@ -0,0 +1,56 @@
1
+ require "abstract_controller"
2
+
3
+ module ActionNotifier
4
+ class Base < AbstractController::Base
5
+
6
+ class << self
7
+ def respond_to?(method, include_private = false)
8
+ super || action_methods.include?(method.to_s)
9
+ end
10
+
11
+ protected
12
+ def method_missing(method_name, *args)
13
+ if respond_to?(method_name)
14
+ new.send(method_name, *args)
15
+ else
16
+ super
17
+ end
18
+ end
19
+ end
20
+
21
+ def notify(app, device_token, message, custom = {})
22
+ if app.is_a? Rpush::Apns::App
23
+ _notify = :notify_apns
24
+ elsif app.is_a? Rpush::Gcm::App
25
+ _notify = :notify_gcm
26
+ else
27
+ raise ArgumentError, "Unsupported app"
28
+ end
29
+
30
+ return send _notify, app, device_token, message, custom
31
+ end
32
+
33
+ def notify_apns(app, device_token, message, custom = {})
34
+ n = Rpush::Apns::Notification.new
35
+ n.app = app
36
+ n.device_token = device_token
37
+ n.alert = message.truncate(110) # TODO: They can be longer now, right?
38
+ if custom[:badge]
39
+ n.badge = custom.delete(:badge)
40
+ end
41
+ n.sound = custom.delete(:sound) || 'default'
42
+ n.data = custom
43
+ n.save!
44
+ return n
45
+ end
46
+
47
+ def notify_gcm(device_token, message, custom = {})
48
+ n = Rpush::Gcm::Notification.new
49
+ n.app = Rpush::Gcm::App.find_by_name("android")
50
+ n.registration_ids = [device_token]
51
+ n.data = { message: message }.merge(custom)
52
+ n.save!
53
+ return n
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module ActionNotifier
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actionnotifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Magnus Hult
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rpush
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 5.0.0.1
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '5.0'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 5.0.0.1
103
+ - !ruby/object:Gem::Dependency
104
+ name: sqlite3
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: mocha
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ description:
132
+ email:
133
+ - magnus@magnushult.se
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".travis.yml"
140
+ - Gemfile
141
+ - LICENSE.txt
142
+ - README.md
143
+ - Rakefile
144
+ - actionnotifier.gemspec
145
+ - lib/action_notifier.rb
146
+ - lib/action_notifier/action_notifier.rb
147
+ - lib/action_notifier/version.rb
148
+ homepage: https://github.com/hult/actionnotifier
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.6.11
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Bla bla bla
172
+ test_files: []