rpush 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +99 -0
- data/LICENSE +7 -0
- data/README.md +189 -0
- data/bin/rpush +36 -0
- data/config/database.yml +44 -0
- data/lib/generators/rpush_generator.rb +44 -0
- data/lib/generators/templates/add_adm.rb +23 -0
- data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +9 -0
- data/lib/generators/templates/add_app_to_rapns.rb +11 -0
- data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +9 -0
- data/lib/generators/templates/add_gcm.rb +102 -0
- data/lib/generators/templates/add_rpush.rb +349 -0
- data/lib/generators/templates/add_wpns.rb +16 -0
- data/lib/generators/templates/create_rapns_apps.rb +16 -0
- data/lib/generators/templates/create_rapns_feedback.rb +18 -0
- data/lib/generators/templates/create_rapns_notifications.rb +29 -0
- data/lib/generators/templates/rename_rapns_to_rpush.rb +63 -0
- data/lib/generators/templates/rpush.rb +104 -0
- data/lib/rpush/TODO +3 -0
- data/lib/rpush/adm/app.rb +15 -0
- data/lib/rpush/adm/data_validator.rb +11 -0
- data/lib/rpush/adm/notification.rb +29 -0
- data/lib/rpush/apns/app.rb +29 -0
- data/lib/rpush/apns/binary_notification_validator.rb +12 -0
- data/lib/rpush/apns/device_token_format_validator.rb +12 -0
- data/lib/rpush/apns/feedback.rb +16 -0
- data/lib/rpush/apns/notification.rb +84 -0
- data/lib/rpush/apns_feedback.rb +13 -0
- data/lib/rpush/app.rb +18 -0
- data/lib/rpush/configuration.rb +75 -0
- data/lib/rpush/daemon/adm/delivery.rb +222 -0
- data/lib/rpush/daemon/adm.rb +9 -0
- data/lib/rpush/daemon/apns/certificate_expired_error.rb +20 -0
- data/lib/rpush/daemon/apns/delivery.rb +64 -0
- data/lib/rpush/daemon/apns/disconnection_error.rb +20 -0
- data/lib/rpush/daemon/apns/feedback_receiver.rb +79 -0
- data/lib/rpush/daemon/apns.rb +16 -0
- data/lib/rpush/daemon/app_runner.rb +187 -0
- data/lib/rpush/daemon/batch.rb +115 -0
- data/lib/rpush/daemon/constants.rb +59 -0
- data/lib/rpush/daemon/delivery.rb +28 -0
- data/lib/rpush/daemon/delivery_error.rb +19 -0
- data/lib/rpush/daemon/dispatcher/http.rb +21 -0
- data/lib/rpush/daemon/dispatcher/tcp.rb +30 -0
- data/lib/rpush/daemon/dispatcher_loop.rb +54 -0
- data/lib/rpush/daemon/dispatcher_loop_collection.rb +33 -0
- data/lib/rpush/daemon/feeder.rb +68 -0
- data/lib/rpush/daemon/gcm/delivery.rb +222 -0
- data/lib/rpush/daemon/gcm.rb +9 -0
- data/lib/rpush/daemon/interruptible_sleep.rb +61 -0
- data/lib/rpush/daemon/loggable.rb +31 -0
- data/lib/rpush/daemon/reflectable.rb +13 -0
- data/lib/rpush/daemon/retry_header_parser.rb +23 -0
- data/lib/rpush/daemon/retryable_error.rb +20 -0
- data/lib/rpush/daemon/service_config_methods.rb +33 -0
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +68 -0
- data/lib/rpush/daemon/store/active_record.rb +154 -0
- data/lib/rpush/daemon/tcp_connection.rb +143 -0
- data/lib/rpush/daemon/too_many_requests_error.rb +20 -0
- data/lib/rpush/daemon/wpns/delivery.rb +132 -0
- data/lib/rpush/daemon/wpns.rb +9 -0
- data/lib/rpush/daemon.rb +140 -0
- data/lib/rpush/deprecatable.rb +23 -0
- data/lib/rpush/deprecation.rb +23 -0
- data/lib/rpush/embed.rb +28 -0
- data/lib/rpush/gcm/app.rb +11 -0
- data/lib/rpush/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +11 -0
- data/lib/rpush/gcm/notification.rb +30 -0
- data/lib/rpush/logger.rb +63 -0
- data/lib/rpush/multi_json_helper.rb +16 -0
- data/lib/rpush/notification.rb +69 -0
- data/lib/rpush/notifier.rb +52 -0
- data/lib/rpush/payload_data_size_validator.rb +10 -0
- data/lib/rpush/push.rb +16 -0
- data/lib/rpush/railtie.rb +11 -0
- data/lib/rpush/reflection.rb +58 -0
- data/lib/rpush/registration_ids_count_validator.rb +10 -0
- data/lib/rpush/version.rb +3 -0
- data/lib/rpush/wpns/app.rb +9 -0
- data/lib/rpush/wpns/notification.rb +26 -0
- data/lib/rpush.rb +62 -0
- data/lib/tasks/cane.rake +18 -0
- data/lib/tasks/rpush.rake +16 -0
- data/lib/tasks/test.rake +38 -0
- data/spec/functional/adm_spec.rb +43 -0
- data/spec/functional/apns_spec.rb +58 -0
- data/spec/functional/embed_spec.rb +49 -0
- data/spec/functional/gcm_spec.rb +42 -0
- data/spec/functional/wpns_spec.rb +41 -0
- data/spec/support/cert_with_password.pem +90 -0
- data/spec/support/cert_without_password.pem +59 -0
- data/spec/support/install.sh +32 -0
- data/spec/support/simplecov_helper.rb +20 -0
- data/spec/support/simplecov_quality_formatter.rb +8 -0
- data/spec/tmp/.gitkeep +0 -0
- data/spec/unit/adm/app_spec.rb +58 -0
- data/spec/unit/adm/notification_spec.rb +45 -0
- data/spec/unit/apns/app_spec.rb +29 -0
- data/spec/unit/apns/feedback_spec.rb +9 -0
- data/spec/unit/apns/notification_spec.rb +208 -0
- data/spec/unit/apns_feedback_spec.rb +21 -0
- data/spec/unit/app_spec.rb +30 -0
- data/spec/unit/configuration_spec.rb +45 -0
- data/spec/unit/daemon/adm/delivery_spec.rb +243 -0
- data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +11 -0
- data/spec/unit/daemon/apns/delivery_spec.rb +101 -0
- data/spec/unit/daemon/apns/disconnection_error_spec.rb +18 -0
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +117 -0
- data/spec/unit/daemon/app_runner_spec.rb +292 -0
- data/spec/unit/daemon/batch_spec.rb +232 -0
- data/spec/unit/daemon/delivery_error_spec.rb +13 -0
- data/spec/unit/daemon/delivery_spec.rb +38 -0
- data/spec/unit/daemon/dispatcher/http_spec.rb +33 -0
- data/spec/unit/daemon/dispatcher/tcp_spec.rb +38 -0
- data/spec/unit/daemon/dispatcher_loop_collection_spec.rb +37 -0
- data/spec/unit/daemon/dispatcher_loop_spec.rb +71 -0
- data/spec/unit/daemon/feeder_spec.rb +98 -0
- data/spec/unit/daemon/gcm/delivery_spec.rb +310 -0
- data/spec/unit/daemon/interruptible_sleep_spec.rb +68 -0
- data/spec/unit/daemon/reflectable_spec.rb +27 -0
- data/spec/unit/daemon/retryable_error_spec.rb +14 -0
- data/spec/unit/daemon/service_config_methods_spec.rb +33 -0
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +114 -0
- data/spec/unit/daemon/store/active_record_spec.rb +357 -0
- data/spec/unit/daemon/tcp_connection_spec.rb +287 -0
- data/spec/unit/daemon/too_many_requests_error_spec.rb +14 -0
- data/spec/unit/daemon/wpns/delivery_spec.rb +159 -0
- data/spec/unit/daemon_spec.rb +159 -0
- data/spec/unit/deprecatable_spec.rb +32 -0
- data/spec/unit/deprecation_spec.rb +15 -0
- data/spec/unit/embed_spec.rb +50 -0
- data/spec/unit/gcm/app_spec.rb +4 -0
- data/spec/unit/gcm/notification_spec.rb +36 -0
- data/spec/unit/logger_spec.rb +127 -0
- data/spec/unit/notification_shared.rb +105 -0
- data/spec/unit/notification_spec.rb +15 -0
- data/spec/unit/notifier_spec.rb +49 -0
- data/spec/unit/push_spec.rb +43 -0
- data/spec/unit/reflection_spec.rb +30 -0
- data/spec/unit/rpush_spec.rb +9 -0
- data/spec/unit/wpns/app_spec.rb +4 -0
- data/spec/unit/wpns/notification_spec.rb +30 -0
- data/spec/unit_spec_helper.rb +101 -0
- metadata +304 -0
@@ -0,0 +1,349 @@
|
|
1
|
+
# NOTE TO THE CURIOUS.
|
2
|
+
#
|
3
|
+
# Congratulations on being a diligent developer and vetting the migrations
|
4
|
+
# added to your project!
|
5
|
+
#
|
6
|
+
# You're probably thinking "This migration is huge!". It is, but that doesn't
|
7
|
+
# mean it'll take a long time to run, or that the reason for it being
|
8
|
+
# this size is because of lousy developers.
|
9
|
+
#
|
10
|
+
# Rpush used to be known as Rapns. In an effort to reduce clutter in db/migrate
|
11
|
+
# for new users of Rpush, what you see below is a concatenation of the
|
12
|
+
# migrations added to Rapns over its lifetime.
|
13
|
+
#
|
14
|
+
# The reason for concatenating old migrations - instead of producing a new
|
15
|
+
# one that attempts to recreate their accumulative state - is that I don't
|
16
|
+
# want to introduce any bugs by writing a new migration.
|
17
|
+
#
|
18
|
+
# So while this looks like a scary amount of code, it is in fact the safest
|
19
|
+
# approach. The constituent parts of this migration have been executed
|
20
|
+
# many times, by many people!
|
21
|
+
|
22
|
+
class AddRpush < ActiveRecord::Migration
|
23
|
+
def self.migrations
|
24
|
+
[CreateRapnsNotifications, CreateRapnsFeedback,
|
25
|
+
AddAlertIsJsonToRapnsNotifications, AddAppToRapns,
|
26
|
+
CreateRapnsApps, AddGcm, AddWpns, AddAdm, RenameRapnsToRpush,
|
27
|
+
AddFailAfterToRpushNotifications]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.up
|
31
|
+
migrations.map(&:up)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.down
|
35
|
+
migrations.reverse.each do |m|
|
36
|
+
begin
|
37
|
+
m.down
|
38
|
+
rescue ActiveRecord::StatementInvalid => e
|
39
|
+
p e
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class CreateRapnsNotifications < ActiveRecord::Migration
|
45
|
+
def self.up
|
46
|
+
create_table :rapns_notifications do |t|
|
47
|
+
t.integer :badge, :null => true
|
48
|
+
t.string :device_token, :null => false, :limit => 64
|
49
|
+
t.string :sound, :null => true, :default => "1.aiff"
|
50
|
+
t.string :alert, :null => true
|
51
|
+
t.text :attributes_for_device, :null => true
|
52
|
+
t.integer :expiry, :null => false, :default => 1.day.to_i
|
53
|
+
t.boolean :delivered, :null => false, :default => false
|
54
|
+
t.timestamp :delivered_at, :null => true
|
55
|
+
t.boolean :failed, :null => false, :default => false
|
56
|
+
t.timestamp :failed_at, :null => true
|
57
|
+
t.integer :error_code, :null => true
|
58
|
+
t.string :error_description, :null => true
|
59
|
+
t.timestamp :deliver_after, :null => true
|
60
|
+
t.timestamps
|
61
|
+
end
|
62
|
+
|
63
|
+
add_index :rapns_notifications, [:delivered, :failed, :deliver_after], :name => 'index_rapns_notifications_multi'
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.down
|
67
|
+
if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi', true)
|
68
|
+
remove_index :rapns_notifications, :name => 'index_rapns_notifications_multi'
|
69
|
+
end
|
70
|
+
drop_table :rapns_notifications
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class CreateRapnsFeedback < ActiveRecord::Migration
|
75
|
+
def self.up
|
76
|
+
create_table :rapns_feedback do |t|
|
77
|
+
t.string :device_token, :null => false, :limit => 64
|
78
|
+
t.timestamp :failed_at, :null => false
|
79
|
+
t.timestamps
|
80
|
+
end
|
81
|
+
|
82
|
+
add_index :rapns_feedback, :device_token
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.down
|
86
|
+
if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token, true)
|
87
|
+
remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
|
88
|
+
end
|
89
|
+
drop_table :rapns_feedback
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class AddAlertIsJsonToRapnsNotifications < ActiveRecord::Migration
|
94
|
+
def self.up
|
95
|
+
add_column :rapns_notifications, :alert_is_json, :boolean, :null => true, :default => false
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.down
|
99
|
+
remove_column :rapns_notifications, :alert_is_json
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class AddAppToRapns < ActiveRecord::Migration
|
104
|
+
def self.up
|
105
|
+
add_column :rapns_notifications, :app, :string, :null => true
|
106
|
+
add_column :rapns_feedback, :app, :string, :null => true
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.down
|
110
|
+
remove_column :rapns_notifications, :app
|
111
|
+
remove_column :rapns_feedback, :app
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class CreateRapnsApps < ActiveRecord::Migration
|
116
|
+
def self.up
|
117
|
+
create_table :rapns_apps do |t|
|
118
|
+
t.string :key, :null => false
|
119
|
+
t.string :environment, :null => false
|
120
|
+
t.text :certificate, :null => false
|
121
|
+
t.string :password, :null => true
|
122
|
+
t.integer :connections, :null => false, :default => 1
|
123
|
+
t.timestamps
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.down
|
128
|
+
drop_table :rapns_apps
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class AddGcm < ActiveRecord::Migration
|
133
|
+
module Rapns
|
134
|
+
class App < ActiveRecord::Base
|
135
|
+
self.table_name = 'rapns_apps'
|
136
|
+
end
|
137
|
+
|
138
|
+
class Notification < ActiveRecord::Base
|
139
|
+
belongs_to :app
|
140
|
+
self.table_name = 'rapns_notifications'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.up
|
145
|
+
add_column :rapns_notifications, :type, :string, :null => true
|
146
|
+
add_column :rapns_apps, :type, :string, :null => true
|
147
|
+
|
148
|
+
AddGcm::Rapns::Notification.update_all :type => 'Rapns::Apns::Notification'
|
149
|
+
AddGcm::Rapns::App.update_all :type => 'Rapns::Apns::App'
|
150
|
+
|
151
|
+
change_column :rapns_notifications, :type, :string, :null => false
|
152
|
+
change_column :rapns_apps, :type, :string, :null => false
|
153
|
+
change_column :rapns_notifications, :device_token, :string, { :null => true, :limit => 64 }
|
154
|
+
change_column :rapns_notifications, :expiry, :integer, { :null => true, :default => 1.day.to_i }
|
155
|
+
change_column :rapns_apps, :environment, :string, :null => true
|
156
|
+
change_column :rapns_apps, :certificate, :text, :null => true, :default => nil
|
157
|
+
|
158
|
+
change_column :rapns_notifications, :error_description, :text, :null => true, :default => nil
|
159
|
+
change_column :rapns_notifications, :sound, :string, :default => 'default'
|
160
|
+
|
161
|
+
rename_column :rapns_notifications, :attributes_for_device, :data
|
162
|
+
rename_column :rapns_apps, :key, :name
|
163
|
+
|
164
|
+
add_column :rapns_apps, :auth_key, :string, :null => true
|
165
|
+
|
166
|
+
add_column :rapns_notifications, :collapse_key, :string, :null => true
|
167
|
+
add_column :rapns_notifications, :delay_while_idle, :boolean, :null => false, :default => false
|
168
|
+
|
169
|
+
reg_ids_type = ActiveRecord::Base.connection.adapter_name.include?('Mysql') ? :mediumtext : :text
|
170
|
+
add_column :rapns_notifications, :registration_ids, reg_ids_type, :null => true
|
171
|
+
add_column :rapns_notifications, :app_id, :integer, :null => true
|
172
|
+
add_column :rapns_notifications, :retries, :integer, :null => true, :default => 0
|
173
|
+
|
174
|
+
AddGcm::Rapns::Notification.reset_column_information
|
175
|
+
AddGcm::Rapns::App.reset_column_information
|
176
|
+
|
177
|
+
AddGcm::Rapns::App.all.each do |app|
|
178
|
+
AddGcm::Rapns::Notification.update_all(['app_id = ?', app.id], ['app = ?', app.name])
|
179
|
+
end
|
180
|
+
|
181
|
+
change_column :rapns_notifications, :app_id, :integer, :null => false
|
182
|
+
remove_column :rapns_notifications, :app
|
183
|
+
|
184
|
+
if index_name_exists?(:rapns_notifications, "index_rapns_notifications_multi", true)
|
185
|
+
remove_index :rapns_notifications, :name => "index_rapns_notifications_multi"
|
186
|
+
elsif index_name_exists?(:rapns_notifications, "index_rapns_notifications_on_delivered_failed_deliver_after", false)
|
187
|
+
remove_index :rapns_notifications, :name => "index_rapns_notifications_on_delivered_failed_deliver_after"
|
188
|
+
end
|
189
|
+
add_index :rapns_notifications, [:app_id, :delivered, :failed, :deliver_after], :name => "index_rapns_notifications_multi"
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.down
|
193
|
+
AddGcm::Rapns::Notification.where(:type => 'Rapns::Gcm::Notification').delete_all
|
194
|
+
|
195
|
+
remove_column :rapns_notifications, :type
|
196
|
+
remove_column :rapns_apps, :type
|
197
|
+
|
198
|
+
change_column :rapns_notifications, :device_token, :string, { :null => false, :limit => 64 }
|
199
|
+
change_column :rapns_notifications, :expiry, :integer, { :null => false, :default => 1.day.to_i }
|
200
|
+
change_column :rapns_apps, :environment, :string, :null => false
|
201
|
+
change_column :rapns_apps, :certificate, :text, :null => false
|
202
|
+
|
203
|
+
change_column :rapns_notifications, :error_description, :string, :null => true, :default => nil
|
204
|
+
change_column :rapns_notifications, :sound, :string, :default => '1.aiff'
|
205
|
+
|
206
|
+
rename_column :rapns_notifications, :data, :attributes_for_device
|
207
|
+
rename_column :rapns_apps, :name, :key
|
208
|
+
|
209
|
+
remove_column :rapns_apps, :auth_key
|
210
|
+
|
211
|
+
remove_column :rapns_notifications, :collapse_key
|
212
|
+
remove_column :rapns_notifications, :delay_while_idle
|
213
|
+
remove_column :rapns_notifications, :registration_ids
|
214
|
+
remove_column :rapns_notifications, :retries
|
215
|
+
|
216
|
+
add_column :rapns_notifications, :app, :string, :null => true
|
217
|
+
|
218
|
+
AddGcm::Rapns::Notification.reset_column_information
|
219
|
+
AddGcm::Rapns::App.reset_column_information
|
220
|
+
|
221
|
+
AddGcm::Rapns::App.all.each do |app|
|
222
|
+
AddGcm::Rapns::Notification.update_all(['app = ?', app.key], ['app_id = ?', app.id])
|
223
|
+
end
|
224
|
+
|
225
|
+
if index_name_exists?(:rapns_notifications, :index_rapns_notifications_multi, true)
|
226
|
+
remove_index :rapns_notifications, :name => :index_rapns_notifications_multi
|
227
|
+
end
|
228
|
+
|
229
|
+
remove_column :rapns_notifications, :app_id
|
230
|
+
|
231
|
+
add_index :rapns_notifications, [:delivered, :failed, :deliver_after], :name => :index_rapns_notifications_multi
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
class AddWpns < ActiveRecord::Migration
|
236
|
+
module Rapns
|
237
|
+
class Notification < ActiveRecord::Base
|
238
|
+
self.table_name = 'rapns_notifications'
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def self.up
|
243
|
+
add_column :rapns_notifications, :uri, :string, :null => true
|
244
|
+
end
|
245
|
+
|
246
|
+
def self.down
|
247
|
+
AddWpns::Rapns::Notification.where(:type => 'Rapns::Wpns::Notification').delete_all
|
248
|
+
remove_column :rapns_notifications, :uri
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
class AddAdm < ActiveRecord::Migration
|
253
|
+
module Rapns
|
254
|
+
class Notification < ActiveRecord::Base
|
255
|
+
self.table_name = 'rapns_notifications'
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def self.up
|
260
|
+
add_column :rapns_apps, :client_id, :string, :null => true
|
261
|
+
add_column :rapns_apps, :client_secret, :string, :null => true
|
262
|
+
add_column :rapns_apps, :access_token, :string, :null => true
|
263
|
+
add_column :rapns_apps, :access_token_expiration, :datetime, :null => true
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.down
|
267
|
+
AddAdm::Rapns::Notification.where(:type => 'Rapns::Adm::Notification').delete_all
|
268
|
+
|
269
|
+
remove_column :rapns_apps, :client_id
|
270
|
+
remove_column :rapns_apps, :client_secret
|
271
|
+
remove_column :rapns_apps, :access_token
|
272
|
+
remove_column :rapns_apps, :access_token_expiration
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
class RenameRapnsToRpush < ActiveRecord::Migration
|
277
|
+
module Rpush
|
278
|
+
class App < ActiveRecord::Base
|
279
|
+
self.table_name = 'rpush_apps'
|
280
|
+
end
|
281
|
+
|
282
|
+
class Notification < ActiveRecord::Base
|
283
|
+
self.table_name = 'rpush_notifications'
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
def self.update_type(model, from, to)
|
288
|
+
model.where(type: from).update_all(type: to)
|
289
|
+
end
|
290
|
+
|
291
|
+
def self.up
|
292
|
+
rename_table :rapns_notifications, :rpush_notifications
|
293
|
+
rename_table :rapns_apps, :rpush_apps
|
294
|
+
rename_table :rapns_feedback, :rpush_feedback
|
295
|
+
|
296
|
+
if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi, true)
|
297
|
+
rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
|
298
|
+
end
|
299
|
+
|
300
|
+
if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token, true)
|
301
|
+
rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
|
302
|
+
end
|
303
|
+
|
304
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Apns::Notification', 'Rpush::Apns::Notification')
|
305
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Gcm::Notification', 'Rpush::Gcm::Notification')
|
306
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Adm::Notification', 'Rpush::Adm::Notification')
|
307
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Wpns::Notification', 'Rpush::Wpns::Notification')
|
308
|
+
|
309
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Apns::App', 'Rpush::Apns::App')
|
310
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Gcm::App', 'Rpush::Gcm::App')
|
311
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Adm::App', 'Rpush::Adm::App')
|
312
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Wpns::App', 'Rpush::Wpns::App')
|
313
|
+
end
|
314
|
+
|
315
|
+
def self.down
|
316
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Apns::Notification', 'Rapns::Apns::Notification')
|
317
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Gcm::Notification', 'Rapns::Gcm::Notification')
|
318
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Adm::Notification', 'Rapns::Adm::Notification')
|
319
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Wpns::Notification', 'Rapns::Wpns::Notification')
|
320
|
+
|
321
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Apns::App', 'Rapns::Apns::App')
|
322
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Gcm::App', 'Rapns::Gcm::App')
|
323
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Adm::App', 'Rapns::Adm::App')
|
324
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Wpns::App', 'Rapns::Wpns::App')
|
325
|
+
|
326
|
+
if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
|
327
|
+
rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
|
328
|
+
end
|
329
|
+
|
330
|
+
if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token, true)
|
331
|
+
rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
|
332
|
+
end
|
333
|
+
|
334
|
+
rename_table :rpush_notifications, :rapns_notifications
|
335
|
+
rename_table :rpush_apps, :rapns_apps
|
336
|
+
rename_table :rpush_feedback, :rapns_feedback
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
class AddFailAfterToRpushNotifications < ActiveRecord::Migration
|
341
|
+
def self.up
|
342
|
+
add_column :rpush_notifications, :fail_after, :timestamp, :null => true
|
343
|
+
end
|
344
|
+
|
345
|
+
def self.down
|
346
|
+
remove_column :rpush_notifications, :fail_after
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class AddWpns < ActiveRecord::Migration
|
2
|
+
module Rapns
|
3
|
+
class Notification < ActiveRecord::Base
|
4
|
+
self.table_name = 'rapns_notifications'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.up
|
9
|
+
add_column :rapns_notifications, :uri, :string, :null => true
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
AddWpns::Rapns::Notification.where(:type => 'Rapns::Wpns::Notification').delete_all
|
14
|
+
remove_column :rapns_notifications, :uri
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateRapnsApps < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :rapns_apps do |t|
|
4
|
+
t.string :key, :null => false
|
5
|
+
t.string :environment, :null => false
|
6
|
+
t.text :certificate, :null => false
|
7
|
+
t.string :password, :null => true
|
8
|
+
t.integer :connections, :null => false, :default => 1
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :rapns_apps
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateRapnsFeedback < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :rapns_feedback do |t|
|
4
|
+
t.string :device_token, :null => false, :limit => 64
|
5
|
+
t.timestamp :failed_at, :null => false
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
|
9
|
+
add_index :rapns_feedback, :device_token
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token, true)
|
14
|
+
remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
|
15
|
+
end
|
16
|
+
drop_table :rapns_feedback
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class CreateRapnsNotifications < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :rapns_notifications do |t|
|
4
|
+
t.integer :badge, :null => true
|
5
|
+
t.string :device_token, :null => false, :limit => 64
|
6
|
+
t.string :sound, :null => true, :default => "1.aiff"
|
7
|
+
t.string :alert, :null => true
|
8
|
+
t.text :attributes_for_device, :null => true
|
9
|
+
t.integer :expiry, :null => false, :default => 1.day.to_i
|
10
|
+
t.boolean :delivered, :null => false, :default => false
|
11
|
+
t.timestamp :delivered_at, :null => true
|
12
|
+
t.boolean :failed, :null => false, :default => false
|
13
|
+
t.timestamp :failed_at, :null => true
|
14
|
+
t.integer :error_code, :null => true
|
15
|
+
t.string :error_description, :null => true
|
16
|
+
t.timestamp :deliver_after, :null => true
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
|
20
|
+
add_index :rapns_notifications, [:delivered, :failed, :deliver_after], :name => 'index_rapns_notifications_multi'
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi', true)
|
25
|
+
remove_index :rapns_notifications, :name => 'index_rapns_notifications_multi'
|
26
|
+
end
|
27
|
+
drop_table :rapns_notifications
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class RenameRapnsToRpush < ActiveRecord::Migration
|
2
|
+
module Rpush
|
3
|
+
class App < ActiveRecord::Base
|
4
|
+
self.table_name = 'rpush_apps'
|
5
|
+
end
|
6
|
+
|
7
|
+
class Notification < ActiveRecord::Base
|
8
|
+
self.table_name = 'rpush_notifications'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.update_type(model, from, to)
|
13
|
+
model.where(type: from).update_all(type: to)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.up
|
17
|
+
rename_table :rapns_notifications, :rpush_notifications
|
18
|
+
rename_table :rapns_apps, :rpush_apps
|
19
|
+
rename_table :rapns_feedback, :rpush_feedback
|
20
|
+
|
21
|
+
if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi, true)
|
22
|
+
rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
|
23
|
+
end
|
24
|
+
|
25
|
+
if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token, true)
|
26
|
+
rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
|
27
|
+
end
|
28
|
+
|
29
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Apns::Notification', 'Rpush::Apns::Notification')
|
30
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Gcm::Notification', 'Rpush::Gcm::Notification')
|
31
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Adm::Notification', 'Rpush::Adm::Notification')
|
32
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Wpns::Notification', 'Rpush::Wpns::Notification')
|
33
|
+
|
34
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Apns::App', 'Rpush::Apns::App')
|
35
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Gcm::App', 'Rpush::Gcm::App')
|
36
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Adm::App', 'Rpush::Adm::App')
|
37
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Wpns::App', 'Rpush::Wpns::App')
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.down
|
41
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Apns::Notification', 'Rapns::Apns::Notification')
|
42
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Gcm::Notification', 'Rapns::Gcm::Notification')
|
43
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Adm::Notification', 'Rapns::Adm::Notification')
|
44
|
+
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Wpns::Notification', 'Rapns::Wpns::Notification')
|
45
|
+
|
46
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Apns::App', 'Rapns::Apns::App')
|
47
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Gcm::App', 'Rapns::Gcm::App')
|
48
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Adm::App', 'Rapns::Adm::App')
|
49
|
+
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Wpns::App', 'Rapns::Wpns::App')
|
50
|
+
|
51
|
+
if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
|
52
|
+
rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
|
53
|
+
end
|
54
|
+
|
55
|
+
if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token, true)
|
56
|
+
rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
|
57
|
+
end
|
58
|
+
|
59
|
+
rename_table :rpush_notifications, :rapns_notifications
|
60
|
+
rename_table :rpush_apps, :rapns_apps
|
61
|
+
rename_table :rpush_feedback, :rapns_feedback
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# Rpush configuration. Options set here are overridden by command-line options.
|
2
|
+
|
3
|
+
Rpush.configure do |config|
|
4
|
+
|
5
|
+
# Run in the foreground?
|
6
|
+
# config.foreground = false
|
7
|
+
|
8
|
+
# Frequency in seconds to check for new notifications.
|
9
|
+
# config.push_poll = 2
|
10
|
+
|
11
|
+
# Frequency in seconds to check for feedback
|
12
|
+
# config.feedback_poll = 60
|
13
|
+
|
14
|
+
# Disable APNs error checking after notification delivery.
|
15
|
+
# config.check_for_errors = true
|
16
|
+
|
17
|
+
# ActiveRecord notifications batch size.
|
18
|
+
# config.batch_size = 100
|
19
|
+
|
20
|
+
# Perform updates to the storage backend in batches to reduce IO.
|
21
|
+
# config.batch_storage_updates = true
|
22
|
+
|
23
|
+
# Path to write PID file. Relative to Rails root unless absolute.
|
24
|
+
# config.pid_file = '/path/to/rpush.pid'
|
25
|
+
|
26
|
+
# Define a custom logger.
|
27
|
+
# config.logger = MyLogger.new
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
Rpush.reflect do |on|
|
32
|
+
|
33
|
+
# Called with a Rpush::Apns::Feedback instance when feedback is received
|
34
|
+
# from the APNs that a notification has failed to be delivered.
|
35
|
+
# Further notifications should not be sent to the device.
|
36
|
+
# on.apns_feedback do |feedback|
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Called when a notification is queued internally for delivery.
|
40
|
+
# The internal queue for each app runner can be inspected:
|
41
|
+
#
|
42
|
+
# Rpush::Daemon::AppRunner.runners.each do |app_id, runner|
|
43
|
+
# runner.app
|
44
|
+
# runner.queue_size
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# on.notification_enqueued do |notification|
|
48
|
+
# end
|
49
|
+
|
50
|
+
# Called when a notification is successfully delivered.
|
51
|
+
# on.notification_delivered do |notification|
|
52
|
+
# end
|
53
|
+
|
54
|
+
# Called when notification delivery failed.
|
55
|
+
# Call 'error_code' and 'error_description' on the notification for the cause.
|
56
|
+
# on.notification_failed do |notification|
|
57
|
+
# end
|
58
|
+
|
59
|
+
# Called when a notification will be retried at a later date.
|
60
|
+
# Call 'deliver_after' on the notification for the next delivery date
|
61
|
+
# and 'retries' for the number of times this notification has been retried.
|
62
|
+
# on.notification_will_retry do |notification|
|
63
|
+
# end
|
64
|
+
|
65
|
+
# Called when a TCP connection is lost and will be reconnected.
|
66
|
+
# on.tcp_connection_lost do |app, error|
|
67
|
+
# end
|
68
|
+
|
69
|
+
# Called for each recipient which successfully receives a notification. This
|
70
|
+
# can occur more than once for the same notification when there are multiple
|
71
|
+
# recipients.
|
72
|
+
# on.gcm_delivered_to_recipient do |notification, registration_id|
|
73
|
+
# end
|
74
|
+
|
75
|
+
# Called for each recipient which fails to receive a notification. This
|
76
|
+
# can occur more than once for the same notification when there are multiple
|
77
|
+
# recipients. (do not handle invalid registration IDs here)
|
78
|
+
# on.gcm_failed_to_recipient do |notification, error, registration_id|
|
79
|
+
# end
|
80
|
+
|
81
|
+
# Called when the GCM returns a canonical registration ID.
|
82
|
+
# You will need to replace old_id with canonical_id in your records.
|
83
|
+
# on.gcm_canonical_id do |old_id, canonical_id|
|
84
|
+
# end
|
85
|
+
|
86
|
+
# Called when the GCM returns a failure that indicates an invalid registration id.
|
87
|
+
# You will need to delete the registration_id from your records.
|
88
|
+
# on.gcm_invalid_registration_id do |app, error, registration_id|
|
89
|
+
# end
|
90
|
+
|
91
|
+
# Called when an SSL certificate will expire within 1 month.
|
92
|
+
# Implement on.error to catch errors raised when the certificate expires.
|
93
|
+
# on.ssl_certificate_will_expire do |app, expiration_time|
|
94
|
+
# end
|
95
|
+
|
96
|
+
# Called when the ADM returns a canonical registration ID.
|
97
|
+
# You will need to replace old_id with canonical_id in your records.
|
98
|
+
# on.adm_canonical_id do |old_id, canonical_id|
|
99
|
+
# end
|
100
|
+
|
101
|
+
# Called when an exception is raised.
|
102
|
+
# on.error do |error|
|
103
|
+
# end
|
104
|
+
end
|
data/lib/rpush/TODO
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rpush
|
2
|
+
module Adm
|
3
|
+
class App < Rpush::App
|
4
|
+
validates :client_id, :client_secret, :presence => true
|
5
|
+
|
6
|
+
def access_token_expired?
|
7
|
+
self.access_token_expiration.nil? || self.access_token_expiration < Time.now
|
8
|
+
end
|
9
|
+
|
10
|
+
def service_name
|
11
|
+
'adm'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Rpush
|
2
|
+
module Adm
|
3
|
+
class Notification < Rpush::Notification
|
4
|
+
validates :registration_ids, :presence => true
|
5
|
+
|
6
|
+
validates_with Rpush::PayloadDataSizeValidator, limit: 6144
|
7
|
+
validates_with Rpush::RegistrationIdsCountValidator, limit: 100
|
8
|
+
|
9
|
+
validates_with Rpush::Adm::DataValidator
|
10
|
+
|
11
|
+
def as_json
|
12
|
+
json = {
|
13
|
+
'data' => data
|
14
|
+
}
|
15
|
+
|
16
|
+
if collapse_key
|
17
|
+
json['consolidationKey'] = collapse_key
|
18
|
+
end
|
19
|
+
|
20
|
+
# number of seconds before message is expired
|
21
|
+
if expiry
|
22
|
+
json['expiresAfter'] = expiry
|
23
|
+
end
|
24
|
+
|
25
|
+
json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|