fireinc-apn_on_rails 0.4.2.5 → 0.4.2.6

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.5"
8
+ s.version = "0.4.2.6"
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"]
@@ -38,26 +38,32 @@ class APN::App < APN::Base
38
38
  end
39
39
 
40
40
  def self.send_notifications_for_cert(the_cert, app_id)
41
+ # unless self.unsent_notifications.nil? || self.unsent_notifications.empty?
42
+ if (app_id == nil)
43
+ conditions = "app_id is null"
44
+ else
45
+ conditions = ["app_id = ?", app_id]
46
+ end
41
47
  begin
42
48
  APN::Connection.open_for_delivery({:cert => the_cert}) do |conn, sock|
43
- devs = APN::Device.where(:app_id => app_id)
44
- unset = APN::Notification.where(:sent_at => nil).where(:device_id => devs.all.collect {|d| d.id}).order(:device_id, :created_at)
45
- unset.each do |noty|
46
- Rails.logger.debug "Sending notification ##{noty.id}"
47
- begin
48
- conn.write(noty.message_for_sending)
49
- rescue => e
50
- Rails.logger.error "Cannot send notification ##{noty.id}: " + e.message
51
- return if e.message == "Broken pipe"
49
+ APN::Device.find_each(:conditions => conditions) do |dev|
50
+ dev.unsent_notifications.each do |noty|
51
+ begin
52
+ conn.write(noty.message_for_sending)
53
+ rescue => e
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
52
59
  end
53
- noty.sent_at = Time.now
54
- noty.save
55
60
  end
56
61
  end
57
62
  rescue Exception => e
58
63
  log_connection_exception(e)
59
64
  end
60
- end
65
+ # end
66
+ end
61
67
 
62
68
  def send_group_notifications
63
69
  if self.cert.nil?
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: 109
4
+ hash: 107
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 2
10
- - 5
11
- version: 0.4.2.5
10
+ - 6
11
+ version: 0.4.2.6
12
12
  platform: ruby
13
13
  authors:
14
14
  - markbates