-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "crouton" | ||
version = "0.0.3" | ||
version = "0.0.4.dev1" | ||
description = "A repository to enable API CRUD Routing" | ||
authors = ["Jacob Stewart <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pydantic import BaseModel | ||
|
||
# UUID | ||
from hashlib import sha256 | ||
from uuid import UUID, uuid4, uuid5 | ||
|
||
|
||
class UUIDGenerator(BaseModel): | ||
namespace: UUID = UUID(NAMESPACE_URL_UUID) | ||
|
||
|
||
def create(self): | ||
name: UUID = str(uuid4()) | ||
return str(uuid5(self.namespace, name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import requests as r | ||
|
||
class AsyncCroutonClient: | ||
def __init__(self, API_ROOT, ACCESS_STRING): | ||
self.API_ROOT = API_ROOT | ||
self.ACCESS_STRING = ACCESS_STRING | ||
|
||
async def get(self, resource: str, item_id: str = None): | ||
if item_id: | ||
res = r.get(self.API_ROOT+resource+'/'+item_id+self.ACCESS_STRING) | ||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code) | ||
print(res.json()) | ||
raise ValueError | ||
else: | ||
res = r.get(self.API_ROOT+resource+self.ACCESS_STRING) | ||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code) | ||
print(res.json()) | ||
raise ValueError | ||
|
||
|
||
def post(self, resource: str, data_obj: dict): | ||
data_obj.update({'id': UUIDGenerator().create()}) | ||
res = r.post(self.API_ROOT+resource+self.ACCESS_STRING, | ||
json=data_obj) | ||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code) | ||
print(res.json()) | ||
raise ValueError | ||
|
||
|
||
def put(self, resource: str, data_obj: dict, item_id: str = None): | ||
if item_id: | ||
res = r.put(self.API_ROOT+resource+'/'+item_id+self.ACCESS_STRING, | ||
json=data_obj) | ||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code) | ||
print(res.json()) | ||
raise ValueError | ||
|
||
def delete(self, resource: str, item_id: str = None): | ||
if item_id: | ||
res = r.delete(self.API_ROOT+resource+'/'+item_id+self.ACCESS_STRING) | ||
else: | ||
res = r.delete(self.API_ROOT+resource+'/'+item_id+self.ACCESS_STRING) | ||
|
||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code, res.json()) | ||
raise ValueError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from loadenv import * | ||
from .UUID import UUIDGenerator | ||
|
||
import requests as r | ||
|
||
def api_get_call(resource: str, item_id: str = None): | ||
if item_id: | ||
res = r.get(API_ROOT+resource+'/'+item_id+ACCESS_STRING) | ||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code) | ||
print(res.json()) | ||
|
||
# Test | ||
raise ValueError(res.status_code) | ||
else: | ||
res = r.get(API_ROOT+resource+ACCESS_STRING) | ||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code) | ||
print(res.json()) | ||
|
||
# Test | ||
raise ValueError(res.json()) | ||
|
||
|
||
def api_post_call(resource: str, data_obj: dict): | ||
if 'id' not in data_obj: | ||
data_obj.update({'id': UUIDGenerator().create()}) | ||
res = r.post(API_ROOT+resource+ACCESS_STRING, | ||
json=data_obj) | ||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code) | ||
print(res.json()) | ||
raise ValueError | ||
|
||
|
||
def api_put_call(resource: str, data_obj: dict, item_id: str): | ||
res = r.put(API_ROOT+resource+'/'+item_id+ACCESS_STRING, | ||
json=data_obj) | ||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code) | ||
print(res.json()) | ||
raise ValueError | ||
|
||
|
||
def api_delete_call(resource: str, item_id: str = None): | ||
if item_id: | ||
res = r.delete(API_ROOT+resource+'/'+item_id+ACCESS_STRING) | ||
else: | ||
res = r.delete(API_ROOT+resource+'/'+item_id+ACCESS_STRING) | ||
|
||
if res.status_code == 200: | ||
return res.json() | ||
else: | ||
print(res.status_code, res.json()) | ||
raise ValueError | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "crouton_client" | ||
version = "0.0.3.dev3" | ||
version = "0.0.3" | ||
description = "A client for Swarmauri's crouton." | ||
authors = ["Jacob Stewart <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
@@ -15,10 +15,8 @@ classifiers = [ | |
|
||
[tool.poetry.dependencies] | ||
python = ">=3.10,<4.0" | ||
fastapi = "*" | ||
databases = "*" | ||
SQLAlchemy-Utils = "*" | ||
#httpx = "*" | ||
requests = "*" | ||
pydantic = "*" | ||
|
||
[tool.poetry.dev-dependencies] | ||
flake8 = "^7.0" # Add flake8 as a development dependency | ||
|