<commit_before>require 'pact_broker/json'
require 'pact_broker/constants'
require 'ostruct'

module PactBroker
  module Pacts
    class PactParams < Hash

      def initialize attributes
        merge!(attributes)
      end

      def self.from_post_request request
        json_content = request.body.to_s
        pact_hash = JSON.parse(json_content, PACT_PARSING_OPTIONS)

        new(
          consumer_name: pact_hash.fetch('consumer',{})['name'],
          provider_name: pact_hash.fetch('provider',{})['name'],
          consumer_version_number: request.headers[CONSUMER_VERSION_HEADER],
          consumer_name_in_pact: pact_hash.fetch('consumer',{})['name'],
          provider_name_in_pact: pact_hash.fetch('provider',{})['name'],
          json_content: json_content
        )
      end

      def self.from_request request, path_info
        json_content = request.body.to_s
        pact_hash = begin
          JSON.parse(json_content, PACT_PARSING_OPTIONS)
        rescue
          {}
        end

        new(
          consumer_name: path_info.fetch(:consumer_name),
          provider_name: path_info.fetch(:provider_name),<commit_msg>Rescue JSON parse when body empty<commit_after>require 'pact_broker/json'
require 'pact_broker/constants'
require 'ostruct'

module PactBroker
  module Pacts
    class PactParams < Hash

      def initialize attributes
        merge!(attributes)
      end

      def self.from_post_request request
        json_content = request.body.to_s
        pact_hash = begin
          JSON.parse(json_content, PACT_PARSING_OPTIONS)
        rescue
          {}
        end

        new(
          consumer_name: pact_hash.fetch('consumer',{})['name'],
          provider_name: pact_hash.fetch('provider',{})['name'],
          consumer_version_number: request.headers[CONSUMER_VERSION_HEADER],
          consumer_name_in_pact: pact_hash.fetch('consumer',{})['name'],
          provider_name_in_pact: pact_hash.fetch('provider',{})['name'],
          json_content: json_content
        )
      end

      def self.from_request request, path_info
        json_content = request.body.to_s
        pact_hash = begin
          JSON.parse(json_content, PACT_PARSING_OPTIONS)
        rescue
          {}
        end

        new(
          consumer_name: path_info.fetch(:consumer_name),
          provider_name: path_info.fetch(:provider_name),
{'fraction_non_alphanumeric': 0.095878889823381, 'fraction_numerical': 0.0, 'mean_word_length': 2.66, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4106723', 'n_tokens_mistral': 718, 'n_tokens_neox': 695, 'n_words': 121}