Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitAuto: [FEATURE] Implement SKU Seller API #336

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# SKU Seller API Integration

This feature implements the SKU Seller API integration, allowing users to consult and delete an SKU Seller. An SKU Seller is a seller associated with an SKU, which is essential for managing multiple sellers offering the same product in a marketplace.

## Features

- **Consult SKU Seller**: Retrieve information about a specific SKU Seller.
- **Delete SKU Seller**: Remove the association of a seller with an SKU.

## Usage

### API Client

```python
from src.api_client import APIClient
from src.authentication import Authentication

auth = Authentication(token="your_api_token")
api_client = APIClient(base_url="https://api.vtex.com", headers=auth.get_headers())
```
# VTEX SDK

🛒 ⚙️ [VTEX](https://vtex.com) platform .NET SDK.
Expand Down
21 changes: 21 additions & 0 deletions src/api_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import requests

class APIClient:
def __init__(self, base_url, headers):
self.base_url = base_url
self.headers = headers

def get_sku_seller(self, sku_id, seller_id):
url = f"{self.base_url}/sku/{sku_id}/seller/{seller_id}"
response = requests.get(url, headers=self.headers)
response.raise_for_status()
return response.json()

def delete_sku_seller(self, sku_id, seller_id):
url = f"{self.base_url}/sku/{sku_id}/seller/{seller_id}"
response = requests.delete(url, headers=self.headers)
response.raise_for_status()
return response.status_code

# Example usage:
# client = APIClient(base_url="https://api.vtex.com", headers={"Authorization": "Bearer token"})
16 changes: 16 additions & 0 deletions src/authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Authentication:
def __init__(self, token):
self.token = token

def get_headers(self):
return {
"Authorization": f"Bearer {self.token}",
"Content-Type": "application/json"
}

# Example usage:
# auth = Authentication(token="your_api_token")
# headers = auth.get_headers()
# api_client = APIClient(base_url="https://api.vtex.com", headers=headers)
# service = SkuSellerService(api_client)
# sku_seller = service.get_sku_seller("sku123", "seller456")
19 changes: 19 additions & 0 deletions src/error_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class APIError(Exception):
def __init__(self, status_code, message="API request failed"):
self.status_code = status_code
self.message = message
super().__init__(self.message)

def __str__(self):
return f"{self.message} (Status Code: {self.status_code})"

def handle_api_errors(response):
if not response.ok:
raise APIError(status_code=response.status_code, message=response.text)

# Example usage in APIClient:
# response = requests.get(url, headers=self.headers)
# handle_api_errors(response)
# return response.json()
#
# This function can be used in the APIClient methods to handle errors.
15 changes: 15 additions & 0 deletions src/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class SkuSeller:
def __init__(self, sku_id, seller_id, price, inventory):
self.sku_id = sku_id
self.seller_id = seller_id
self.price = price
self.inventory = inventory

@classmethod
def from_json(cls, data):
return cls(
sku_id=data.get('skuId'),
seller_id=data.get('sellerId'),
price=data.get('price'),
inventory=data.get('inventory')
)
28 changes: 28 additions & 0 deletions src/service_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from src.api_client import APIClient

Check notice on line 1 in src/service_layer.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/service_layer.py#L1

'src.api_client.APIClient' imported but unused (F401)

Check warning on line 1 in src/service_layer.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/service_layer.py#L1

Unused APIClient imported from src.api_client
from src.models import SkuSeller

class SkuSellerService:
def __init__(self, api_client):
self.api_client = api_client

def get_sku_seller(self, sku_id, seller_id):
try:
data = self.api_client.get_sku_seller(sku_id, seller_id)
return SkuSeller.from_json(data)
except Exception as e:
print(f"Error retrieving SKU Seller: {e}")
return None

def delete_sku_seller(self, sku_id, seller_id):
try:
status_code = self.api_client.delete_sku_seller(sku_id, seller_id)
return status_code == 204
except Exception as e:
print(f"Error deleting SKU Seller: {e}")
return False

# Example usage:
# api_client = APIClient(base_url="https://api.vtex.com", headers={"Authorization": "Bearer token"})
# service = SkuSellerService(api_client)
# sku_seller = service.get_sku_seller("sku123", "seller456")
# success = service.delete_sku_seller("sku123", "seller456")
33 changes: 33 additions & 0 deletions tests/test_sku_seller_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest
from unittest.mock import MagicMock
from src.service_layer import SkuSellerService
from src.models import SkuSeller

class TestSkuSellerService(unittest.TestCase):
def setUp(self):
self.mock_api_client = MagicMock()
self.service = SkuSellerService(self.mock_api_client)

def test_get_sku_seller(self):
# Mock API response
self.mock_api_client.get_sku_seller.return_value = {
'skuId': 'sku123',
'sellerId': 'seller456',
'price': 100.0,
'inventory': 50
}

sku_seller = self.service.get_sku_seller('sku123', 'seller456')
self.assertIsInstance(sku_seller, SkuSeller)
self.assertEqual(sku_seller.sku_id, 'sku123')
self.assertEqual(sku_seller.seller_id, 'seller456')

def test_delete_sku_seller(self):
# Mock API response
self.mock_api_client.delete_sku_seller.return_value = 204

success = self.service.delete_sku_seller('sku123', 'seller456')
self.assertTrue(success)

if __name__ == '__main__':
unittest.main()
Loading