Spaces:
Build error
Build error
import requests | |
from config.settings import SHOPIFY_ACCESS_TOKEN, SHOP_NAME | |
from utils.logger import setup_logger | |
from utils.model_loader import ModelLoader | |
logger = setup_logger(__name__) | |
class ShopifyClient: | |
def __init__(self): | |
self.session = ModelLoader.create_retry_session() | |
self.headers = { | |
'X-Shopify-Access-Token': SHOPIFY_ACCESS_TOKEN, | |
'Content-Type': 'application/json' | |
} | |
if not SHOP_NAME: | |
raise ValueError("SHOP_NAME environment variable not set") | |
self.base_url = f"https://{SHOP_NAME}/admin/api/2023-10" | |
def fetch_data(self, endpoint): | |
try: | |
url = f"{self.base_url}/{endpoint}.json" | |
response = self.session.get(url, headers=self.headers) | |
response.raise_for_status() | |
return response.json() | |
except requests.exceptions.RequestException as e: | |
logger.error(f"Shopify API error: {str(e)}") | |
return None | |