<commit_before>class HipchatMessage
  attr_accessor :type
  attr_accessor :uri
  attr_accessor :amount

  def initialize attributes={}
    self.type = attributes[:type]
    self.uri = attributes[:uri]
    self.amount = attributes[:amount]
  end

  def self.new_from_request(request_body)
    request = JSON.parse request_body
    resource = request["data"]["object"]
    attributes = {
      type: request["type"],
      id: resource['id'],
      amount: resource['amount']
    }

    self.new attributes
  end

  def to_h
    {text:"#{type} - #{amount} - #{uri}", notify:should_notify?, color:set_color}
  end

  def valid?
    type !=nil && uri != nil
  end

  def should_notify?
    case type
    when 'charge.succeeded'
      true
    when 'charge.failed'
      true
    when 'charge.dispute.create'
      true
    when 'transfer.paid'
      true
    when 'transfer.failed'
      true
    else
      false
    end
  end

  def set_color
    case type
    when 'charge.failed'
      'red'
    when 'charge.failed'
      'red'
    when 'charge.refunded'
      'green'
    when 'charge.succeeded'
      'green'
    when 'charge.succeeded'
      'green'
    when /hold/
      'yellow'
    when /refund/
      'yellow'
    else
      'gray'
    end
  end

private

  def build_from_request(request_body)
  end

end<commit_msg>Update message format<commit_after>class HipchatMessage
  attr_accessor :type
  attr_accessor :id
  attr_accessor :amount
  attr_accessor :resource

  def initialize attributes={}
    @type = attributes[:type]
    @id = attributes[:id]
    @amount = attributes[:amount]
    @resource = attributes[:resource]
  end

  def self.new_from_request(request_body)
    request = JSON.parse request_body
    resource = request["data"]["object"]
    attributes = {
      type: request["type"],
      id: resource['id'],
      amount: resource['amount'],
      resource: resource
    }

    self.new attributes
  end

  def to_h
    {text:"#{type} - #{amount} - #{id} : #{resource.reject {|k,v| !v.is_a?(String) || k == 'object' || k == 'id'}}", notify:should_notify?, color:set_color}
  end

  def valid?
    type !=nil && id != nil
  end

  def should_notify?
    case type
    when 'charge.succeeded'
      true
    when 'charge.failed'
      true
    when 'charge.dispute.create'
      true
    when 'transfer.paid'
      true
    when 'transfer.failed'
      true
    else
      false
    end
  end

  def set_color
    case type
    when 'charge.failed'
      'red'
    when 'charge.failed'
      'red'
    when 'charge.refunded'
      'green'
    when 'charge.succeeded'
      'green'
    when 'charge.succeeded'
      'green'
    when /hold/
      'yellow'
    when /refund/
      'yellow'
    else
      'gray'
    end
  end
end
{'fraction_non_alphanumeric': 0.11450381679389313, 'fraction_numerical': 0.0, 'mean_word_length': 2.3560975609756096, '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': '3705387', 'n_tokens_mistral': 921, 'n_tokens_neox': 894, 'n_words': 224}