<commit_before>import requests
import json
from ClassyClientResponse import ClassyClientResponse
from Exceptions import *

class ClassyClient:
	"""Classy Client Library."""

	URL_BASE = "https://api.classy.org/2.0/"

	def __init__(self, client_id, client_secret):
		self.__client_id = client_id
		self.__client_secret = client_secret
		self.__access_token = self.__generate_token()
		self.__session = requests.Session()

	def __generate_token(self):
		"""
		Get a Classy API OAuth token.
		See: https://developers.classy.org/overview/authentication
		"""
		response = requests.post("https://api.classy.org/oauth2/auth", params={
			"grant_type": "client_credentials",
			"client_id": self.__client_id,
			"client_secret": self.__client_secret
		}).json()

		if 'error' in response:
			raise ClassyAuthError("Invalid API key or secret")

		return response['access_token']

	def __call(self, method, endpoint, params={}, data={}, expand=[], page=None, per_page=None):
		"""Make a request."""
		headers = {'Authorization': "Bearer " + self.__access_token}

		endpoint = endpoint.strip("/")

		if expand:
			params.update({"with":",".join(expand)})

		if page:
			params.update({"page": page})

		if per_page:
			params.update({"per_page": per_page})

		r = self.__session.request(method, ClassyClient.URL_BASE + endpoint, params=params, json=data, headers=headers)

		if r.status_code is not requests.codes.ok:
			self.handle_error(r)

		return ClassyClientResponse(r, self.__session)

	def get(self, endpoint, params={}, expand=[], page=None, per_page=None):
		"""Make a GET request."""
		return self.__call("GET", endpoint, params=params, expand=expand, page=page, per_page=per_page)

	def post(self, endpoint, data={}):
		"""Make a POST request."""
		return self.__call("POST", endpoint, data=data)

	def put(self, endpoint, data, params={}):
		"""Make a PUT request."""
		return self.__call("PUT", endpoint, params=params, data=data)

	def delete(self, endpoint):
		"""Make a DELETE request."""
		return self.__call("DELETE", endpoint, params=params, data=data)

	def handle_error(self, response):
		"""Handle Classy errors."""
		error = response.json()['error']
		raise ClassyResponseError(error)<commit_msg>fixed incorrect exception name<commit_after>import requests
import json
from ClassyClientResponse import ClassyClientResponse
from Exceptions import *

class ClassyClient:
	"""Classy Client Library."""

	URL_BASE = "https://api.classy.org/2.0/"

	def __init__(self, client_id, client_secret):
		self.__client_id = client_id
		self.__client_secret = client_secret
		self.__access_token = self.__generate_token()
		self.__session = requests.Session()

	def __generate_token(self):
		"""
		Get a Classy API OAuth token.
		See: https://developers.classy.org/overview/authentication
		"""
		response = requests.post("https://api.classy.org/oauth2/auth", params={
			"grant_type": "client_credentials",
			"client_id": self.__client_id,
			"client_secret": self.__client_secret
		}).json()

		if 'error' in response:
			raise ClassyAuthError("Invalid API key or secret")

		return response['access_token']

	def __call(self, method, endpoint, params={}, data={}, expand=[], page=None, per_page=None):
		"""Make a request."""
		headers = {'Authorization': "Bearer " + self.__access_token}

		endpoint = endpoint.strip("/")

		if expand:
			params.update({"with":",".join(expand)})

		if page:
			params.update({"page": page})

		if per_page:
			params.update({"per_page": per_page})

		r = self.__session.request(method, ClassyClient.URL_BASE + endpoint, params=params, json=data, headers=headers)

		if r.status_code is not requests.codes.ok:
			self.handle_error(r)

		return ClassyClientResponse(r, self.__session)

	def get(self, endpoint, params={}, expand=[], page=None, per_page=None):
		"""Make a GET request."""
		return self.__call("GET", endpoint, params=params, expand=expand, page=page, per_page=per_page)

	def post(self, endpoint, data={}):
		"""Make a POST request."""
		return self.__call("POST", endpoint, data=data)

	def put(self, endpoint, data, params={}):
		"""Make a PUT request."""
		return self.__call("PUT", endpoint, params=params, data=data)

	def delete(self, endpoint):
		"""Make a DELETE request."""
		return self.__call("DELETE", endpoint, params=params, data=data)

	def handle_error(self, response):
		"""Handle Classy errors."""
		error = response.json()['error']
		raise ClassyRequestError(error)
{'fraction_non_alphanumeric': 0.15193868349864742, 'fraction_numerical': 0.001352569882777277, 'mean_word_length': 5.09478021978022, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, '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': '6690975', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1382, 'n_words': 348}