File size: 1,001 Bytes
af3dbe5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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