wireframe-apn_on_rails 0.3.0.20110214171409 → 0.3.0.20110214174036

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.
@@ -68,28 +68,27 @@ class APN::Notification < APN::Base
68
68
 
69
69
  # Opens a connection to the Apple APN server and attempts to batch deliver
70
70
  # an Array of notifications.
71
- #
72
- # This method expects an Array of APN::Notifications. If no parameter is passed
73
- # in then it will use the following:
74
- # APN::Notification.all(:conditions => {:sent_at => nil})
75
- #
76
- # As each APN::Notification is sent the <tt>sent_at</tt> column will be timestamped,
77
- # so as to not be sent again.
78
- #
79
71
  # This can be run from the following Rake task:
80
72
  # $ rake apn:notifications:deliver
81
- def send_notifications(notifications = APN::Notification.all(:conditions => {:sent_at => nil}))
82
- return if notifications.nil? || notifications.empty?
73
+ def send_notifications(notifications)
83
74
  sent_ids = []
75
+ sent = false
76
+ message = ''
77
+
78
+ notifications.find_each do |noty|
79
+ sent_ids << noty.id
80
+ message << noty.message_for_sending
81
+ end
82
+
83
+ return if send_ids.empty?
84
+
84
85
  begin
85
86
  APN::Connection.open_for_delivery do |conn, sock|
86
- notifications.each do |noty|
87
- sent_ids << noty.id
88
- conn.write(noty.message_for_sending)
89
- end
87
+ sent = true
88
+ conn.write(message)
90
89
  end
91
90
  ensure
92
- APN::Notification.update_all(['sent_at = ?', Time.now.utc], ['id in (?)', sent_ids]) if sent_ids.any?
91
+ APN::Notification.update_all(['sent_at = ?', Time.now.utc], ['id in (?)', sent_ids]) if sent && sent_ids.any?
93
92
  end
94
93
  end
95
94
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wireframe-apn_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 40220428342901
4
+ hash: 40220428348159
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
9
  - 0
10
- - 20110214171409
11
- version: 0.3.0.20110214171409
10
+ - 20110214174036
11
+ version: 0.3.0.20110214174036
12
12
  platform: ruby
13
13
  authors:
14
14
  - ryan