<commit_before>class PushNotification

	CONFIG = YAML.load_file(Rails.root.join("config/gcm.yml"))[Rails.env]
	def self.send_post_chat_notifications(chat)
        gcm = GCM.new(CONFIG["api_key"])
		chat.chatable.members.each do |mem|
			next if mem == chat.user || mem.is_online?(chat.chatable)
			devices = mem.device_tokens
			tokens = devices.map{|t| t.token}
			if !tokens.blank?
				response = gcm.send(tokens, {:data => {:message => chat.notify_text, 
					:redirect_url => Rails.application.routes.url_helpers.post_chats_path(chat.chatable, :auth_key => mem.user_auth_key, :uid => mem.id)}})
				Rails.logger.info "gcm log: notification sent to #{mem.name}(#{mem.id}) with #{tokens.length} devices"
				self.process_gcm_response(response, devices)
			end
		end
	end

	def self.process_gcm_response(response, devices)
		begin
            response = JSON.parse(response[:body])
            puts "failed = ", response["failure"], "out of", devices.length
            response["results"].each_with_index do |res, i|
                if res["message_id"]
                    if res["registration_id"]
                        devices[i].token = res["registration_id"]
                        devices[i].save!
                    	ExceptionNotifier.notify_exception(Exception.new("Token not registered"), :data => {:response => response.inspect})
                    end
                elsif res["error"] == "NotRegistered"
                    devices[i].valid_token = false
                    devices[i].save
                end
            end
        rescue JSON::ParserError => e
            ExceptionNotifier.notify_exception(e)
        end
	end
end<commit_msg>postion exception<commit_after>class PushNotification

	CONFIG = YAML.load_file(Rails.root.join("config/gcm.yml"))[Rails.env]
	def self.send_post_chat_notifications(chat)
        gcm = GCM.new(CONFIG["api_key"])
		chat.chatable.members.each do |mem|
			next if mem == chat.user || mem.is_online?(chat.chatable)
			devices = mem.device_tokens
			tokens = devices.map{|t| t.token}
			if !tokens.blank?
				response = gcm.send(tokens, {:data => {:message => chat.notify_text, 
					:redirect_url => Rails.application.routes.url_helpers.post_chats_path(chat.chatable, :auth_key => mem.user_auth_key, :uid => mem.id)}})
				Rails.logger.info "gcm log: notification sent to #{mem.name}(#{mem.id}) with #{tokens.length} devices"
				self.process_gcm_response(response, devices)
			end
		end
	end

	def self.process_gcm_response(response, devices)
		begin
            response = JSON.parse(response[:body])
            puts "failed = ", response["failure"], "out of", devices.length
            response["results"].each_with_index do |res, i|
                if res["message_id"]
                    if res["registration_id"]
                    	ExceptionNotifier.notify_exception(Exception.new("Token not registered"), :data => {:response => response.inspect})
                        devices[i].token = res["registration_id"]
                        devices[i].save!
                    end
                elsif res["error"] == "NotRegistered"
                    devices[i].valid_token = false
                    devices[i].save
                end
            end
        rescue JSON::ParserError => e
            ExceptionNotifier.notify_exception(e)
        end
	end
end
{'fraction_non_alphanumeric': 0.12462552426602756, 'fraction_numerical': 0.0, 'mean_word_length': 2.4281314168377826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2206638', 'n_tokens_mistral': 1055, 'n_tokens_neox': 970, 'n_words': 188}