rpush 1.0.0-java → 2.0.0-java
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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +37 -22
- data/bin/rpush +13 -4
- data/lib/generators/rpush_generator.rb +2 -0
- data/lib/generators/templates/add_adm.rb +5 -5
- data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +1 -1
- data/lib/generators/templates/add_app_to_rapns.rb +2 -2
- data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
- data/lib/generators/templates/add_gcm.rb +32 -32
- data/lib/generators/templates/add_rpush.rb +67 -67
- data/lib/generators/templates/add_wpns.rb +2 -2
- data/lib/generators/templates/create_rapns_apps.rb +5 -5
- data/lib/generators/templates/create_rapns_feedback.rb +2 -2
- data/lib/generators/templates/create_rapns_notifications.rb +15 -15
- data/lib/generators/templates/rpush.rb +28 -7
- data/lib/generators/templates/rpush_2_0_0_updates.rb +42 -0
- data/lib/rpush/client/active_model/adm/app.rb +23 -0
- data/lib/rpush/client/active_model/adm/data_validator.rb +14 -0
- data/lib/rpush/client/active_model/adm/notification.rb +28 -0
- data/lib/rpush/client/active_model/apns/app.rb +37 -0
- data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +16 -0
- data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +14 -0
- data/lib/rpush/client/active_model/apns/notification.rb +90 -0
- data/lib/rpush/client/active_model/gcm/app.rb +19 -0
- data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +14 -0
- data/lib/rpush/client/active_model/gcm/notification.rb +31 -0
- data/lib/rpush/client/active_model/notification.rb +26 -0
- data/lib/rpush/client/active_model/payload_data_size_validator.rb +13 -0
- data/lib/rpush/client/active_model/registration_ids_count_validator.rb +13 -0
- data/lib/rpush/client/active_model/wpns/app.rb +13 -0
- data/lib/rpush/client/active_model/wpns/notification.rb +17 -0
- data/lib/rpush/client/active_model.rb +21 -0
- data/lib/rpush/client/active_record/adm/app.rb +11 -0
- data/lib/rpush/client/active_record/adm/notification.rb +11 -0
- data/lib/rpush/client/active_record/apns/app.rb +11 -0
- data/lib/rpush/client/active_record/apns/feedback.rb +22 -0
- data/lib/rpush/client/active_record/apns/notification.rb +46 -0
- data/lib/rpush/client/active_record/app.rb +17 -0
- data/lib/rpush/client/active_record/gcm/app.rb +11 -0
- data/lib/rpush/client/active_record/gcm/notification.rb +11 -0
- data/lib/rpush/client/active_record/notification.rb +38 -0
- data/lib/rpush/client/active_record/wpns/app.rb +11 -0
- data/lib/rpush/client/active_record/wpns/notification.rb +11 -0
- data/lib/rpush/client/active_record.rb +19 -0
- data/lib/rpush/client/redis/adm/app.rb +14 -0
- data/lib/rpush/client/redis/adm/notification.rb +11 -0
- data/lib/rpush/client/redis/apns/app.rb +11 -0
- data/lib/rpush/client/redis/apns/feedback.rb +20 -0
- data/lib/rpush/client/redis/apns/notification.rb +11 -0
- data/lib/rpush/client/redis/app.rb +24 -0
- data/lib/rpush/client/redis/gcm/app.rb +11 -0
- data/lib/rpush/client/redis/gcm/notification.rb +11 -0
- data/lib/rpush/client/redis/notification.rb +68 -0
- data/lib/rpush/client/redis/wpns/app.rb +11 -0
- data/lib/rpush/client/redis/wpns/notification.rb +11 -0
- data/lib/rpush/client/redis.rb +35 -0
- data/lib/rpush/configuration.rb +27 -6
- data/lib/rpush/daemon/adm/delivery.rb +56 -55
- data/lib/rpush/daemon/apns/delivery.rb +20 -44
- data/lib/rpush/daemon/apns/feedback_receiver.rb +11 -8
- data/lib/rpush/daemon/apns.rb +6 -5
- data/lib/rpush/daemon/app_runner.rb +103 -99
- data/lib/rpush/daemon/batch.rb +54 -40
- data/lib/rpush/daemon/delivery.rb +13 -3
- data/lib/rpush/daemon/delivery_error.rb +10 -2
- data/lib/rpush/daemon/dispatcher/apns_tcp.rb +114 -0
- data/lib/rpush/daemon/dispatcher/http.rb +3 -3
- data/lib/rpush/daemon/dispatcher/tcp.rb +3 -3
- data/lib/rpush/daemon/dispatcher_loop.rb +37 -23
- data/lib/rpush/daemon/errors.rb +18 -0
- data/lib/rpush/daemon/feeder.rb +28 -39
- data/lib/rpush/daemon/gcm/delivery.rb +19 -20
- data/lib/rpush/daemon/interruptible_sleep.rb +26 -45
- data/lib/rpush/daemon/loggable.rb +2 -4
- data/lib/rpush/daemon/proc_title.rb +16 -0
- data/lib/rpush/daemon/queue_payload.rb +12 -0
- data/lib/rpush/daemon/reflectable.rb +3 -5
- data/lib/rpush/daemon/retry_header_parser.rb +6 -6
- data/lib/rpush/daemon/retryable_error.rb +2 -0
- data/lib/rpush/daemon/ring_buffer.rb +16 -0
- data/lib/rpush/daemon/service_config_methods.rb +23 -7
- data/lib/rpush/daemon/signal_handler.rb +56 -0
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +21 -17
- data/lib/rpush/daemon/store/active_record.rb +71 -38
- data/lib/rpush/daemon/store/interface.rb +19 -0
- data/lib/rpush/daemon/store/redis.rb +149 -0
- data/lib/rpush/daemon/string_helpers.rb +15 -0
- data/lib/rpush/daemon/synchronizer.rb +60 -0
- data/lib/rpush/daemon/tcp_connection.rb +6 -11
- data/lib/rpush/daemon/wpns/delivery.rb +21 -30
- data/lib/rpush/daemon.rb +40 -60
- data/lib/rpush/deprecatable.rb +4 -3
- data/lib/rpush/deprecation.rb +7 -10
- data/lib/rpush/embed.rb +8 -3
- data/lib/rpush/logger.rb +11 -15
- data/lib/rpush/push.rb +1 -2
- data/lib/rpush/reflection.rb +8 -12
- data/lib/rpush/version.rb +1 -1
- data/lib/rpush.rb +5 -29
- data/lib/tasks/quality.rake +35 -0
- data/lib/tasks/test.rake +1 -5
- data/spec/.rubocop.yml +4 -0
- data/spec/functional/adm_spec.rb +3 -6
- data/spec/functional/apns_spec.rb +117 -24
- data/spec/functional/embed_spec.rb +20 -20
- data/spec/functional/gcm_spec.rb +4 -7
- data/spec/functional/new_app_spec.rb +59 -0
- data/spec/functional/retry_spec.rb +46 -0
- data/spec/functional/synchronization_spec.rb +68 -0
- data/spec/functional/wpns_spec.rb +3 -6
- data/spec/functional_spec_helper.rb +26 -0
- data/spec/integration/rpush_spec.rb +13 -0
- data/spec/integration/support/gcm_success_response.json +1 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/support/active_record_setup.rb +48 -0
- data/{config → spec/support/config}/database.yml +0 -0
- data/spec/support/install.sh +43 -7
- data/spec/support/simplecov_helper.rb +9 -5
- data/spec/support/simplecov_quality_formatter.rb +10 -6
- data/spec/unit/apns_feedback_spec.rb +3 -3
- data/spec/unit/{adm → client/active_record/adm}/app_spec.rb +3 -3
- data/spec/unit/{adm → client/active_record/adm}/notification_spec.rb +5 -7
- data/spec/unit/client/active_record/apns/app_spec.rb +29 -0
- data/spec/unit/client/active_record/apns/feedback_spec.rb +9 -0
- data/spec/unit/client/active_record/apns/notification_spec.rb +231 -0
- data/spec/unit/client/active_record/app_spec.rb +30 -0
- data/spec/unit/client/active_record/gcm/app_spec.rb +4 -0
- data/spec/unit/{gcm → client/active_record/gcm}/notification_spec.rb +5 -7
- data/spec/unit/client/active_record/notification_spec.rb +21 -0
- data/spec/unit/client/active_record/wpns/app_spec.rb +4 -0
- data/spec/unit/client/active_record/wpns/notification_spec.rb +21 -0
- data/spec/unit/configuration_spec.rb +12 -5
- data/spec/unit/daemon/adm/delivery_spec.rb +66 -55
- data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +3 -3
- data/spec/unit/daemon/apns/delivery_spec.rb +90 -83
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +22 -17
- data/spec/unit/daemon/app_runner_spec.rb +78 -186
- data/spec/unit/daemon/batch_spec.rb +52 -115
- data/spec/unit/daemon/delivery_spec.rb +15 -1
- data/spec/unit/daemon/dispatcher/http_spec.rb +3 -2
- data/spec/unit/daemon/dispatcher/tcp_spec.rb +10 -9
- data/spec/unit/daemon/dispatcher_loop_spec.rb +6 -24
- data/spec/unit/daemon/feeder_spec.rb +38 -39
- data/spec/unit/daemon/gcm/delivery_spec.rb +122 -101
- data/spec/unit/daemon/reflectable_spec.rb +2 -2
- data/spec/unit/daemon/retryable_error_spec.rb +1 -1
- data/spec/unit/daemon/service_config_methods_spec.rb +6 -3
- data/spec/unit/daemon/signal_handler_spec.rb +95 -0
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +48 -27
- data/spec/unit/daemon/store/active_record_spec.rb +38 -47
- data/spec/unit/daemon/tcp_connection_spec.rb +22 -34
- data/spec/unit/daemon/wpns/delivery_spec.rb +58 -50
- data/spec/unit/daemon_spec.rb +48 -82
- data/spec/unit/embed_spec.rb +6 -4
- data/spec/unit/logger_spec.rb +35 -43
- data/spec/unit/notification_shared.rb +9 -79
- data/spec/unit/push_spec.rb +6 -10
- data/spec/unit/reflection_spec.rb +25 -25
- data/spec/unit/rpush_spec.rb +1 -2
- data/spec/unit_spec_helper.rb +33 -88
- metadata +126 -76
- data/lib/rpush/TODO +0 -3
- data/lib/rpush/adm/app.rb +0 -15
- data/lib/rpush/adm/data_validator.rb +0 -11
- data/lib/rpush/adm/notification.rb +0 -29
- data/lib/rpush/apns/app.rb +0 -29
- data/lib/rpush/apns/binary_notification_validator.rb +0 -12
- data/lib/rpush/apns/device_token_format_validator.rb +0 -12
- data/lib/rpush/apns/feedback.rb +0 -16
- data/lib/rpush/apns/notification.rb +0 -84
- data/lib/rpush/app.rb +0 -18
- data/lib/rpush/daemon/apns/certificate_expired_error.rb +0 -20
- data/lib/rpush/daemon/apns/disconnection_error.rb +0 -20
- data/lib/rpush/daemon/dispatcher_loop_collection.rb +0 -33
- data/lib/rpush/daemon/too_many_requests_error.rb +0 -20
- data/lib/rpush/gcm/app.rb +0 -11
- data/lib/rpush/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +0 -11
- data/lib/rpush/gcm/notification.rb +0 -30
- data/lib/rpush/notification.rb +0 -69
- data/lib/rpush/notifier.rb +0 -52
- data/lib/rpush/payload_data_size_validator.rb +0 -10
- data/lib/rpush/railtie.rb +0 -11
- data/lib/rpush/registration_ids_count_validator.rb +0 -10
- data/lib/rpush/wpns/app.rb +0 -9
- data/lib/rpush/wpns/notification.rb +0 -26
- data/lib/tasks/cane.rake +0 -18
- data/lib/tasks/rpush.rake +0 -16
- data/spec/unit/apns/app_spec.rb +0 -29
- data/spec/unit/apns/feedback_spec.rb +0 -9
- data/spec/unit/apns/notification_spec.rb +0 -208
- data/spec/unit/app_spec.rb +0 -30
- data/spec/unit/daemon/apns/disconnection_error_spec.rb +0 -18
- data/spec/unit/daemon/dispatcher_loop_collection_spec.rb +0 -37
- data/spec/unit/daemon/interruptible_sleep_spec.rb +0 -68
- data/spec/unit/daemon/too_many_requests_error_spec.rb +0 -14
- data/spec/unit/gcm/app_spec.rb +0 -4
- data/spec/unit/notification_spec.rb +0 -15
- data/spec/unit/notifier_spec.rb +0 -49
- data/spec/unit/wpns/app_spec.rb +0 -4
- data/spec/unit/wpns/notification_spec.rb +0 -30
@@ -1,84 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Apns
|
3
|
-
class Notification < Rpush::Notification
|
4
|
-
class MultipleAppAssignmentError < StandardError; end
|
5
|
-
|
6
|
-
validates :device_token, :presence => true
|
7
|
-
validates :badge, :numericality => true, :allow_nil => true
|
8
|
-
|
9
|
-
validates_with Rpush::Apns::DeviceTokenFormatValidator
|
10
|
-
validates_with Rpush::Apns::BinaryNotificationValidator
|
11
|
-
|
12
|
-
alias_method :attributes_for_device=, :data=
|
13
|
-
alias_method :attributes_for_device, :data
|
14
|
-
|
15
|
-
def device_token=(token)
|
16
|
-
write_attribute(:device_token, token.delete(" <>")) if !token.nil?
|
17
|
-
end
|
18
|
-
|
19
|
-
def alert=(alert)
|
20
|
-
if alert.is_a?(Hash)
|
21
|
-
write_attribute(:alert, multi_json_dump(alert))
|
22
|
-
self.alert_is_json = true if has_attribute?(:alert_is_json)
|
23
|
-
else
|
24
|
-
write_attribute(:alert, alert)
|
25
|
-
self.alert_is_json = false if has_attribute?(:alert_is_json)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def alert
|
30
|
-
string_or_json = read_attribute(:alert)
|
31
|
-
|
32
|
-
if has_attribute?(:alert_is_json)
|
33
|
-
if alert_is_json?
|
34
|
-
multi_json_load(string_or_json)
|
35
|
-
else
|
36
|
-
string_or_json
|
37
|
-
end
|
38
|
-
else
|
39
|
-
multi_json_load(string_or_json) rescue string_or_json
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
MDM_KEY = '__rpush_mdm__'
|
44
|
-
def mdm=(magic)
|
45
|
-
self.attributes_for_device = (attributes_for_device || {}).merge({ MDM_KEY => magic })
|
46
|
-
end
|
47
|
-
|
48
|
-
CONTENT_AVAILABLE_KEY = '__rpush_content_available__'
|
49
|
-
def content_available=(bool)
|
50
|
-
return unless bool
|
51
|
-
self.attributes_for_device = (attributes_for_device || {}).merge({ CONTENT_AVAILABLE_KEY => true })
|
52
|
-
end
|
53
|
-
|
54
|
-
def as_json
|
55
|
-
json = ActiveSupport::OrderedHash.new
|
56
|
-
|
57
|
-
if attributes_for_device && attributes_for_device.key?(MDM_KEY)
|
58
|
-
json['mdm'] = attributes_for_device[MDM_KEY]
|
59
|
-
else
|
60
|
-
json['aps'] = ActiveSupport::OrderedHash.new
|
61
|
-
json['aps']['alert'] = alert if alert
|
62
|
-
json['aps']['badge'] = badge if badge
|
63
|
-
json['aps']['sound'] = sound if sound
|
64
|
-
|
65
|
-
if attributes_for_device && attributes_for_device[CONTENT_AVAILABLE_KEY]
|
66
|
-
json['aps']['content-available'] = 1
|
67
|
-
end
|
68
|
-
|
69
|
-
if attributes_for_device
|
70
|
-
non_aps_attributes = attributes_for_device.reject { |k, v| k == CONTENT_AVAILABLE_KEY }
|
71
|
-
non_aps_attributes.each { |k, v| json[k.to_s] = v }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
json
|
76
|
-
end
|
77
|
-
|
78
|
-
def to_binary(options = {})
|
79
|
-
id_for_pack = options[:for_validation] ? 0 : id
|
80
|
-
[1, id_for_pack, expiry, 0, 32, device_token, payload_size, payload].pack("cNNccH*na*")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/lib/rpush/app.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
class App < ActiveRecord::Base
|
3
|
-
self.table_name = 'rpush_apps'
|
4
|
-
|
5
|
-
if Rpush.attr_accessible_available?
|
6
|
-
attr_accessible :name, :environment, :certificate, :password, :connections, :auth_key, :client_id, :client_secret
|
7
|
-
end
|
8
|
-
|
9
|
-
has_many :notifications, :class_name => 'Rpush::Notification', :dependent => :destroy
|
10
|
-
|
11
|
-
validates :name, :presence => true, :uniqueness => { :scope => [:type, :environment] }
|
12
|
-
validates_numericality_of :connections, :greater_than => 0, :only_integer => true
|
13
|
-
|
14
|
-
def service_name
|
15
|
-
raise NotImplementedError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Apns
|
3
|
-
class CertificateExpiredError < StandardError
|
4
|
-
attr_reader :app, :time
|
5
|
-
|
6
|
-
def initialize(app, time)
|
7
|
-
@app = app
|
8
|
-
@time = time
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
message
|
13
|
-
end
|
14
|
-
|
15
|
-
def message
|
16
|
-
"#{app.name} certificate expired at #{time}."
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Apns
|
3
|
-
class DisconnectionError < StandardError
|
4
|
-
attr_reader :code, :description
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@code = nil
|
8
|
-
@description = "APNs disconnected without returning an error."
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
message
|
13
|
-
end
|
14
|
-
|
15
|
-
def message
|
16
|
-
"The APNs disconnected without returning an error. This may indicate you are using an invalid certificate for the host."
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Daemon
|
3
|
-
class DispatcherLoopCollection
|
4
|
-
attr_reader :loops
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@loops = []
|
8
|
-
end
|
9
|
-
|
10
|
-
def push(dispatcher_loop)
|
11
|
-
@loops << dispatcher_loop
|
12
|
-
end
|
13
|
-
|
14
|
-
def pop
|
15
|
-
dispatcher_loop = @loops.pop
|
16
|
-
dispatcher_loop.stop
|
17
|
-
dispatcher_loop.wakeup
|
18
|
-
@loops.map(&:wakeup)
|
19
|
-
dispatcher_loop.wait
|
20
|
-
end
|
21
|
-
|
22
|
-
def size
|
23
|
-
@loops.size
|
24
|
-
end
|
25
|
-
|
26
|
-
def stop
|
27
|
-
@loops.map(&:stop)
|
28
|
-
@loops.map(&:wakeup)
|
29
|
-
@loops.map(&:wait)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
class TooManyRequestsError < StandardError
|
3
|
-
attr_reader :code, :description, :response
|
4
|
-
|
5
|
-
def initialize(code, notification_id, description, response)
|
6
|
-
@code = code
|
7
|
-
@notification_id = notification_id
|
8
|
-
@description = description
|
9
|
-
@response = response
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
message
|
14
|
-
end
|
15
|
-
|
16
|
-
def message
|
17
|
-
"Too many requests for #{@notification_id}, received error #{@code} (#{@description}) - retry after #{@response.header['retry-after']}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/rpush/gcm/app.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Gcm
|
3
|
-
class ExpiryCollapseKeyMutualInclusionValidator < ActiveModel::Validator
|
4
|
-
def validate(record)
|
5
|
-
if record.collapse_key && !record.expiry
|
6
|
-
record.errors[:expiry] << "must be set when using a collapse_key"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Gcm
|
3
|
-
class Notification < Rpush::Notification
|
4
|
-
validates :registration_ids, :presence => true
|
5
|
-
|
6
|
-
validates_with Rpush::PayloadDataSizeValidator, limit: 4096
|
7
|
-
validates_with Rpush::RegistrationIdsCountValidator, limit: 1000
|
8
|
-
|
9
|
-
validates_with Rpush::Gcm::ExpiryCollapseKeyMutualInclusionValidator
|
10
|
-
|
11
|
-
def as_json
|
12
|
-
json = {
|
13
|
-
'registration_ids' => registration_ids,
|
14
|
-
'delay_while_idle' => delay_while_idle,
|
15
|
-
'data' => data
|
16
|
-
}
|
17
|
-
|
18
|
-
if collapse_key
|
19
|
-
json['collapse_key'] = collapse_key
|
20
|
-
end
|
21
|
-
|
22
|
-
if expiry
|
23
|
-
json['time_to_live'] = expiry
|
24
|
-
end
|
25
|
-
|
26
|
-
json
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/rpush/notification.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
class Notification < ActiveRecord::Base
|
3
|
-
include Rpush::MultiJsonHelper
|
4
|
-
|
5
|
-
self.table_name = 'rpush_notifications'
|
6
|
-
|
7
|
-
# TODO: Dump using multi json.
|
8
|
-
serialize :registration_ids
|
9
|
-
|
10
|
-
belongs_to :app, :class_name => 'Rpush::App'
|
11
|
-
|
12
|
-
if Rpush.attr_accessible_available?
|
13
|
-
attr_accessible :badge, :device_token, :sound, :alert, :data, :expiry,:delivered,
|
14
|
-
:delivered_at, :failed, :failed_at, :error_code, :error_description, :deliver_after,
|
15
|
-
:alert_is_json, :app, :app_id, :collapse_key, :delay_while_idle, :registration_ids, :uri
|
16
|
-
end
|
17
|
-
|
18
|
-
validates :expiry, :numericality => true, :allow_nil => true
|
19
|
-
validates :app, :presence => true
|
20
|
-
|
21
|
-
scope :ready_for_delivery, lambda {
|
22
|
-
where('delivered = ? AND failed = ? AND (deliver_after IS NULL OR deliver_after < ?)',
|
23
|
-
false, false, Time.now)
|
24
|
-
}
|
25
|
-
|
26
|
-
scope :for_apps, lambda { |apps|
|
27
|
-
where('app_id IN (?)', apps.map(&:id))
|
28
|
-
}
|
29
|
-
|
30
|
-
scope :completed, lambda { where("delivered = ? OR failed = ?", true, true) }
|
31
|
-
|
32
|
-
def data=(attrs)
|
33
|
-
return unless attrs
|
34
|
-
raise ArgumentError, "must be a Hash" if !attrs.is_a?(Hash)
|
35
|
-
write_attribute(:data, multi_json_dump(attrs.merge(data || {})))
|
36
|
-
end
|
37
|
-
|
38
|
-
def registration_ids=(ids)
|
39
|
-
ids = [ids] if ids && !ids.is_a?(Array)
|
40
|
-
super
|
41
|
-
end
|
42
|
-
|
43
|
-
def data
|
44
|
-
multi_json_load(read_attribute(:data)) if read_attribute(:data)
|
45
|
-
end
|
46
|
-
|
47
|
-
def payload
|
48
|
-
multi_json_dump(as_json)
|
49
|
-
end
|
50
|
-
|
51
|
-
def payload_size
|
52
|
-
payload.bytesize
|
53
|
-
end
|
54
|
-
|
55
|
-
def payload_data_size
|
56
|
-
multi_json_dump(as_json['data']).bytesize
|
57
|
-
end
|
58
|
-
|
59
|
-
class << self
|
60
|
-
def created_before(dt)
|
61
|
-
where("created_at < ?", dt)
|
62
|
-
end
|
63
|
-
|
64
|
-
def completed_and_older_than(dt)
|
65
|
-
completed.created_before(dt)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/lib/rpush/notifier.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
|
3
|
-
module Rpush
|
4
|
-
# This class notifies the sleeping Rpush Daemon that there are new Notifications to send,
|
5
|
-
# and to interrupt its sleep to send them immediately. The purpose of this is to allow
|
6
|
-
# much higher sleep times to reduce database polling activity.
|
7
|
-
class Notifier
|
8
|
-
def initialize(host, port)
|
9
|
-
@host, @port = host, port
|
10
|
-
end
|
11
|
-
|
12
|
-
# notify the daemon that there is a Notification to send.
|
13
|
-
def notify
|
14
|
-
socket.write('x')
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return [UDPSocket]
|
18
|
-
def socket
|
19
|
-
if @socket.nil?
|
20
|
-
@socket = UDPSocket.new
|
21
|
-
@socket.connect(@host, @port)
|
22
|
-
end
|
23
|
-
@socket
|
24
|
-
end
|
25
|
-
|
26
|
-
# close the udp socket
|
27
|
-
def close
|
28
|
-
if @socket
|
29
|
-
@socket.close
|
30
|
-
@socket = nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
# Call this from a client application after saving a Notification to the database to wakeup the Rpush
|
37
|
-
# Daemon to deliver the notification immediately.
|
38
|
-
def self.wakeup
|
39
|
-
notifier.notify
|
40
|
-
end
|
41
|
-
|
42
|
-
# Default notifier instance. This uses the :connect, :port values in Rpush.config.wakeup to connect to the
|
43
|
-
# wakeup socket in the Rpush Daemon. It will fall back to :host, :port if :connect is not specified.
|
44
|
-
def self.notifier
|
45
|
-
unless @notifier
|
46
|
-
if Rpush.config.wakeup
|
47
|
-
@notifier = Notifier.new(Rpush.config.wakeup[:connect] || Rpush.config.wakeup[:host], Rpush.config.wakeup[:port])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
@notifier
|
51
|
-
end
|
52
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
class PayloadDataSizeValidator < ActiveModel::Validator
|
3
|
-
def validate(record)
|
4
|
-
limit = options[:limit] || 1024
|
5
|
-
if !record.data.nil? && record.payload_data_size > limit
|
6
|
-
record.errors[:base] << "Notification payload data cannot be larger than #{limit} bytes."
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
data/lib/rpush/railtie.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
class RegistrationIdsCountValidator < ActiveModel::Validator
|
3
|
-
def validate(record)
|
4
|
-
limit = options[:limit] || 100
|
5
|
-
if record.registration_ids && record.registration_ids.size > limit
|
6
|
-
record.errors[:base] << "Number of registration_ids cannot be larger than #{limit}."
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
data/lib/rpush/wpns/app.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Wpns
|
3
|
-
class Notification < Rpush::Notification
|
4
|
-
validates :uri, presence: true
|
5
|
-
validates :uri, format: { with: /https?:\/\/[\S]+/ }
|
6
|
-
validates :alert, presence: true
|
7
|
-
|
8
|
-
def as_json
|
9
|
-
json = {
|
10
|
-
'message' => alert,
|
11
|
-
'uri' => uri
|
12
|
-
}
|
13
|
-
|
14
|
-
if collapse_key
|
15
|
-
json['consolidationKey'] = collapse_key
|
16
|
-
end
|
17
|
-
|
18
|
-
json
|
19
|
-
end
|
20
|
-
|
21
|
-
def uri_is_valid?
|
22
|
-
return (/https?:\/\/[\S]+/.match(uri) != nil)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/tasks/cane.rake
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'cane/rake_task'
|
3
|
-
|
4
|
-
desc "Run cane to check quality metrics"
|
5
|
-
Cane::RakeTask.new(:quality) do |cane|
|
6
|
-
cane.add_threshold 'coverage/covered_percent', :>=, 98
|
7
|
-
cane.no_style = false
|
8
|
-
cane.style_measure = 1000
|
9
|
-
cane.no_doc = true
|
10
|
-
cane.abc_max = 20
|
11
|
-
end
|
12
|
-
|
13
|
-
namespace :spec do
|
14
|
-
task :cane => ['spec', 'quality']
|
15
|
-
end
|
16
|
-
rescue LoadError
|
17
|
-
warn "cane not available, quality task not provided."
|
18
|
-
end
|
data/lib/tasks/rpush.rake
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
namespace :rpush do
|
2
|
-
namespace :notifications do
|
3
|
-
desc "Delete completed notifications older than number of days (DAYS > 0)"
|
4
|
-
task :clean => :environment do
|
5
|
-
date = (ENV['DAYS'].blank? || ENV['DAYS'].to_i <= 0) ? nil : Time.zone.now.end_of_day - (ENV['DAYS'].to_i).days
|
6
|
-
|
7
|
-
if(date.nil?)
|
8
|
-
puts "DAYS is required and must be greater than 0"
|
9
|
-
else
|
10
|
-
puts "BEG: Delete completed notifications before '#{date}'\n"
|
11
|
-
deleted_count = Rpush::Notification.completed_and_older_than(date).delete_all
|
12
|
-
puts "END: Deleted #{deleted_count} notifications"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/spec/unit/apns/app_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Rpush::App do
|
4
|
-
it 'does not validate an app with an invalid certificate' do
|
5
|
-
app = Rpush::Apns::App.new(:name => 'test', :environment => 'development', :certificate => 'foo')
|
6
|
-
app.valid?
|
7
|
-
app.errors[:certificate].should eq ['Certificate value must contain a certificate and a private key.']
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'validates a certificate without a password' do
|
11
|
-
app = Rpush::Apns::App.new :name => 'test', :environment => 'development', :certificate => TEST_CERT
|
12
|
-
app.valid?
|
13
|
-
app.errors[:certificate].should eq []
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'validates a certificate with a password' do
|
17
|
-
app = Rpush::Apns::App.new :name => 'test', :environment => 'development',
|
18
|
-
:certificate => TEST_CERT_WITH_PASSWORD, :password => 'fubar'
|
19
|
-
app.valid?
|
20
|
-
app.errors[:certificate].should eq []
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'validates a certificate with an incorrect password' do
|
24
|
-
app = Rpush::Apns::App.new :name => 'test', :environment => 'development',
|
25
|
-
:certificate => TEST_CERT_WITH_PASSWORD, :password => 'incorrect'
|
26
|
-
app.valid?
|
27
|
-
app.errors[:certificate].should eq ["Certificate value must contain a certificate and a private key."]
|
28
|
-
end
|
29
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require "unit_spec_helper"
|
2
|
-
|
3
|
-
describe Rpush::Apns::Feedback do
|
4
|
-
it "should validate the format of the device_token" do
|
5
|
-
notification = Rpush::Apns::Feedback.new(:device_token => "{$%^&*()}")
|
6
|
-
notification.valid?.should be_false
|
7
|
-
notification.errors[:device_token].include?("is invalid").should be_true
|
8
|
-
end
|
9
|
-
end
|