aa_global_notifications 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64f044fd20f3705c61f729d01c9c9e22c0754b3e
4
+ data.tar.gz: 7a8f1e61d160bca468fc402836d98cabca1b4f14
5
+ SHA512:
6
+ metadata.gz: a0446a0991ee13b0cfa5728ce59b1df85b851e303c14d3f9da66eb9a58c87a1235941e9150ff35e5b073c5d9fd5da40874f971f092599a099a0467202ed83998
7
+ data.tar.gz: f6c8b6be52a7c9694615fb6f5982fbd06a3fca66b8b7eb4d7def4c42c6128bef1adad6a696135dcd480f4ecbae0db851dcb457f0b4f7e0c37e46b65ac5ea374d
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = AaGlobalNotifications
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,12 @@
1
+ require "bundler"
2
+ require 'rake'
3
+ Bundler.setup
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ def cmd(command)
7
+ puts command
8
+ raise unless system command
9
+ end
10
+
11
+ # Import all our rake tasks
12
+ FileList['tasks/**/*.rake'].each { |task| import task }
@@ -0,0 +1,73 @@
1
+ module AaGlobalNotifications
2
+ class PushNotification < ActiveRecord::Base
3
+ # Override point in case of collisions, plus keeps the table name tidy.
4
+
5
+ include AASM
6
+
7
+ validates :message, :length => {
8
+ :minimum => 1,
9
+ :maximum => 50
10
+ }
11
+
12
+ validates_presence_of :message, :state
13
+
14
+ self.table_name = "agn_push_notifications"
15
+
16
+ after_create :send_notification
17
+
18
+
19
+ aasm column: :state do
20
+ state :pending, :initial => true
21
+ state :sent
22
+ state :failed
23
+
24
+ event :mark_as_sent do
25
+ transitions :from => [:pending, :failed], :to => :sent
26
+ end
27
+
28
+ event :mark_as_failed do
29
+ transitions :from => :pending, :to => :failed
30
+ end
31
+
32
+ event :resend_notification do
33
+ transitions :from => :failed, :to => :pending
34
+ end
35
+ end
36
+
37
+ def retry!
38
+ resend_notification!
39
+ self.class.delay.send_notification(self.id)
40
+ end
41
+
42
+ def send_notification
43
+ #schedule push notification
44
+ self.class.delay.send_notification(self.id)
45
+ end
46
+
47
+ def self.send_notification(id)
48
+ push_notification = PushNotification.find(id)
49
+ response = push_notification.deliver
50
+
51
+ if response.success?
52
+ push_notification.mark_as_sent
53
+ puts "Push notification sent successfully"
54
+ return true
55
+ else
56
+ push_notification.mark_as_failed
57
+ puts "Push notification failed"
58
+ push_notification.errors[:base] << "Couldn't contact Urban Airship to send push notification"
59
+ return false
60
+ end
61
+ end
62
+
63
+ def deliver
64
+ notification = {
65
+ :aps => {
66
+ :alert => self.message,
67
+ :badge => 1
68
+ }
69
+ }
70
+ Urbanairship.broadcast_push(notification)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,7 @@
1
+ require "aa_global_notifications/engine"
2
+
3
+ module AaGlobalNotifications
4
+ def self.setup
5
+ yield self
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ require 'aasm'
2
+ require 'urbanairship'
3
+
4
+ module AaGlobalNotifications
5
+ class Engine < ::Rails::Engine
6
+ config.generators do |g|
7
+ g.test_framework :rspec, :fixture => false
8
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
9
+ g.assets false
10
+ g.helper false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module AaGlobalNotifications
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class AaGlobalNotifications::InstallGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_migrations
9
+ copy_migration "create_agn_push_notifications"
10
+
11
+ #active_admin push_notifications
12
+ #app/admin/push_notifications.rb
13
+
14
+ puts "Installation successful. You can now run:"
15
+ puts " rake db:migrate"
16
+ end
17
+
18
+ def copy_initializer
19
+ template "initializer.rb", "config/initializers/aa_global_notifications.rb"
20
+ end
21
+
22
+ def config_active_admin
23
+ template "push_notification.rb", "app/admin/push_notification.rb"
24
+ end
25
+
26
+ # This is defined in ActiveRecord::Generators::Base, but that inherits from NamedBase, so it expects a name argument
27
+ # which we don't want here. So we redefine it here. Yuck.
28
+ def self.next_migration_number(dirname)
29
+ if ActiveRecord::Base.timestamped_migrations
30
+ Time.now.utc.strftime("%Y%m%d%H%M%S%L%N")
31
+ else
32
+ "%.3d" % (current_migration_number(dirname) + 1)
33
+ end
34
+ end
35
+
36
+ protected
37
+
38
+ def copy_migration(filename)
39
+ if self.class.migration_exists?("db/migrate", "#{filename}")
40
+ say_status("skipped", "Migration #{filename}.rb already exists")
41
+ else
42
+ migration_template "#{filename}.rb", "db/migrate/#{filename}.rb"
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAgnPushNotifications < ActiveRecord::Migration
2
+ def change
3
+ create_table :agn_push_notifications do |t|
4
+ t.string :message
5
+ t.string :state
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ AaGlobalNotifications.setup do |config|
2
+
3
+ end
4
+
@@ -0,0 +1,32 @@
1
+ ActiveAdmin.register AaGlobalNotifications::PushNotification, :as => "Global Notification" do
2
+ actions :index, :show, :create, :destroy, :new, :update, :edit
3
+
4
+ permit_params :message
5
+
6
+ form do |f|
7
+ f.inputs "Push Notification" do
8
+ f.input :message
9
+ end
10
+ f.actions
11
+ end
12
+
13
+ index do
14
+ column :message
15
+ column :state
16
+ column "Actions" do |notification|
17
+ links = ''.html_safe
18
+ if notification.failed?
19
+ links << link_to("Retry", retry_admin_global_notification_path(notification), :class => "member_link", method: :put)
20
+ links << link_to("Edit", edit_admin_global_notification_path(notification), :class => "member_link")
21
+ end
22
+ links << link_to("View", admin_global_notification_path(notification), :class => "member_link")
23
+ end
24
+ end
25
+
26
+ member_action :retry, method: :put do
27
+ @push_notification = AaGlobalNotifications::PushNotification.find(params[:id])
28
+ @push_notification.retry!
29
+ redirect_to admin_global_notifications_path, flash: { message: "Push notification has been scheduled retry" }
30
+ end
31
+ end
32
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :aa_global_notifications do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aa_global_notifications
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - William Porter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aasm
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: urbanairship
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sidekiq
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-sidekiq
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: factory_girl_rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: capybara
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: awesome_print
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Easily send push notifications to all your mobile users from Active Admin
154
+ email:
155
+ - wp@papercloud.com.au
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - MIT-LICENSE
161
+ - README.rdoc
162
+ - Rakefile
163
+ - app/models/aa_global_notifications/push_notification.rb
164
+ - config/routes.rb
165
+ - lib/aa_global_notifications.rb
166
+ - lib/aa_global_notifications/engine.rb
167
+ - lib/aa_global_notifications/version.rb
168
+ - lib/generators/aa_global_notifications/install/USAGE
169
+ - lib/generators/aa_global_notifications/install/install_generator.rb
170
+ - lib/generators/aa_global_notifications/install/templates/create_agn_push_notifications.rb
171
+ - lib/generators/aa_global_notifications/install/templates/initializer.rb
172
+ - lib/generators/aa_global_notifications/install/templates/push_notification.rb
173
+ - lib/tasks/aa_global_notifications_tasks.rake
174
+ homepage: http://papercloud.com.au
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.2.2
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Send global push notifications through active_admin
198
+ test_files: []