Skip to content

Commit

Permalink
Begin draft of PDAP client
Browse files Browse the repository at this point in the history
  • Loading branch information
maxachis committed Dec 18, 2024
1 parent ee76173 commit 147a786
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions pdap_api_client/PDAPClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from urllib import parse

Check warning on line 1 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L1 <100>

Missing docstring in public module
Raw output
./pdap_api_client/PDAPClient.py:1:1: D100 Missing docstring in public module

Check warning on line 1 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L1 <401>

'urllib.parse' imported but unused
Raw output
./pdap_api_client/PDAPClient.py:1:1: F401 'urllib.parse' imported but unused
from enum import Enum
from typing import Optional

import requests
from requests.models import PreparedRequest

API_URL = "https://data-sources-v2.pdap.dev/api"

class Namespaces(Enum):

Check warning on line 10 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L10 <101>

Missing docstring in public class
Raw output
./pdap_api_client/PDAPClient.py:10:1: D101 Missing docstring in public class
AUTH = "auth"


class RequestManager:
"""
Handles making requests and managing the responses
"""




class URLBuilder:

Check warning on line 22 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L22 <101>

Missing docstring in public class
Raw output
./pdap_api_client/PDAPClient.py:22:1: D101 Missing docstring in public class

Check failure on line 22 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L22 <303>

too many blank lines (4)
Raw output
./pdap_api_client/PDAPClient.py:22:1: E303 too many blank lines (4)

def __init__(self):

Check warning on line 24 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L24 <107>

Missing docstring in __init__
Raw output
./pdap_api_client/PDAPClient.py:24:1: D107 Missing docstring in __init__
self.base_url = API_URL

def build_url(

Check warning on line 27 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L27 <102>

Missing docstring in public method
Raw output
./pdap_api_client/PDAPClient.py:27:1: D102 Missing docstring in public method
self,
namespace: Namespaces,
subdomains: Optional[list[str]] = None,
query_parameters: Optional[dict] = None
):
url = f"{self.base_url}/{namespace.value}"
if subdomains is not None:
url = f"{url}/{'/'.join(subdomains)}"
if query_parameters is None:
return url
req = PreparedRequest()
req.prepare_url(url, params=query_parameters)
return req.url



class AccessManager:

Check failure on line 44 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L44 <303>

too many blank lines (3)
Raw output
./pdap_api_client/PDAPClient.py:44:1: E303 too many blank lines (3)
"""
Manages login, api key, access and refresh tokens
"""
def __init__(self, email: str, password: str):

Check warning on line 48 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L48 <107>

Missing docstring in __init__
Raw output
./pdap_api_client/PDAPClient.py:48:1: D107 Missing docstring in __init__

Check warning on line 48 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L48 <100>

Unused argument 'email'
Raw output
./pdap_api_client/PDAPClient.py:48:24: U100 Unused argument 'email'

Check warning on line 48 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L48 <100>

Unused argument 'password'
Raw output
./pdap_api_client/PDAPClient.py:48:36: U100 Unused argument 'password'
self.url_builder = URLBuilder()

def login(self, email: str, password: str):

Check warning on line 51 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L51 <102>

Missing docstring in public method
Raw output
./pdap_api_client/PDAPClient.py:51:1: D102 Missing docstring in public method
url = self.url_builder.build_url(
namespace=Namespaces.AUTH,
subdomains=["login"]
)
response = requests.post(
url=url,
json={
"email": email,
"password": password
}
)
response.raise_for_status()
# TODO: Finish


class PDAPClient:

Check warning on line 67 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L67 <101>

Missing docstring in public class
Raw output
./pdap_api_client/PDAPClient.py:67:1: D101 Missing docstring in public class

def __init__(self):

Check warning on line 69 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L69 <107>

Missing docstring in __init__
Raw output
./pdap_api_client/PDAPClient.py:69:1: D107 Missing docstring in __init__
pass

def match_agency(self):

Check warning on line 72 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L72 <102>

Missing docstring in public method
Raw output
./pdap_api_client/PDAPClient.py:72:1: D102 Missing docstring in public method
pass

def check_for_unique_source_url(self, url: str):

Check warning on line 75 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L75 <102>

Missing docstring in public method
Raw output
./pdap_api_client/PDAPClient.py:75:1: D102 Missing docstring in public method

Check warning on line 75 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L75 <100>

Unused argument 'url'
Raw output
./pdap_api_client/PDAPClient.py:75:43: U100 Unused argument 'url'
pass

Check warning on line 76 in pdap_api_client/PDAPClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] pdap_api_client/PDAPClient.py#L76 <292>

no newline at end of file
Raw output
./pdap_api_client/PDAPClient.py:76:13: W292 no newline at end of file
Empty file added pdap_api_client/__init__.py
Empty file.

0 comments on commit 147a786

Please sign in to comment.