Skip to content

Commit

Permalink
v1.1.1 - Added LimitExceeded error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince2347X authored May 7, 2021
2 parents 8b35bcf + 6aa97aa commit 924c4f0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
8 changes: 3 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
#
import os
import sys
import re
import sphinx_rtd_theme
import sphinx_rtd_dark_mode

sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0,os.path.abspath('.'))

version = "v1.1.0"

version = "v1.1.1"


# -- Project information -----------------------------------------------------
Expand All @@ -30,7 +31,6 @@
# The full version, including alpha/beta/rc tags
release = version


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
Expand All @@ -50,7 +50,6 @@
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
Expand All @@ -65,4 +64,3 @@

pygments_style = 'friendly'
default_dark_mode = True

3 changes: 3 additions & 0 deletions docs/source/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Errors

.. autoclass:: pydoodle.errors.LanguageNotSupported
:members:

.. autoclass:: pydoodle.errors.LimitExceeded
:members:

.. autoclass:: pydoodle.errors.UnauthorizedRequest
:members:
Expand Down
2 changes: 1 addition & 1 deletion pydoodle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# METADATA #
############

__version__ = "v1.1.0"
__version__ = "v1.1.1"
__title__ = "pydoodle"
__license__ = "MIT"
__author__ = "Prince2347X"
Expand Down
6 changes: 6 additions & 0 deletions pydoodle/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ class LanguageNotSupported(Exception):
pass


class LimitExceeded(Exception):
"""Raised when the daily limit has exceeded. Learn more: https://jdoodle.com/compiler-api"""
pass


class UnauthorizedRequest(Exception):
"""Raised if either your clientID or clientSecret is invalid."""
pass
Expand All @@ -12,6 +17,7 @@ class BadRequest(Exception):
"""Raised when invalid language or versionIndex is provided. """
pass


class LinkNotSupported(Exception):
"""Raised if the provided link isn't supported yet by pydoodle."""
pass
7 changes: 5 additions & 2 deletions pydoodle/jdoodle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import requests
from .errors import UnauthorizedRequest, BadRequest, LanguageNotSupported, LinkNotSupported
from .errors import UnauthorizedRequest, BadRequest, LanguageNotSupported, LinkNotSupported, LimitExceeded


class Output:
Expand Down Expand Up @@ -59,7 +59,8 @@ def _read_link(self, link: str) -> str:
r = requests.get(raw_link)
return r.text

def execute(self, script: str, language: str, link: bool = False, stdIn: str = None, versionIndex: int = None) -> Output:
def execute(self, script: str, language: str, link: bool = False, stdIn: str = None,
versionIndex: int = None) -> Output:

"""
Executes the provided script.
Expand Down Expand Up @@ -125,6 +126,8 @@ def execute(self, script: str, language: str, link: bool = False, stdIn: str = N
elif response.status_code == 400:
raise BadRequest(f"statusCode: {error['statusCode']}, error: {error['error']}\n"
f"Invalid versionIndex or language provided.")
elif response.status_code == 429:
raise LimitExceeded("Daily limit exceeded. No more API calls for today.")

def usage(self) -> int:
"""
Expand Down

0 comments on commit 924c4f0

Please sign in to comment.