K87L8BZBS6

RedisApi class

Oct 30th, 2024 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import requests
  2. from typing import List, Dict, Any
  3.  
  4.  
  5. class RedisApi:
  6.     def __init__(self, api_token: str) -> None:
  7.         """
  8.        Initialize RedisApi with the base URL for the landings service and an API token.
  9.  
  10.        Parameters:
  11.            api_token (str): The API token used for authorization.
  12.        """
  13.         self.hostname: str = "develop.k8s.tetrika-school.ru"
  14.         self.url: str = f"https://{self.hostname}/landings_service/api/v1/landings/"
  15.         self.api_token: str = api_token
  16.  
  17.     def get_landings(self) -> List[Dict[str, Any]]:
  18.         """
  19.        Fetches landing page data from the API using the stored API token.
  20.  
  21.        Returns:
  22.             List[Dict[str, Any]]: A list of dictionaries containing the response JSON from the API,
  23.                                     where each dictionary represents a landing.
  24.        """
  25.         headers = {"Authorization": f"Bearer {self.api_token}"}
  26.  
  27.         response = requests.get(url=self.url, headers=headers)
  28.         response_data = response.json()
  29.  
  30.         return response_data
  31.  
Advertisement
Add Comment
Please, Sign In to add comment