<commit_before>module Bibliovore
  class Client
    @@base = 'https://api.bibliocommons.com'
    @@version = 'v1'

    # Create a Bibliovore client
    #
    # @param [String] api_key Your API key. The shirt and shoes of API service
    # @return Client A new instance of Client
    def initialize(api_key)
      @api_key = api_key
      @conn = Faraday.new
    end

    def conn
      @conn
    end

    # Get a library by id
    #
    # @param [String] id The library id
    # @return Library A new Library instance
    def library(id)
      Bibliovore::Library.new(
        get_endpoint("libraries/#{id}"), self
      )
    end

    # Retrieve users by name search.
    #
    # @param [String] query The string to search for
    # @return Array An array of User objects matching the query string
    #
    # This will return an empty array if there is no match, or at most one 
    # exact match. The format of the users endpoint implies that it might 
    # someday allow for multiple results.
    def users(query)
      get_endpoint('users', {'q' => query})["users"].map{|u| 
        Bibliovore::User.new(u, self)
      }
    end

    # Retrieve a user by id
    #
    # @param [Fixnum] id The id of the user to retrieve
    # @returns User A new User instance
    def user(id)
      Bibliovore::User.new(
        get_endpoint("users/#{id}")['user'], self
      )
    end

    # Retrieve an endpoint
    #
    # @param [String] path The endpoint path
    # @return [Hash] a parsed JSON object
    def get_endpoint(path, params = {})
      fullpath = "#{@@base}/#{@@version}/#{path}"
      response = @conn.get fullpath, params.merge({"api_key" => @api_key})
      data = JSON.parse(response.body)
      if data.keys.include?('error')
        raise Bibliovore::ApiError, data['error']['message']
      end
      return data
    end
  end
end<commit_msg>Declare attribute accessor for @conn<commit_after>module Bibliovore
  class Client
    @@base = 'https://api.bibliocommons.com'
    @@version = 'v1'

    attr_reader :conn

    # Create a Bibliovore client
    #
    # @param [String] api_key Your API key. The shirt and shoes of API service
    # @return Client A new instance of Client
    def initialize(api_key)
      @api_key = api_key
      @conn = Faraday.new
    end

    # def conn
    #   @conn
    # end

    # Get a library by id
    #
    # @param [String] id The library id
    # @return Library A new Library instance
    def library(id)
      Bibliovore::Library.new(
        get_endpoint("libraries/#{id}"), self
      )
    end

    # Retrieve users by name search.
    #
    # @param [String] query The string to search for
    # @return Array An array of User objects matching the query string
    #
    # This will return an empty array if there is no match, or at most one 
    # exact match. The format of the users endpoint implies that it might 
    # someday allow for multiple results.
    def users(query)
      get_endpoint('users', {'q' => query})["users"].map{|u| 
        Bibliovore::User.new(u, self)
      }
    end

    # Retrieve a user by id
    #
    # @param [Fixnum] id The id of the user to retrieve
    # @returns User A new User instance
    def user(id)
      Bibliovore::User.new(
        get_endpoint("users/#{id}")['user'], self
      )
    end

    # Retrieve an endpoint
    #
    # @param [String] path The endpoint path
    # @raise [Bibliovore::ApiError] if asd dsa dsad
    # @return [Hash] a parsed JSON object
    def get_endpoint(path, params = {})
      fullpath = "#{@@base}/#{@@version}/#{path}"
      response = @conn.get fullpath, params.merge({"api_key" => @api_key})
      data = JSON.parse(response.body)
      if data.keys.include?('error')
        raise Bibliovore::ApiError, data['error']['message']
      end
      return data
    end
  end
end
{'fraction_non_alphanumeric': 0.10869565217391304, 'fraction_numerical': 0.0005238344683080147, 'mean_word_length': 2.4405405405405407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '1517737', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1173, 'n_words': 401}