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

Fix nested query params in list and get methods #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
110 changes: 64 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# SwellPy - Headless ecommerce Python API wrapper

## Authors/ Maintainers
[Greg Hoskin](mailto:[email protected])

[Mustafa Hoda](mailto:[email protected])


## Overview
> This library implements a convenient wrapper for Swell's [Backend API](https://swell.store/docs/api)
and is authorized with a private key making it ideal for server-side use.
Expand All @@ -32,67 +26,80 @@ Rate limiting and caching (LRU) are also included for better performance.
Currently, all responses are python dictionaries generated from requests.json().
This may evolve to return individual classes with advanced processing and methods.

## Prerequisites

1. Install [pyenv](https://github.com/pyenv/pyenv#installation)

## Getting Setup
1. Clone SwellPy and build locally
```

1. Clone SwellPy and build the project
```bash
git clone [email protected]:swellstores/swellpy.git
cd swellpy
pyenv install -s

python -m build
pip3 install -r requirements.txt
python3 -m build
```

2. Install and Import
2. Install and import the package locally

```bash
pip3 install dist/swellpy-0.0.1.tar.gz
```
pip install [relative path to swellpy]
```

## Initialization Options
When creating a Swell instance, you can pass initialization options for the
desired amount of rate limiting (by # of calls and period)

```python
from swellpy import Swell
```

3. Instantiate a new Swell instance
```python
swell = Swell({
store_id: "SWELL_STORE_ID",
api_key: "SWELL_API_KEY"
)}
swell = Swell({
"store_id": "SWELL_STORE_ID",
"api_key": "SWELL_API_KEY",
"options": {
"rate_limit_calls": 2,
"rate_limit_period": 1,
},
})
```

4. Request resource
### List

```python
response = swell.products.create({'name': 'my-product-slug'})
print(response) # or setup logging (see below)
query = {
"date_created": {
"$gte": "2022-09-25T00:00:00.000Z"
},
"expand": ["items.product", "shipments:100"],
}
response = swell.orders.list(query)
print(response)
```

**About Swell**

[Swell](https://www.swell.is) is a customizable, API-first platform for powering
modern B2C/B2B shopping experiences and marketplaces. Build and connect anything
using your favorite technologies, and provide admins with an easy to use dashboard.


## Initialization Options
When creating a Swell instance, you can pass initialization options for the
desired amount of rate limiting (by # of calls and period)
### Create

```python
swell = Swell({
"store_id": "SWELL_STORE_ID",
"api_key": "SWELL_API_KEY"
"options": {
"rate_limit_calls": 2,
"rate_limit_period": 1
}
})
data = {
"name": "T-Shirt",
"price": 99.00,
"active": True,
"options": [
{
"name": "Size",
"values": [
{ "name": "Small" },
{ "name": "Large" },
],
},
],
}
response = swell.products.create(data)
print(response)
```
## Documentation

📖 [**View Swell Backend API Documentation**](https://developers.swell.is/backend-api/introduction)


## Handling log messages
## Logging

SwellPy uses the standard Logging library to log HTTP requests (DEBUG level).
To capture these logs, a handler can be configured as shown:
Expand All @@ -108,4 +115,15 @@ handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.addHandler(handler)
```

## Documentation

📖 [**View Swell Backend API Documentation**](https://developers.swell.is/backend-api/introduction)

**About Swell**

[Swell](https://www.swell.is) is a customizable, API-first platform for powering
modern B2C/B2B shopping experiences and marketplaces. Build and connect anything
using your favorite technologies, and provide admins with an easy to use dashboard.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name="swellpy"
version="0.0.1"
description = "Python API Wrapper for Swell"
classifiers = ["Programming Language :: Python :: 3"]
authors = [{ name="Greg Hoskin", email="[email protected]"}, { "name"="Musafa Hoda", email="[email protected]"}]
authors = [{ name="Greg Hoskin" }, { "name"="Musafa Hoda" }]
dependencies = [
"requests",
"requests-toolbelt",
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ requests-toolbelt==0.10.1
vcrpy==1.10.3
ratelimit==2.2.1
pytest==7.2.0
python-dotenv===1.0.0
build==1.0.3
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
name=PACKAGE_NAME,
version=VERSION,
author='Greg Hoskin, Mustafa Hoda',
author_email='[email protected], [email protected]',
packages=find_packages(),
install_requires=[
'requests',
Expand Down
4 changes: 2 additions & 2 deletions swellpy/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def list(self, params: Optional[dict] = None) -> dict:
self.check_limit()

response = self._swell._session.get(
url=f'{self._swell._base_url}/{self.endpoint}', params=params)
url=f'{self._swell._base_url}/{self.endpoint}', json=params)

return handle_requests_response(self._swell, response)

Expand All @@ -71,7 +71,7 @@ def get(self, id: str, params: Optional[dict] = None) -> dict:
self.check_limit()

response = self._swell._session.get(
url=f'{self._swell._base_url}/{self.endpoint}/{id}', params=params)
url=f'{self._swell._base_url}/{self.endpoint}/{id}', json=params)

return handle_requests_response(self._swell, response)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from dotenv import load_dotenv
import pytest
from api import Swell
from swellpy import Swell

load_dotenv()

Expand Down