<commit_before># frozen-string-literal: true

require 'json'
require 'active_support/string_inquirer'

module Pushing
  module Adapters
    class LowdownAdapter
      @@clients   = {}
      @@semaphore = Mutex.new

      def initialize(apn_settings)
        @certificate_path = apn_settings.certificate_path
        @environment      = ActiveSupport::StringInquirer.new(apn_settings.environment.to_s)
        @topic            = apn_settings.topic
      end

      def push!(notification)
        # Don't load lowdown earlier as it may load Celluloid (and start it)
        # before daemonizing the workers spun up by a gem (e,g, delayed_job).
        require 'lowdown' unless defined?(Lodwown)

        lowdown_notification = Lowdown::Notification.new(token: notification.device_token)
        lowdown_notification.payload = notification.payload
        lowdown_notification.topic   = @topic

        response = nil
        client.group do |group|
          group.send_notification(lowdown_notification) do |_response|
            response = _response
          end
        end

        raise response.raw_body if !response.success?
        ApnResponse.new(response)
      rescue => cause
        error = Pushing::ApnDeliveryError.new("Error while trying to send push notification: #{cause.message}", ApnResponse.new(response))

        raise error, error.message, cause.backtrace
      end

      private<commit_msg>Do not wrap a respone if it's nil<commit_after># frozen-string-literal: true

require 'json'
require 'active_support/string_inquirer'

module Pushing
  module Adapters
    class LowdownAdapter
      @@clients   = {}
      @@semaphore = Mutex.new

      def initialize(apn_settings)
        @certificate_path = apn_settings.certificate_path
        @environment      = ActiveSupport::StringInquirer.new(apn_settings.environment.to_s)
        @topic            = apn_settings.topic
      end

      def push!(notification)
        # Don't load lowdown earlier as it may load Celluloid (and start it)
        # before daemonizing the workers spun up by a gem (e,g, delayed_job).
        require 'lowdown' unless defined?(Lodwown)

        lowdown_notification = Lowdown::Notification.new(token: notification.device_token)
        lowdown_notification.payload = notification.payload
        lowdown_notification.topic   = @topic

        response = nil
        client.group do |group|
          group.send_notification(lowdown_notification) do |_response|
            response = _response
          end
        end

        raise response.raw_body if !response.success?
        ApnResponse.new(response)
      rescue => cause
        response = response ? ApnResponse.new(response) : nil
        error    = Pushing::ApnDeliveryError.new("Error while trying to send push notification: #{cause.message}", response)

        raise error, error.message, cause.backtrace
      end

      private
{'fraction_non_alphanumeric': 0.07713498622589532, 'fraction_numerical': 0.0, 'mean_word_length': 2.714833759590793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3214914', 'n_tokens_mistral': 806, 'n_tokens_neox': 784, 'n_words': 202}