diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml index 21f2f01..0aaf369 100644 --- a/.github/workflows/pythonpublish.yml +++ b/.github/workflows/pythonpublish.yml @@ -1,26 +1,27 @@ name: Upload Python Package - on: - release: - types: [created] - + release: + types: [created] jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.1 + - name: Setup Python (3.8) + uses: actions/setup-python@v5 + with: + python-version: "3.8" + - name: Upgrade Pip, Build, Twine + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade build + python -m pip install twine + - name: Build Source + run: | + python -m build + - name: Publish Source + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/* \ No newline at end of file diff --git a/.gitignore b/.gitignore index 38a0812..ba0732b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ notes.txt *.pyc **/__pycache__ -.vscode \ No newline at end of file +.vscode +.dist \ No newline at end of file diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..e0d61b5 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.9.4 diff --git a/LICENSE b/LICENSE index 02246bb..cd09477 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021- Sanjay-B(Sanjay Bhadra) +Copyright (c) 2024- sbhadr (Sanjay Bhadra) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/examples/legacy/instanceGroup.py b/examples/legacy/instanceGroup.py index c0f210c..8d25113 100644 --- a/examples/legacy/instanceGroup.py +++ b/examples/legacy/instanceGroup.py @@ -1,5 +1,4 @@ import asyncio -import aiohttp from pyblox3 import Groups_v1 # Instance your group as a variable diff --git a/examples/legacy/login.py b/examples/legacy/login.py index a711b07..0540f29 100644 --- a/examples/legacy/login.py +++ b/examples/legacy/login.py @@ -2,8 +2,10 @@ # examples -> login.py # pyblox # -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. +# THIS DOES NOT WORK. Roblox removed the ability for bots to login traditionally. +# Use an account cookie or opencloud instead. # from pyblox3 import * diff --git a/pyblox3/__init__.py b/pyblox3/__init__.py deleted file mode 100644 index 923bc5f..0000000 --- a/pyblox3/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -# -# __init__.py -# pyblox -# -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. -# - -__title__ = 'pyblox' -__author__ = 'Sanjay-B' -__license__ = 'MIT' -__copyright__ = 'Copyright © 2021- Sanjay-B(Sanjay Bhadra)' - -# Dependencies - - -# Parent Class Modules -from .src.groups import * -from .src.users import * -from .src.auth import * -from .src.abtesting import * -from .src.accountInformation import * -from .src.privateMessages import * -from .src.games import * - - - -# Utility Modules -from .src.util import * \ No newline at end of file diff --git a/pyblox3/src/util/cached.py b/pyblox3/src/util/cached.py deleted file mode 100644 index 119c660..0000000 --- a/pyblox3/src/util/cached.py +++ /dev/null @@ -1,12 +0,0 @@ -# -# util -> cached.py -# pyblox -# -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. -# - -class Cached: - cache = {} - file_cache = {} - auth = {} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b2ea1c5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,57 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "pyblox3" +version = "3.0-beta.6" +authors = [ + { name="Sanjay Bhadra", email="sbhadr.github@gmail.com" } +] +description = "An API wrapper for Roblox written in Python" +readme = "README.md" +license = { file="LICENSE" } +requires-python = ">=3.8" +dependencies = [ + "aiohttp", + "asyncio", + "httpx", + "pytest" +] +classifiers = [ + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Development Status :: 4 - Beta", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13" +] +keywords = [ + "Python", "Roblox", "API", "Wrapper", "Library", "Python3", "API-Wrapper", "RobloxDev", + "Roblox-API", "Game Development", "Automation", "Scripting", "HTTP Requests", + "JSON", "Authentication", "User Management", "Asset Management", "Game Analytics", + "Server Communication", "Data Parsing", "Web Scraping", "Multiplayer Games", + "Community Engagement", "Player Data", "Game Sessions", "Inventory Management", "Platform Integration", + "Cloud Services", "Social Features", "Development Tools", "Content Creation", "Security", + "Rate Limiting", "Error Handling", "Open Source", "Collaboration", "Version Control", + "Documentation", "Tutorials", "User Support", "Performance Optimization", "Cross-platform", + "Event Handling", "Asynchronous Programming", "Dependency Management", "Unit Testing", + "Continuous Integration", "Deployment", "Community Contributions", "Licensing" +] + +[project.urls] +Repository = "https://github.com/RbxAPI/Pyblox/tree/nightly_build" +Issues = "https://github.com/RbxAPI/Pyblox/issues" +Source = "https://github.com/RbxAPI/Pyblox" +Discord = "https://discord.com/invite/EDXNdAT" + +[tool.hatch.build.targets.wheel] +packages = [ + "src", + "pyblox3.webapi", + "pyblox3.webapi.util" +] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index d56f488..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -aiohttp -asyncio -httpx -pytest \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index e8b1f8c..0000000 --- a/setup.py +++ /dev/null @@ -1,46 +0,0 @@ -''' -MIT License - -Copyright (c) 2021- Sanjay-B (Sanjay Bhadra) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -''' - -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="pyblox3", - version="3.0-beta.5", - author="Sanjay-B (Sanjay Bhadra)", - author_email="sanjay2003rbx@gmail.com", - description="An API wrapper for Roblox written in Python.", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/RbxAPI/Pyblox/tree/nightly_build", - packages=['pyblox3','pyblox3.src','pyblox3.src.util'], - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], - python_requires='>=3.6', -) diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..4c1ccf7 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,26 @@ +# +# __init__.py +# pyblox +# +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. +# + +__title__ = 'pyblox' +__author__ = 'sbhadr' +__version__ = '3.0-beta.6' +__license__ = 'MIT' +__copyright__ = 'Copyright © 2024- sbhadr (Sanjay Bhadra)' + + +# Parent Class Modules +from .webapi.groups import * +from .webapi.users import * +from .webapi.auth import * +from .webapi.abtesting import * +from .webapi.accountInformation import * +from .webapi.privateMessages import * +from .webapi.games import * + +# Utility Modules +from .webapi.util import * \ No newline at end of file diff --git a/pyblox3/src/abtesting.py b/src/webapi/abtesting.py similarity index 92% rename from pyblox3/src/abtesting.py rename to src/webapi/abtesting.py index 05748d2..6e34119 100644 --- a/pyblox3/src/abtesting.py +++ b/src/webapi/abtesting.py @@ -2,11 +2,11 @@ # abtesting.py # pyblox # -# By NSG (Nikita Petko) and IvanG (Ivan Gregrovnich) with Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B with MFD. All rights reserved. +# By NSG (Nikita Petko) and IvanG (Ivan Gregrovnich) with sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr with MFD. All rights reserved. # -from .util import * +from .util import Req root = "https://abtesting.roblox.com" diff --git a/pyblox3/src/accountInformation.py b/src/webapi/accountInformation.py similarity index 99% rename from pyblox3/src/accountInformation.py rename to src/webapi/accountInformation.py index 4d09251..7db5541 100644 --- a/pyblox3/src/accountInformation.py +++ b/src/webapi/accountInformation.py @@ -2,11 +2,11 @@ # accountInformation.py # pyblox # -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. # -from .util import * +from .util import Req Req = Req() diff --git a/pyblox3/src/auth.py b/src/webapi/auth.py similarity index 57% rename from pyblox3/src/auth.py rename to src/webapi/auth.py index 6c481ca..36f44e4 100644 --- a/pyblox3/src/auth.py +++ b/src/webapi/auth.py @@ -2,14 +2,10 @@ # auth.py # pyblox # -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. # -from .util import * - -Req = Req() - root = "https://auth.roblox.com" class Auth_v2: diff --git a/pyblox3/src/games.py b/src/webapi/games.py similarity index 99% rename from pyblox3/src/games.py rename to src/webapi/games.py index 8efc67a..fc1b5ce 100644 --- a/pyblox3/src/games.py +++ b/src/webapi/games.py @@ -2,11 +2,11 @@ # games.py # pyblox # -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. # -from .util import * +from .util import Req Req = Req() diff --git a/pyblox3/src/groups.py b/src/webapi/groups.py similarity index 99% rename from pyblox3/src/groups.py rename to src/webapi/groups.py index a27842f..826f70a 100644 --- a/pyblox3/src/groups.py +++ b/src/webapi/groups.py @@ -2,11 +2,11 @@ # groups.py # pyblox # -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. # -from .util import * +from .util import Req Req = Req() diff --git a/pyblox3/src/privateMessages.py b/src/webapi/privateMessages.py similarity index 98% rename from pyblox3/src/privateMessages.py rename to src/webapi/privateMessages.py index b4dd91f..2c26ec7 100644 --- a/pyblox3/src/privateMessages.py +++ b/src/webapi/privateMessages.py @@ -2,11 +2,11 @@ # privateMessages.py # pyblox # -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2021- Sanjay-B(Sanjay Bhadra). All rights reserved. +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. # -from .util import * +from .util import Req Req = Req() diff --git a/pyblox3/src/users.py b/src/webapi/users.py similarity index 96% rename from pyblox3/src/users.py rename to src/webapi/users.py index c86c0df..241387d 100644 --- a/pyblox3/src/users.py +++ b/src/webapi/users.py @@ -2,11 +2,11 @@ # users.py # pyblox # -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2020- Sanjay-B(Sanjay Bhadra). All rights reserved. +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. # -from .util import * +from .util import Req Req = Req() diff --git a/pyblox3/src/util/__init__.py b/src/webapi/util/__init__.py similarity index 73% rename from pyblox3/src/util/__init__.py rename to src/webapi/util/__init__.py index 0940a47..4635dfa 100644 --- a/pyblox3/src/util/__init__.py +++ b/src/webapi/util/__init__.py @@ -1,19 +1,19 @@ -# -# __init__.py -# pyblox -> util -# -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. -# - -# Some nifty methods that I like to keep handy because -# I write them over and over for every project. -# Bet you relate.. -# -# Message from Sanjay 2024: Who the hell uses -# the word nifty..? - -# Parent Class Modules -from .req import Req -from .io import io -from .cached import Cached +# +# __init__.py +# pyblox -> util +# +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. +# + +# Some nifty methods that I like to keep handy because +# I write them over and over for every project. +# Bet you relate.. +# +# Message from Sanjay 2024: Who the hell uses +# the word nifty..? + +# Parent Class Modules +from .req import Req +from .io import io +from .cached import Cached diff --git a/src/webapi/util/cached.py b/src/webapi/util/cached.py new file mode 100644 index 0000000..a5167b5 --- /dev/null +++ b/src/webapi/util/cached.py @@ -0,0 +1,12 @@ +# +# util -> cached.py +# pyblox +# +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. +# + +class Cached: + cache = {} + file_cache = {} + auth = {} \ No newline at end of file diff --git a/pyblox3/src/util/io.py b/src/webapi/util/io.py similarity index 83% rename from pyblox3/src/util/io.py rename to src/webapi/util/io.py index ad06a5c..7eb382a 100644 --- a/pyblox3/src/util/io.py +++ b/src/webapi/util/io.py @@ -1,38 +1,38 @@ -# -# util -> jsoni.py -# pyblox -# -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. -# - -import json -import os -import inspect - -class io: - - def read(**kwargs): - file = kwargs.get("file",None) - with open(str(file),"r",encoding="utf-8") as jfile: - data = json.load(jfile) - return data - - def write(**kwargs): - file = kwargs.get("file",None) - key = kwargs.get("key",None) - value = kwargs.get("value",None) - with open(str(file),"r",encoding="utf-8") as jfile: - data = json.load(jfile) - jfile.close() - data[str(key)].append(value) - with open(str(file),"w",encoding="utf-8") as jfile: - json.dumps(data,jfile) - jfile.close() - - def getPath(): - file_string = os.path.abspath(inspect.stack()[-1][1]) - print(file_string) - print(file_string[:27]) - - +# +# util -> jsoni.py +# pyblox +# +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. +# + +import json +import os +import inspect + +class io: + + def read(**kwargs): + file = kwargs.get("file",None) + with open(str(file),"r",encoding="utf-8") as jfile: + data = json.load(jfile) + return data + + def write(**kwargs): + file = kwargs.get("file",None) + key = kwargs.get("key",None) + value = kwargs.get("value",None) + with open(str(file),"r",encoding="utf-8") as jfile: + data = json.load(jfile) + jfile.close() + data[str(key)].append(value) + with open(str(file),"w",encoding="utf-8") as jfile: + json.dumps(data,jfile) + jfile.close() + + def getPath(): + file_string = os.path.abspath(inspect.stack()[-1][1]) + print(file_string) + print(file_string[:27]) + + diff --git a/pyblox3/src/util/req.py b/src/webapi/util/req.py similarity index 95% rename from pyblox3/src/util/req.py rename to src/webapi/util/req.py index 927ccc2..dd03451 100644 --- a/pyblox3/src/util/req.py +++ b/src/webapi/util/req.py @@ -1,126 +1,126 @@ -# -# util -> req.py -# pyblox -# -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. -# - -import httpx - -class HttpError(Exception): - """ - Base class that represents an HTTP Error in the form of an exception. - """ - def __init__(self, kind="Generic", message="Generic Error", url="Somewhere"): - """ - Creates an exception with specified message. - If not message is provided, it defaults to "Generic Error". - - @param kind: str. Represents the the kind of exception. - @param message: str. Represents the error message of the exception. - @param url: str. Represents the url the error occured at. - """ - self.kind = kind - self.message = message - self.url = url - super().__init__(self.message) - - -class Req: - """ - Base class that holds HTTP request and response mechanisms. - """ - - async def request(self, t: str, url: str, payload=None, header={}, cookies={}): - """ - Creates, executes and returns a request in the form of a response. - Throws an exception if conditions are not met. - - @param t: Str. Type of request. ie. GET, POST, PATCH, DELETE or DEL. - Can also be lowercase, snakecase, etc. - @param url: Str. URL to send the request. - @param payload: Dict or None. Represents the payload or data to send - the request with. - @param header: Dict. Represents the headers to send the request with. - @param cookies: Dict. Represents the cookies to send the request with. - - @return: Tuple. - - @example: - - # GET Request - response = Req.request(t="GET",url="http://httpbin.org/get") - - # You can get the status of the request by doing: - response[0] - - # And so on... its a tuple so this also works as a shorthand: - response = Req.request(t="GET",url="http://httpbin.org/get")[0] - - @example: - - # POST Request - data = {"Username":"JohnDoe","Password":"JaneDoe"} - - # Data you want to send as a payload - response = Req.request(t="POST",url="http//httpbin.org/post",payload=data) - - # Again, all data is returned wholesale as a tuple so this works: - response[0] # Gets you the status of the request - - # Once again, this works as a shorthand: - response = Req.request(t="POST",url"http://httpbin.org/post",payload=data)[0] - """ - async with httpx.AsyncClient(cookies=cookies) as client: - - # TODO: Backwards Compatibility (will be renamed to this later) - kind = t.upper() - headers = header - - # Obtain our initial token (fresh) - response = await client.post(url="https://www.roblox.com/authentication/signoutfromallsessionsandreauthenticate", data=None, headers=headers) - csrf_token = response.headers.get("X-CSRF-TOKEN") - if not csrf_token: - raise HttpError("POST Request", "Initial X-CSRF-TOKEN was not found in headers, aborted", url) - - # Perform actual request - headers["X-CSRF-TOKEN"] = csrf_token - if kind == "GET": - response = await client.get(url, headers=headers) - elif kind == "POST": - if not cookies: - raise HttpError("POST Request", "Endpoint requires account cookie / authentication", url) - elif not payload: - raise HttpError("POST Request", "Endpoint requires payload / request body", url) - response = await client.post(url=url, data=payload, headers=headers) - elif kind == "PATCH": - if not cookies: - raise HttpError("PATCH Request", "Endpoint requires account cookie / authentication", url) - elif not payload: - raise HttpError("PATCH Request", "Endpoint requires payload / request body", url) - response = await client.patch(url=url, data=payload, headers=headers) - elif kind == ("DEL" or "DELETE"): - if not cookies: - raise HttpError("DELETE Request", "Endpoint requires account cookie / authentication", url) - response = await client.delete(url=url, payload=payload, headers=headers) - return self.parse_response(response) - - def parse_response(self, response): - """ - Parses respone into expected tuple format. - - @param response: Response. The response object from the request that has been performed. - - @return: tuple. If the status code is 200, the return is Tuple(status_code, content, headers, encoding, json). - If the status code is not 200, the return is Tuple(status_code, content, headers, encoding, json["errors"][0]). - Note that a status code of 200 means the request is successful. Otherwise, an error has occured. - """ - status_code = response.status_code - content = response.content - headers = response.headers - encoding = response.encoding - json = response.json() - if status_code == 200: - return status_code, content, headers, encoding, json +# +# util -> req.py +# pyblox +# +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. +# + +import httpx + +class HttpError(Exception): + """ + Base class that represents an HTTP Error in the form of an exception. + """ + def __init__(self, kind="Generic", message="Generic Error", url="Somewhere"): + """ + Creates an exception with specified message. + If not message is provided, it defaults to "Generic Error". + + @param kind: str. Represents the the kind of exception. + @param message: str. Represents the error message of the exception. + @param url: str. Represents the url the error occured at. + """ + self.kind = kind + self.message = message + self.url = url + super().__init__(self.message) + + +class Req: + """ + Base class that holds HTTP request and response mechanisms. + """ + + async def request(self, t: str, url: str, payload=None, header={}, cookies={}): + """ + Creates, executes and returns a request in the form of a response. + Throws an exception if conditions are not met. + + @param t: Str. Type of request. ie. GET, POST, PATCH, DELETE or DEL. + Can also be lowercase, snakecase, etc. + @param url: Str. URL to send the request. + @param payload: Dict or None. Represents the payload or data to send + the request with. + @param header: Dict. Represents the headers to send the request with. + @param cookies: Dict. Represents the cookies to send the request with. + + @return: Tuple. + + @example: + + # GET Request + response = Req.request(t="GET",url="http://httpbin.org/get") + + # You can get the status of the request by doing: + response[0] + + # And so on... its a tuple so this also works as a shorthand: + response = Req.request(t="GET",url="http://httpbin.org/get")[0] + + @example: + + # POST Request + data = {"Username":"JohnDoe","Password":"JaneDoe"} + + # Data you want to send as a payload + response = Req.request(t="POST",url="http//httpbin.org/post",payload=data) + + # Again, all data is returned wholesale as a tuple so this works: + response[0] # Gets you the status of the request + + # Once again, this works as a shorthand: + response = Req.request(t="POST",url"http://httpbin.org/post",payload=data)[0] + """ + async with httpx.AsyncClient(cookies=cookies) as client: + + # TODO: Backwards Compatibility (will be renamed to this later) + kind = t.upper() + headers = header + + # Obtain our initial token (fresh) + response = await client.post(url="https://www.roblox.com/authentication/signoutfromallsessionsandreauthenticate", data=None, headers=headers) + csrf_token = response.headers.get("X-CSRF-TOKEN") + if not csrf_token: + raise HttpError("POST Request", "Initial X-CSRF-TOKEN was not found in headers, aborted", url) + + # Perform actual request + headers["X-CSRF-TOKEN"] = csrf_token + if kind == "GET": + response = await client.get(url, headers=headers) + elif kind == "POST": + if not cookies: + raise HttpError("POST Request", "Endpoint requires account cookie / authentication", url) + elif not payload: + raise HttpError("POST Request", "Endpoint requires payload / request body", url) + response = await client.post(url=url, data=payload, headers=headers) + elif kind == "PATCH": + if not cookies: + raise HttpError("PATCH Request", "Endpoint requires account cookie / authentication", url) + elif not payload: + raise HttpError("PATCH Request", "Endpoint requires payload / request body", url) + response = await client.patch(url=url, data=payload, headers=headers) + elif kind == ("DEL" or "DELETE"): + if not cookies: + raise HttpError("DELETE Request", "Endpoint requires account cookie / authentication", url) + response = await client.delete(url=url, payload=payload, headers=headers) + return self.parse_response(response) + + def parse_response(self, response): + """ + Parses respone into expected tuple format. + + @param response: Response. The response object from the request that has been performed. + + @return: tuple. If the status code is 200, the return is Tuple(status_code, content, headers, encoding, json). + If the status code is not 200, the return is Tuple(status_code, content, headers, encoding, json["errors"][0]). + Note that a status code of 200 means the request is successful. Otherwise, an error has occured. + """ + status_code = response.status_code + content = response.content + headers = response.headers + encoding = response.encoding + json = response.json() + if status_code == 200: + return status_code, content, headers, encoding, json return status_code, content, headers, encoding, json["errors"][0] \ No newline at end of file diff --git a/TESTFILE.py b/tests/TESTFILE.py similarity index 75% rename from TESTFILE.py rename to tests/TESTFILE.py index 4d6e23e..db7858b 100644 --- a/TESTFILE.py +++ b/tests/TESTFILE.py @@ -2,15 +2,14 @@ # TESTFILE.py # pyblox # -# By Sanjay-B(Sanjay Bhadra) -# Copyright © 2019- Sanjay-B(Sanjay Bhadra). All rights reserved. +# By sbhadr (Sanjay Bhadra) +# Copyright © 2024- sbhadr (Sanjay Bhadra). All rights reserved. # # This file does can be deleted w/o any issues to source. # import asyncio -import aiohttp -from pyblox3 import Auth_v2, Groups_v1 +from src import Auth_v2, Groups_v1 test_data = { "isApprovalRequired": False, @@ -23,7 +22,7 @@ # Instance your auth details base_bot_user = Auth_v2(cookies={'.ROBLOSECURITY': "YourCookie"}) # Instance your group as a variable -base_group = Groups_v1(groupid=5265464,auth=base_bot_user) +base_group = Groups_v1(groupid=7,auth=base_bot_user) # Standard Event Loop async def event_loop(): diff --git a/tests/.keep b/tests/__init__.py similarity index 100% rename from tests/.keep rename to tests/__init__.py