<commit_before># frozen_string_literal: true

require 'excon/hypermedia/ext/response'

module Excon
  module HyperMedia
    # Response
    #
    # This HyperMedia::Response object helps determine valid subsequent
    # requests and attribute values.
    #
    class Response
      attr_reader :response

      def initialize(response)
        @response = response
      end

      # handle
      #
      # Correctly handle the hypermedia request.
      #
      def handle(method_name, *params)
        return false if disabled?

        case resource.type?(method_name)
        when :link      then return handle_link(method_name, params)
        when :attribute then return handle_attribute(method_name)
        end

        respond_to?(method_name) ? send(method_name) : false
      end

      def links
        resource.links
      end

      def attributes
        resource.attributes
      end

      def resource
        @resource ||= Resource.new(response.body)
      end

      def enabled?
        response.data[:hypermedia] == true
      end

      def disabled?
        !enabled?
      end

      private

      def handle_link(name, params)
        Excon.new(resource.link(name).uri, params.first.to_h.merge(hypermedia: true))
      end

      def handle_attribute(name)
        attributes[name.to_s]
      end
    end
  end
end
<commit_msg>pass url as string to Excon.new<commit_after># frozen_string_literal: true

require 'excon/hypermedia/ext/response'

module Excon
  module HyperMedia
    # Response
    #
    # This HyperMedia::Response object helps determine valid subsequent
    # requests and attribute values.
    #
    class Response
      attr_reader :response

      def initialize(response)
        @response = response
      end

      # handle
      #
      # Correctly handle the hypermedia request.
      #
      def handle(method_name, *params)
        return false if disabled?

        case resource.type?(method_name)
        when :link      then return handle_link(method_name, params)
        when :attribute then return handle_attribute(method_name)
        end

        respond_to?(method_name) ? send(method_name) : false
      end

      def links
        resource.links
      end

      def attributes
        resource.attributes
      end

      def resource
        @resource ||= Resource.new(response.body)
      end

      def enabled?
        response.data[:hypermedia] == true
      end

      def disabled?
        !enabled?
      end

      private

      def handle_link(name, params)
        Excon.new(resource.link(name).href, params.first.to_h.merge(hypermedia: true))
      end

      def handle_attribute(name)
        attributes[name.to_s]
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06862385321100918, 'fraction_numerical': 0.0, 'mean_word_length': 2.094211123723042, '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': '7127831', 'n_tokens_mistral': 763, 'n_tokens_neox': 736, 'n_words': 201}