fireinc-apn_on_rails 0.4.2.6 → 0.4.2.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fireinc-apn_on_rails}
|
8
|
-
s.version = "0.4.2.
|
8
|
+
s.version = "0.4.2.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["markbates", "Rebecca Nesson", "Caleb Adam Haye"]
|
@@ -1,16 +1,16 @@
|
|
1
1
|
class APN::App < APN::Base
|
2
|
-
|
2
|
+
|
3
3
|
has_many :groups, :class_name => 'APN::Group', :dependent => :destroy
|
4
4
|
has_many :devices, :class_name => 'APN::Device', :dependent => :destroy
|
5
5
|
has_many :notifications, :through => :devices, :dependent => :destroy
|
6
6
|
has_many :unsent_notifications, :through => :devices
|
7
7
|
has_many :group_notifications, :through => :groups
|
8
8
|
has_many :unsent_group_notifications, :through => :groups
|
9
|
-
|
9
|
+
|
10
10
|
def cert
|
11
11
|
(RAILS_ENV == 'production' ? apn_prod_cert : apn_dev_cert)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# Opens a connection to the Apple APN server and attempts to batch deliver
|
15
15
|
# an Array of group notifications.
|
16
16
|
#
|
@@ -25,9 +25,9 @@ class APN::App < APN::Base
|
|
25
25
|
end
|
26
26
|
APN::App.send_notifications_for_cert(self.cert, self.id)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def self.send_notifications
|
30
|
-
apps = APN::App.all
|
30
|
+
apps = APN::App.all
|
31
31
|
apps.each do |app|
|
32
32
|
app.send_notifications
|
33
33
|
end
|
@@ -36,55 +36,60 @@ class APN::App < APN::Base
|
|
36
36
|
send_notifications_for_cert(global_cert, nil)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def self.send_notifications_for_cert(the_cert, app_id)
|
41
41
|
# unless self.unsent_notifications.nil? || self.unsent_notifications.empty?
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
Rails.logger.error "Cannot send notification ##{noty.id}: " + e.message
|
55
|
-
return if e.message == "Broken pipe"
|
56
|
-
end
|
57
|
-
noty.sent_at = Time.now
|
58
|
-
noty.save
|
59
|
-
end
|
42
|
+
if (app_id == nil)
|
43
|
+
conditions = "app_id is null"
|
44
|
+
else
|
45
|
+
conditions = ["app_id = ?", app_id]
|
46
|
+
end
|
47
|
+
begin
|
48
|
+
APN::Connection.open_for_delivery({:cert => the_cert}) do |conn, sock|
|
49
|
+
APN::Device.find_each(:conditions => conditions) do |dev|
|
50
|
+
dev.unsent_notifications.each do |noty|
|
51
|
+
conn.write(noty.message_for_sending)
|
52
|
+
noty.sent_at = Time.now
|
53
|
+
noty.save
|
60
54
|
end
|
61
55
|
end
|
62
|
-
rescue Exception => e
|
63
|
-
log_connection_exception(e)
|
64
56
|
end
|
57
|
+
rescue Exception => e
|
58
|
+
log_connection_exception(e)
|
59
|
+
end
|
65
60
|
# end
|
66
61
|
end
|
67
|
-
|
62
|
+
|
68
63
|
def send_group_notifications
|
69
|
-
if self.cert.nil?
|
64
|
+
if self.cert.nil?
|
70
65
|
raise APN::Errors::MissingCertificateError.new
|
71
66
|
return
|
72
67
|
end
|
73
|
-
unless self.unsent_group_notifications.nil? || self.unsent_group_notifications.empty?
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
68
|
+
unless self.unsent_group_notifications.nil? || self.unsent_group_notifications.empty?
|
69
|
+
unsent_group_notifications.each do |gnoty|
|
70
|
+
failed = 0
|
71
|
+
devices_to_send = gnoty.devices.count
|
72
|
+
gnoty.devices.find_in_batches(:batch_size => 100) do |devices|
|
73
|
+
APN::Connection.open_for_delivery({:cert => self.cert}) do |conn, sock|
|
74
|
+
devices.each do |device|
|
75
|
+
begin
|
76
|
+
conn.write(gnoty.message_for_sending(device))
|
77
|
+
rescue Exception => e
|
78
|
+
puts e.message
|
79
|
+
failed += 1
|
80
|
+
end
|
81
|
+
end
|
78
82
|
end
|
79
|
-
gnoty.sent_at = Time.now
|
80
|
-
gnoty.save
|
81
83
|
end
|
84
|
+
puts "Sent to: #{devices_to_send - failed}/#{devices_to_send} "
|
85
|
+
gnoty.sent_at = Time.now
|
86
|
+
gnoty.save
|
82
87
|
end
|
83
88
|
end
|
84
89
|
end
|
85
|
-
|
90
|
+
|
86
91
|
def send_group_notification(gnoty)
|
87
|
-
if self.cert.nil?
|
92
|
+
if self.cert.nil?
|
88
93
|
raise APN::Errors::MissingCertificateError.new
|
89
94
|
return
|
90
95
|
end
|
@@ -98,14 +103,14 @@ class APN::App < APN::Base
|
|
98
103
|
end
|
99
104
|
end
|
100
105
|
end
|
101
|
-
|
106
|
+
|
102
107
|
def self.send_group_notifications
|
103
108
|
apps = APN::App.all
|
104
109
|
apps.each do |app|
|
105
110
|
app.send_group_notifications
|
106
111
|
end
|
107
|
-
end
|
108
|
-
|
112
|
+
end
|
113
|
+
|
109
114
|
# Retrieves a list of APN::Device instnces from Apple using
|
110
115
|
# the <tt>devices</tt> method. It then checks to see if the
|
111
116
|
# <tt>last_registered_at</tt> date of each APN::Device is
|
@@ -122,8 +127,10 @@ class APN::App < APN::Base
|
|
122
127
|
return
|
123
128
|
end
|
124
129
|
APN::App.process_devices_for_cert(self.cert)
|
125
|
-
end
|
126
|
-
|
130
|
+
end
|
131
|
+
|
132
|
+
# process_devices
|
133
|
+
|
127
134
|
def self.process_devices
|
128
135
|
apps = APN::App.all
|
129
136
|
apps.each do |app|
|
@@ -134,23 +141,23 @@ class APN::App < APN::Base
|
|
134
141
|
APN::App.process_devices_for_cert(global_cert)
|
135
142
|
end
|
136
143
|
end
|
137
|
-
|
144
|
+
|
138
145
|
def self.process_devices_for_cert(the_cert)
|
139
146
|
puts "in APN::App.process_devices_for_cert"
|
140
147
|
APN::Feedback.devices(the_cert).each do |device|
|
141
148
|
if device.last_registered_at < device.feedback_at
|
142
149
|
puts "device #{device.id} -> #{device.last_registered_at} < #{device.feedback_at}"
|
143
150
|
device.destroy
|
144
|
-
else
|
151
|
+
else
|
145
152
|
puts "device #{device.id} -> #{device.last_registered_at} not < #{device.feedback_at}"
|
146
153
|
end
|
147
|
-
end
|
154
|
+
end
|
148
155
|
end
|
149
|
-
|
150
|
-
|
156
|
+
|
157
|
+
|
151
158
|
protected
|
152
|
-
def
|
159
|
+
def log_connection_exception(ex)
|
153
160
|
puts ex.message
|
154
161
|
end
|
155
|
-
|
162
|
+
|
156
163
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fireinc-apn_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 105
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
9
|
- 2
|
10
|
-
-
|
11
|
-
version: 0.4.2.
|
10
|
+
- 7
|
11
|
+
version: 0.4.2.7
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- markbates
|