Skip to content

Commit

Permalink
Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince2347X committed Jun 24, 2021
1 parent 5eb36a2 commit 180a94a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
5 changes: 3 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import os
import sys
import re
import pydoodle
import sphinx_rtd_theme
import sphinx_rtd_dark_mode

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


version = "v1.2.0"
version = "v1.1.2"


# -- Project information -----------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion pydoodle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from .jdoodle import Compiler
from .jdoodle import Output
from .errors import LimitExceeded, LinkNotSupported, LanguageNotSupported, UnauthorizedRequest, BadRequest

############
# METADATA #
############

__version__ = "v1.2.0"
__version__ = "v1.1.2"
__title__ = "pydoodle"
__license__ = "MIT"
__author__ = "Prince2347X"
Expand Down
73 changes: 53 additions & 20 deletions pydoodle/jdoodle.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,66 @@
from typing import Any, Tuple

import requests
from .errors import UnauthorizedRequest, BadRequest, LanguageNotSupported, LinkNotSupported, LimitExceeded


class Output:
"""
The output of the executed script.
"""

def __init__(self, output, statusCode, memory, cpuTime):
self.output = output
self.statusCode = statusCode
self.memory = memory
self.cpuTime = cpuTime
def __init__(self, response_json: dict):
"""
The output of the executed script.
:param response_json: The response from the API
:type respose_json: dict
"""
self._output = response_json['output'],
self._statusCode = response_json['statusCode'],
self._memory = response_json['memory'],
self._cpuTime = response_json['cpuTime']

@property
def output(self) -> str:
"""
:returns: The output of the executed script.
:rtype: str
"""
return self.output

@property
def statusCode(self):
"""
:return: The status code of the API request.
:rtype: int
"""
return self._statusCode

class Compiler:
"""
Initialize the compiler which let you access the Jdoodle API.
@property
def memory(self) -> str:
"""
:return: Memory used to execute the script (in kilobytes).
:rtype: str
"""
return str(self._memory)

@property
def cpuTime(self) -> str:
"""
:return: The time taken in the execution of the script (in seconds).
:rtype: str
"""
return self._cpuTime

:param clientId: The clientId which you can get from https://jdoodle.com/compiler-api/
:type clientId: str
:param clientSecret: The clientSecret which you can get from https://jdoodle.com/compiler-api/
:type clientSecret: str
"""

class Compiler:

def __init__(self, clientId: str, clientSecret: str):
"""
Initialize the compiler which let you access the Jdoodle API.
:param clientId: The clientId which you can get from https://jdoodle.com/compiler-api/
:type clientId: str
:param clientSecret: The clientSecret which you can get from https://jdoodle.com/compiler-api/
:type clientSecret: str
"""
if not isinstance(clientId, str):
raise TypeError
elif not isinstance(clientSecret, str):
Expand Down Expand Up @@ -114,10 +150,7 @@ def execute(self, script: str, language: str, link: bool = False, stdIn: str = N
response = requests.post(url=self.base_url, headers=self.headers, json=self.json)
response_json = response.json()
if response.status_code == 200:
return Output(output=response_json['output'],
statusCode=response_json['statusCode'],
memory=response_json['memory'],
cpuTime=response_json['cpuTime'])
return Output(response_json)
else:
error = response.json()
if response.status_code == 401:
Expand Down

0 comments on commit 180a94a

Please sign in to comment.