<commit_before>require 'poms/api/drivers/net_http'
require 'poms/api/request'
require 'poms/api/auth'
require 'poms/errors'

module Poms
  module Api
    # The Client module isolates all HTTP interactions, regardless of the driver
    # module to implement the actual operations. Use the Client module to build
    # signed requests and execute them.
    #
    # @see Poms::Api::Drivers::NetHttp
    module Client
      extend Drivers::NetHttp

      module_function

      def get(uri, credentials, headers = {})
        handle_response(
          execute(
            sign(
              prepare_get(uri, headers),
              credentials
            )
          )
        )
      end

      def post(uri, body, credentials, headers = {})
        handle_response(
          execute(
            sign(
              prepare_post(uri, body, headers),
              credentials
            )
          )
        )
      end

      def handle_response(response)
        case response.code
        when 400..499 then raise Errors::HttpMissingError
        when 500..599 then raise Errors::HttpServerError
        else
          response
        end
      end

      def prepare_get(uri, headers = {})
        Request.get(uri, nil, headers)
      end

      def prepare_post(uri, body, headers = {})
        Request.post(uri, body, headers)
      end<commit_msg>Provide response code when raising http error<commit_after>require 'poms/api/drivers/net_http'
require 'poms/api/request'
require 'poms/api/auth'
require 'poms/errors'

module Poms
  module Api
    # The Client module isolates all HTTP interactions, regardless of the driver
    # module to implement the actual operations. Use the Client module to build
    # signed requests and execute them.
    #
    # @see Poms::Api::Drivers::NetHttp
    module Client
      extend Drivers::NetHttp

      module_function

      def get(uri, credentials, headers = {})
        handle_response(
          execute(
            sign(
              prepare_get(uri, headers),
              credentials
            )
          )
        )
      end

      def post(uri, body, credentials, headers = {})
        handle_response(
          execute(
            sign(
              prepare_post(uri, body, headers),
              credentials
            )
          )
        )
      end

      def handle_response(response)
        case response.code
        when 400..499 then raise Errors::HttpMissingError, response.code
        when 500..599 then raise Errors::HttpServerError, response.code
        else
          response
        end
      end

      def prepare_get(uri, headers = {})
        Request.get(uri, nil, headers)
      end

      def prepare_post(uri, body, headers = {})
        Request.post(uri, body, headers)
      end
{'fraction_non_alphanumeric': 0.07764198418404025, 'fraction_numerical': 0.008626887131560028, 'mean_word_length': 1.8311291963377416, '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': '6163515', 'n_tokens_mistral': 758, 'n_tokens_neox': 731, 'n_words': 215}