<commit_before>module Chargify2
  # Resource orchestrates the connection from the Client to the Chargify API Resources, available
  # at the Resource URIs.
  #
  # Resource implements CRUD operations on the Chargify API Resources: {Resource.create}, {Resource.read},
  # {Resource.update}, {Resource.delete}, and {Resource.list}.
  class Resource
    include HTTParty

    base_uri Chargify2::Client::BASE_URI
    headers 'Content-Type' => 'application/json', 'Accept' => 'application/json'
    format :json
    
    def self.path(resource_path)
      @path = resource_path
    end

    def self.uri
      if @path.nil? || @path.to_s.size == 0
        raise ResourceError, "No path configured.  Please use a defined Resource."
      end
      "#{base_uri}/#{@path}"
    end
    
    def uri
      self.class.uri
    end
    
    # Define the representation class for this resource
    def self.representation(klass = nil)
      unless klass.nil?
        @@representation = klass
      end
      @@representation ||= nil
    end
    
    def initialize(client)
      @client = client
      @username = client.api_id
      @password = <PASSWORD>
      
      self.class.base_uri(client.base_uri)
      self.class.basic_auth(@username, @password)
    end
    
    def self.read(id, query = {})
      response = get("#{uri}/#{id}", :query => query.empty? ? nil : query)
      response_hash = response.parsed_response[representation.to_s.downcase.split('::').last] || {}
      representation.new(response_hash.symbolize_keys)
    end
    
    def read(id, query = {})
      self.class.read(id, query)
    end
  end
  
  class ResourceError < StandardError; end
end<commit_msg>Access the httparty response directly as a hash<commit_after>module Chargify2
  # Resource orchestrates the connection from the Client to the Chargify API Resources, available
  # at the Resource URIs.
  #
  # Resource implements CRUD operations on the Chargify API Resources: {Resource.create}, {Resource.read},
  # {Resource.update}, {Resource.delete}, and {Resource.list}.
  class Resource
    include HTTParty

    base_uri Chargify2::Client::BASE_URI
    headers 'Content-Type' => 'application/json', 'Accept' => 'application/json'
    format :json
    
    def self.path(resource_path)
      @path = resource_path
    end

    def self.uri
      if @path.nil? || @path.to_s.size == 0
        raise ResourceError, "No path configured.  Please use a defined Resource."
      end
      "#{base_uri}/#{@path}"
    end
    
    def uri
      self.class.uri
    end
    
    # Define the representation class for this resource
    def self.representation(klass = nil)
      unless klass.nil?
        @@representation = klass
      end
      @@representation ||= nil
    end
    
    def initialize(client)
      @client = client
      @username = client.api_id
      @password = <PASSWORD>
      
      self.class.base_uri(client.base_uri)
      self.class.basic_auth(@username, @password)
    end
    
    def self.read(id, query = {})
      response = get("#{uri}/#{id}", :query => query.empty? ? nil : query)
      response_hash = response[representation.to_s.downcase.split('::').last] || {}
      representation.new(response_hash.symbolize_keys)
    end
    
    def read(id, query = {})
      self.class.read(id, query)
    end
  end
  
  class ResourceError < StandardError; end
end
{'fraction_non_alphanumeric': 0.10982142857142857, 'fraction_numerical': 0.0017857142857142857, 'mean_word_length': 2.6974697469746975, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2818443', 'n_tokens_mistral': 1011, 'n_tokens_neox': 997, 'n_words': 266}