<commit_before>require "pushofy/version"
require 'rubygems'
require 'socket'
require_relative 'applepayload'
require_relative 'ssl_helper'
require 'openssl'
module Pushofy
  #
  class Push

    def initialize(args = {})
      @id = args[:id]
      @message = args[:message]
      @app = args[:app]
      @from = args[:from]
    end



    def send_push
      device = Device.find(@id)
      device_type = device.device_type
      if device_type == 'IOS' && !device_type.nil?
        send_to_ios(device)
      elsif device_type == 'Android' && !device_type.nil?
        send_to_android(device)
      end
    end

    def send_to_ios(device)

      payload_hash = {}
      payload_hash['aps'] = {}
      payload_hash['aps']['alert'] = {}
      payload_hash['aps']['alert']['body'] = "You have a new #{@app} from #{@from}"
      payload_hash['aps']['sound'] = 'default'
      payload_hash['aps']['badge'] = 1
      payload_hash['app'] = @app
      payload_hash['url'] = @message
      device_token_hex = device.registration_id
      puts "AAAAAA"
      puts payload_hash
      ApplePush.new(payload_hash, device_token_hex).push
    end

    def send_to_android(device)
      body = {}
      arr = []
      arr << device.registration_id
      body['registration_ids'] = arr<commit_msg>replaced the hash syntax of the payload with a new one and also removed the check device.nil from the conditionals<commit_after>require "pushofy/version"
require 'rubygems'
require 'socket'
require_relative 'applepayload'
require_relative 'ssl_helper'
require 'openssl'
module Pushofy
  #
  class Push

    def initialize(args = {})
      @id = args[:id]
      @message = args[:message]
      @app = args[:app]
      @from = args[:from]
    end



    def send_push
      device = Device.find(@id)
      device_type = device.device_type
      if device_type == 'IOS'
        send_to_ios(device)
      elsif device_type == 'Android'
        send_to_android(device)
      end
    end

    def send_to_ios(device)


      payload_hash = {
        aps: {
          alert: {
            body: "You have a new #{@app}, form #{@from}"
          },
          sound: 'default',
          badge: 1,
        },
        app: @app,
        url: @message
      }

      ApplePush.new(payload_hash, device_token_hex).push
    end

    def send_to_android(device)
      body = {}
      arr = []
      arr << device.registration_id
      body['registration_ids'] = arr
{'fraction_non_alphanumeric': 0.12047697368421052, 'fraction_numerical': 0.0008223684210526315, 'mean_word_length': 2.5312046444121914, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '7206113', 'n_tokens_mistral': 785, 'n_tokens_neox': 757, 'n_words': 176}