<commit_before>class EmailAlertsUnsubscriber
  def self.call(...)
    new(...).unsubscribe
  end

  attr_reader :item, :body, :govuk_request_id

  def initialize(item:, body: nil, govuk_request_id: nil)
    @item = item
    @body = body
    @govuk_request_id = govuk_request_id
  end

  def unsubscribe
    args = { slug: subscriber_list_slug }

    if body
      args.merge!({
        body:,
        sender_message_id: SecureRandom.uuid,
      })

      # GOVUK-Request-Id HTTP header is set by Nginx and handled by gds-api-adapters.
      # For out-of-band processes (asynchronous workers)
      # it needs to be set explicitly to send emails.
      args.merge!({ govuk_request_id: }) if govuk_request_id
    end

    Services.email_alert_api.bulk_unsubscribe(args)
  end

private

  def subscriber_list_slug
    subscriber_list = Services.email_alert_api.find_subscriber_list(
      item.subscriber_list_search_attributes,
    )
    subscriber_list.dig("subscriber_list", "slug")
  end
end<commit_msg>Fix converting hash to keyword arguments<commit_after>class EmailAlertsUnsubscriber
  def self.call(...)
    new(...).unsubscribe
  end

  attr_reader :item, :body, :govuk_request_id

  def initialize(item:, body: nil, govuk_request_id: nil)
    @item = item
    @body = body
    @govuk_request_id = govuk_request_id
  end

  def unsubscribe
    args = { slug: subscriber_list_slug }

    if body
      args.merge!({
        body:,
        sender_message_id: SecureRandom.uuid,
      })

      # GOVUK-Request-Id HTTP header is set by Nginx and handled by gds-api-adapters.
      # For out-of-band processes (asynchronous workers)
      # it needs to be set explicitly to send emails.
      args.merge!({ govuk_request_id: }) if govuk_request_id
    end

    Services.email_alert_api.bulk_unsubscribe(**args)
  end

private

  def subscriber_list_slug
    subscriber_list = Services.email_alert_api.find_subscriber_list(
      item.subscriber_list_search_attributes,
    )
    subscriber_list.dig("subscriber_list", "slug")
  end
end
{'fraction_non_alphanumeric': 0.08640157093765341, 'fraction_numerical': 0.0, 'mean_word_length': 3.1762295081967213, 'pattern_counts': {'":': 0, '<': 3, '<?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': '356353', 'n_tokens_mistral': 698, 'n_tokens_neox': 675, 'n_words': 156}