<commit_before>class InjectionResponseService
  def initialize(json)
    @response = json.stringify_keys
    raise ParseError, 'Invalid JSON string' unless @response.keys.eql?(%w[errors uuid messages])
  end

  def run!
    claim = Claim::BaseClaim.find_by(uuid: @response['uuid'])
    if claim.nil?
      failure_message = "Failed to inject '#{@response['uuid']}' because no claim found"
      LogStuff.send(:info, 'InjectionResponseService::NonExistentClaim',
                    action: 'run!',
                    uuid: @response['uuid']) { failure_message }
      update_slack(failure_message)
      return false
    end
    ia = InjectionAttempt.create(claim: claim, succeeded: ccr_injected?, error_message: error_message)
    update_slack(generate_message(ccr_injected?, claim))
    ia.save
  end

  private

  def generate_message(success, claim)
    if success
      "Claim #{claim.case_number} successfully injected"
    else
      "Claim #{claim.case_number} could not be injected because #{error_message}"
    end
  end

  def update_slack(message)
    payload = {
      channel: Settings.slack.channel,
      username: Settings.slack.bot_name,
      text: message,
      icon_emoji: Settings.slack.icon
    }.to_json
    RestClient.post(Settings.slack.bot_url, payload, content_type: :json)
  end

  def ccr_injected?
    @response['errors'].empty?
  end

  def error_message
    @response['errors'].join(' ')
  end
end<commit_msg>add uuid to slack message output<commit_after>class InjectionResponseService
  def initialize(json)
    @response = json.stringify_keys
    raise ParseError, 'Invalid JSON string' unless @response.keys.eql?(%w[errors uuid messages])
  end

  def run!
    claim = Claim::BaseClaim.find_by(uuid: @response['uuid'])
    if claim.nil?
      failure_message = 'Failed to inject because no claim found'
      LogStuff.send(:info, 'InjectionResponseService::NonExistentClaim',
                    action: 'run!',
                    uuid: @response['uuid']) { failure_message }
      update_slack(failure_message)
      return false
    end
    ia = InjectionAttempt.create(claim: claim, succeeded: ccr_injected?, error_message: error_message)
    update_slack(generate_message(ccr_injected?, claim))
    ia.save
  end

  private

  def generate_message(success, claim)
    if success
      "Claim #{claim.case_number} successfully injected"
    else
      "Claim #{claim.case_number} could not be injected because #{error_message}"
    end
  end

  def update_slack(message)
    payload = {
      channel: Settings.slack.channel,
      username: Settings.slack.bot_name,
      text: "#{message} {#{@response['uuid']}}",
      icon_emoji: Settings.slack.icon
    }.to_json
    RestClient.post(Settings.slack.bot_url, payload, content_type: :json)
  end

  def ccr_injected?
    @response['errors'].empty?
  end

  def error_message
    @response['errors'].join(' ')
  end
end
{'fraction_non_alphanumeric': 0.10748626373626374, 'fraction_numerical': 0.0, 'mean_word_length': 3.4136363636363636, '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': '1548964', 'n_tokens_mistral': 894, 'n_tokens_neox': 869, 'n_words': 206}