<commit_before>require "httparty"

class Base
  include HTTParty

  BASE_URL      = "http://api.eventfinda.co.nz/v2/".freeze
  RESOURCE_SLUG = "base"

  attr_reader :api_extension
  attr_reader :filters

  def initialize
    @api_extension = "json"
    @filters       = { "rows" => "20" }
  end

  def by_keywords_and(keywords)
    apply_filter "q", set_keywords_and(keywords)

    self
  end

  def by_keywords_or(keywords)
    apply_filter "q", set_keywords_or(keywords)

    self
  end

  def by_query(query)
    apply_filter "q", query

    self
  end

  def by_rows(rows)
    apply_filter "rows", rows

    self
  end

  def results
    @results = response["#{self.class::RESOURCE_SLUG}"]
  end

  def url
    "#{BASE_URL}#{self.class::RESOURCE_SLUG}.#{api_extension}?#{get_filters}"
  end

  def with_extension(extension)
    if ["json", "xml"].include? extension
      @api_extension = extension
    end

    self
  end

  private

  def apply_filter(filter_name, value)
    filters[filter_name] = value
  end

  def auth
    {
      username: EventFindaRuby.configuration.username,
      password: <PASSWORD>.configuration.password
    }
  end

  def get_filters
    filters.map { |k,v| "#{k}=#{v}" }.join("&")
  end

  def response
    HTTParty.get("#{url}", basic_auth: auth)<commit_msg>Base module - 'resource_slug' method implemented<commit_after>require "httparty"

class Base
  include HTTParty

  BASE_URL      = "http://api.eventfinda.co.nz/v2/".freeze
  RESOURCE_SLUG = "base"

  attr_reader :api_extension
  attr_reader :filters

  def initialize
    @api_extension = "json"
    @filters       = { "rows" => "20" }
  end

  def by_keywords_and(keywords)
    apply_filter "q", set_keywords_and(keywords)

    self
  end

  def by_keywords_or(keywords)
    apply_filter "q", set_keywords_or(keywords)

    self
  end

  def by_query(query)
    apply_filter "q", query

    self
  end

  def by_rows(rows)
    apply_filter "rows", rows

    self
  end

  def results
    @results = response[resource_slug]
  end

  def url
    "#{BASE_URL}#{resource_slug}.#{api_extension}?#{get_filters}"
  end

  def with_extension(extension)
    if ["json", "xml"].include? extension
      @api_extension = extension
    end

    self
  end

  private

  def apply_filter(filter_name, value)
    filters[filter_name] = value
  end

  def auth
    {
      username: EventFindaRuby.configuration.username,
      password: <PASSWORD>
    }
  end

  def get_filters
    filters.map { |k,v| "#{k}=#{v}" }.join("&")
  end

  def resource_slug
    self.class::RESOURCE_SLUG
  end

  def response
    HTTParty.get("#{url}", basic_auth: auth)
{'fraction_non_alphanumeric': 0.11275626423690205, 'fraction_numerical': 0.002277904328018223, 'mean_word_length': 3.072642967542504, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4795688', 'n_tokens_mistral': 968, 'n_tokens_neox': 910, 'n_words': 199}