<commit_before># -*- coding: utf-8 -*-

import requests
import json
from .exceptions import GistException

class Gist:
  BASE_URL = 'https://api.github.com'

  def __init__(self, token):
    response = requests.get(self.BASE_URL + '/user?access_token=' + token)
    if response.status_code != 200:
      raise GistException(Gist.__get_response_error('The entered token is invalid', response))
    else:
      self.__user_data = response.json()
      self.__headers = {
        'X-Github-Username': self.__user_data.get('login'),
        'Content-Type': 'application/json',
        'Authorization': 'token %s' %token
      }
      self.__defaults = {
        'public': False,
        'files': {}
      }

  def create(self, gist_data):
    _data = json.dumps(dict(self.__defaults, **gist_data))

    response = requests.post(
      self.BASE_URL + '/gists',
      data = _data,
      headers = self.__headers
    )

    if response.status_code == 201:
      return response.json()

    raise GistException(Gist.__get_response_error('Gist can\'t created', response))

  def edit(self, gist_id, gist_data):
    self.__defaults.pop('description', None)
    gist_data = json.dumps(dict(self.__defaults, **gist_data))
    response = requests.patch(
      self.BASE_URL + '/gists/%s' %gist_id,
      data=gist_data,
      headers=self.__headers
    )

    if response.status_code == 200:
      return response.json()

    raise GistException(Gist.__get_response_error('Can\'t edit the gist', response))

  def list(self, include_secret = False):
    headers = {} if not include_secret else self.__headers
    response = requests.get(''.join((
      self.BASE_URL + '/users/',
      self.__user_data.get('login') + '/gists',
    )), headers=headers)

    if response.status_code == 200:
      return response.json()

    raise GistException(Gist.__get_response_error('It is not possible to list files', response))

  def delete(self, gist_id):
    response = requests.delete(
      self.BASE_URL + '/gists/' + gist_id,
      headers=self.__headers
    )

    if response.status_code == 204:
      return True

    raise GistException(Gist.__get_response_error('The Gist can be deleted', response))

  def get(self, gist_id):
    response = requests.get(self.BASE_URL + '/gists/' + gist_id)
    if response.status_code == 200:
      return response.json()

    raise GistException(Gist.__get_response_error('The gist not exist', response))

  @staticmethod<commit_msg>not include headers parameter when authentication is not required<commit_after># -*- coding: utf-8 -*-

import requests
import json
from .exceptions import GistException

class Gist:
  BASE_URL = 'https://api.github.com'

  def __init__(self, token):
    response = requests.get(self.BASE_URL + '/user?access_token=' + token)
    if response.status_code != 200:
      raise GistException(Gist.__get_response_error('The entered token is invalid', response))
    else:
      self.__user_data = response.json()
      self.__headers = {
        'X-Github-Username': self.__user_data.get('login'),
        'Content-Type': 'application/json',
        'Authorization': 'token %s' %token
      }
      self.__defaults = {
        'public': False,
        'files': {}
      }

  def create(self, gist_data):
    _data = json.dumps(dict(self.__defaults, **gist_data))

    response = requests.post(
      self.BASE_URL + '/gists',
      data = _data,
      headers = self.__headers
    )

    if response.status_code == 201:
      return response.json()

    raise GistException(Gist.__get_response_error('Gist can\'t created', response))

  def edit(self, gist_id, gist_data):
    self.__defaults.pop('description', None)
    gist_data = json.dumps(dict(self.__defaults, **gist_data))
    response = requests.patch(
      self.BASE_URL + '/gists/%s' %gist_id,
      data=gist_data,
      headers=self.__headers
    )

    if response.status_code == 200:
      return response.json()

    raise GistException(Gist.__get_response_error('Can\'t edit the gist', response))

  def list(self, include_secret = False):
    base_url = ''.join((
      self.BASE_URL + '/users/',
      self.__user_data.get('login') + '/gists',
    ))
    response = None

    if include_secret:
      response = requests.get(base_url, headers=self.__headers)
    else:
      response = requests.get(base_url)

    if response.status_code == 200:
      return response.json()

    raise GistException(Gist.__get_response_error('It is not possible to list files', response))

  def delete(self, gist_id):
    response = requests.delete(
      self.BASE_URL + '/gists/' + gist_id,
      headers=self.__headers
    )

    if response.status_code == 204:
      return True

    raise GistException(Gist.__get_response_error('The Gist can be deleted', response))

  def get(self, gist_id):
    response = requests.get(self.BASE_URL + '/gists/' + gist_id)
    if response.status_code == 200:
      return response.json()

    raise GistException(Gist.__get_response_error('The gist not exist', response))

  @staticmethod
{'fraction_non_alphanumeric': 0.12683604605001986, 'fraction_numerical': 0.007542675664946407, 'mean_word_length': 3.1337161607875306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4202305', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1561, 'n_words': 350}