<commit_before>class BitbucketClient
  include HTTParty
  base_uri 'https://api.bitbucket.org/1.0/repositories'

  def initialize(username, password)
    credentials = { username: username, password: password }
    @headers = { basic_auth: credentials }
  end

  def commit_comments(slug, sha)
    response = self.class.get("/#{slug}/changesets/#{sha}/comments", @headers)
    openstruct(response.parsed_response)
  end

  def create_commit_comment(slug, sha, body, path, position)
    post("/#{slug}/changesets/#{sha}/comments", body, path, position)
  end

  def pull_comments(slug, pr_id)
    url = "/#{slug}/pullrequests/#{pr_id}/comments"
    response = self.class.get(url, @headers)
    openstruct(response.parsed_response)
  end

  def pull_requests(slug)
    base = 'https://api.bitbucket.org/2.0/repositories'
    url = "#{base}/#{slug}/pullrequests?state=OPEN"
    response = self.class.get(url, @headers)
    openstruct(response.parsed_response['values'])
  end

  def create_pull_comment(slug, pull_id, body, path, position)
    post("/#{slug}/pullrequests/#{pull_id}/comments", body, path, position)
  end

  private

  def openstruct(response)
    response.map { |r| OpenStruct.new(r) }
  end

  def post(url, body, path, position)
    options = {
      body: {
        content: body,
        line_to: position,
        filename: path
      }
    }
    options.merge!(@headers)
    self.class.post(url, options)
  end
end<commit_msg>BitbucketClient: use class.basic_auth instead of setting headers<commit_after>class BitbucketClient
  include HTTParty
  base_uri 'https://api.bitbucket.org/1.0/repositories'

  def initialize(username, password)
    self.class.basic_auth(username, password)
  end

  def commit_comments(slug, sha)
    response = get("/#{slug}/changesets/#{sha}/comments")
    openstruct(response)
  end

  def create_commit_comment(slug, sha, body, path, position)
    post("/#{slug}/changesets/#{sha}/comments", body, path, position)
  end

  def pull_comments(slug, pull_id)
    response = get("/#{slug}/pullrequests/#{pull_id}/comments")
    openstruct(response)
  end

  def pull_requests(slug)
    base = 'https://api.bitbucket.org/2.0/repositories'
    response = get("#{base}/#{slug}/pullrequests?state=OPEN")
    openstruct(response['values'])
  end

  def create_pull_comment(slug, pull_id, body, path, position)
    post("/#{slug}/pullrequests/#{pull_id}/comments", body, path, position)
  end

  private

  def openstruct(response)
    response.map { |r| OpenStruct.new(r) }
  end

  def post(url, body, path, position)
    options = {
      body: {
        content: body,
        line_to: position,
        filename: path
      }
    }
    self.class.post(url, options)
  end

  def get(url)
    self.class.get(url).parsed_response
  end
end
{'fraction_non_alphanumeric': 0.13680430879712746, 'fraction_numerical': 0.002872531418312388, 'mean_word_length': 3.6125827814569536, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2256934', 'n_tokens_mistral': 913, 'n_tokens_neox': 924, 'n_words': 183}