lib/ass.rb in ass-0.0.18 vs lib/ass.rb in ass-0.0.19

- old
+ new

@@ -109,12 +109,12 @@ ############################################################ ## Sequel Database Setup ############################################################ -unless File.exist?("#{Dir.pwd}/ass.db") then - $DB = Sequel.connect("sqlite://#{Dir.pwd}/ass.db") +unless File.exist?("#{Dir.pwd}/ass-#{$model}.db") then + $DB = Sequel.connect("sqlite://#{Dir.pwd}/ass-#{$model}.db") $DB.create_table :tokens do primary_key :id String :app, :unique => false, :null => false String :token, :unique => false, :null => false, :size => 100 @@ -123,17 +123,17 @@ end $DB.create_table :pushes do primary_key :id String :pid, :unique => true, :null => false, :size => 100 - String :app, :unique => true, :null => false, :size => 30 + String :app, :unique => false, :null => false, :size => 30 String :message, :unique => false, :null => false, :size => 107 Time :created_at - index [:pid, :message] + index [:pid, :app, :message] end else - $DB = Sequel.connect("sqlite://#{Dir.pwd}/ass.db") + $DB = Sequel.connect("sqlite://#{Dir.pwd}/ass-#{$model}.db") end WillPaginate.per_page = 10 # Token = $DB[:tokens] @@ -281,12 +281,12 @@ puts "#{badge} : #{message} extra: #{extra}" if "#{$mode}".strip == 'development' pid = params[:pid] puts "'#{message}' was sent to (#{app}) with pid: [#{pid}], badge:#{badge} , sound: #{sound}, extra:#{extra}" if "#{$mode}".strip == 'development' - @push = Token.where(:app => app) - @exist = Push.first(:pid => pid) + @tokens = Token.where(:app => "#{app}") + @exist = Push.first(:pid => "#{pid}", :app => "#{app}") unless @exist openSSLContext = $certkey["#{app}"] # Connect to port 2195 on the server. sock = nil @@ -299,11 +299,11 @@ sslSocket = OpenSSL::SSL::SSLSocket.new(sock, openSSLContext) sslSocket.connect #Push.create( :pid => pid ) Push.insert(:pid => pid, :message => message, :created_at => Time.now, :app => "#{app}" ) # write our packet to the stream - @push.each do |o| + @tokens.each do |o| tokenText = o[:token] # pack the token to convert the ascii representation back to binary tokenData = [tokenText].pack('H*') # construct the payload po = {:aps => {:alert => "#{message}", :badge => badge, :sound => "#{sound}"}, :extra => "#{extra}"} @@ -326,12 +326,12 @@ puts message if "#{$mode}".strip == 'development' pid = params[:pid] puts "'#{message}' was sent to (#{app}) with pid: [#{pid}]" if "#{$mode}".strip == 'development' - @push = Token.where(:app => app) - @exist = Push.first(:pid => pid) + @tokens = Token.where(:app => "#{app}") + @exist = Push.first(:pid => "#{pid}", :app => "#{app}") unless @exist openSSLContext = $certkey["#{app}"] # Connect to port 2195 on the server. sock = nil @@ -342,12 +342,12 @@ end # do our SSL handshaking sslSocket = OpenSSL::SSL::SSLSocket.new(sock, openSSLContext) sslSocket.connect #Push.create( :pid => pid ) - Push.insert(:pid => pid) + Push.insert(:pid => pid, :message => message, :created_at => Time.now, :app => "#{app}" ) # write our packet to the stream - @push.each do |o| + @tokens.each do |o| tokenText = o[:token] # pack the token to convert the ascii representation back to binary tokenData = [tokenText].pack('H*') # construct the payload po = {:aps => {:alert => "#{message}", :badge => 1}} \ No newline at end of file