readyview 0.0.1__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: readyview
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: ReadyLinks ReadyView API library.
5
5
  Project-URL: Homepage, https://gitlab.com/readylinks
6
6
  Project-URL: Issues, https://gitlab.com/readylinks
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "readyview"
7
- version = "0.0.1"
7
+ version = "0.0.2"
8
8
  authors = [
9
9
  { name="ReadyLinks Developers", email="developers@ready-links.com" },
10
10
  ]
@@ -0,0 +1,5 @@
1
+ from .dashboard import Dashboard
2
+ from .rest_session import *
3
+ from .config import (
4
+ DEFAULT_BASE_URL
5
+ )
@@ -0,0 +1,4 @@
1
+ # Package Constants
2
+
3
+ # Base URL preceding all endpoint resources
4
+ DEFAULT_BASE_URL = "https://api.readylinks.io/"
@@ -0,0 +1,17 @@
1
+ import rest_session
2
+ from switch import Switch
3
+ import os
4
+
5
+ class Dashboard:
6
+ def __init__(self, organization_id=None, api_key=None):
7
+ self.organization_id = organization_id or os.environ.get("READYVIEW_DASHBOARD_ORG_ID")
8
+ self.api_key = api_key or os.environ.get("READYVIEW_DASHBOARD_API_KEY")
9
+ self._rest = rest_session.RestSession(self.organization_id, self.api_key)
10
+ self.switch = Switch(self._rest)
11
+
12
+ def display_info(self):
13
+ return (
14
+ f"Org ID: {self.organization_id}\n"
15
+ f"API Key: {self.api_key}\n"
16
+ )
17
+
@@ -0,0 +1,28 @@
1
+ import requests
2
+ from requests.auth import HTTPBasicAuth
3
+
4
+ # Base URL preceding all endpoint resources
5
+ DEFAULT_BASE_URL = "https://api.readylinks.io/"
6
+
7
+ class RestSession:
8
+ def __init__(self, organization_id: str, api_key: str, base_url=DEFAULT_BASE_URL):
9
+ self.base_url = base_url
10
+ self.organization_id = organization_id
11
+ self.api_key = api_key
12
+
13
+ def request(self, method, url):
14
+ reponse = None
15
+ try:
16
+ response = requests.get(self.base_url + url, auth=HTTPBasicAuth(self.organization_id, self.api_key), timeout=100)
17
+ except Exception as e:
18
+ print(str(e))
19
+ return response
20
+
21
+
22
+ def get(self, url, params=None):
23
+ response = self.request("GET", url)
24
+ if response:
25
+ if response.status_code != 200:
26
+ return {"error": f'failed with code {response.status_code} {response.text}'}
27
+ return response.json()
28
+ return None
@@ -0,0 +1,25 @@
1
+ class Switch(object):
2
+ def __init__(self, rest):
3
+ super(Switch, self).__init__()
4
+ self._rest = rest
5
+
6
+ def get_ports(self, mac_address: str):
7
+ url = f"v1/devices/{mac_address}/switch/ports"
8
+ return self._rest.get(url)
9
+
10
+ def get_switch(self, mac_address: str):
11
+ url = f"v1/devices/{mac_address}/switch"
12
+ return self._rest.get(url)
13
+
14
+ def get_switches(self):
15
+ url = 'v2/devices'
16
+ return self._rest.get(url)
17
+
18
+ def get_device(self, id: str):
19
+ url = f'v2/devices/{id}'
20
+ return self._rest.get(url)
21
+
22
+ def display_info(self):
23
+ return (
24
+ f"MAC Address: {self.mac_address}\n"
25
+ )
File without changes
@@ -1,10 +0,0 @@
1
- class Dashboard:
2
- def __init__(self, shipment_id, tracking_number):
3
- self.organization_id = shipment_id
4
- self.api_key = tracking_number
5
-
6
- def display_info(self):
7
- return (
8
- f"Org ID: {self.organization_id}\n"
9
- f"API Key: {self.api_key}\n"
10
- )
File without changes
File without changes