Skip to content

Commit 2352f70

Browse files
authored
Merge pull request #4 from paywithextend/github-actions-and-readme
add build workflow / update readme
2 parents ff833dd + a0c17b6 commit 2352f70

File tree

11 files changed

+126
-30
lines changed

11 files changed

+126
-30
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Release Stage Build
2+
3+
on:
4+
push:
5+
branches:
6+
- development
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: 3.11
23+
24+
- name: Install dependencies
25+
run: sudo apt-get install make
26+
27+
- name: Create virtual environment
28+
run: make venv
29+
30+
- name: Build package
31+
run: |
32+
set -x
33+
source venv/bin/activate
34+
rm -rf build dist *.egg-info
35+
make build ENV=stage
36+
37+
- name: Extract Version from pyproject.toml
38+
id: get_version
39+
run: |
40+
# Extract the version assuming a line like: version = "0.1.0"
41+
VERSION=$(grep -Po '^version\s*=\s*"\K[^"]+' pyproject.toml)
42+
echo "Version extracted: $VERSION"
43+
echo "version=$VERSION" >> $GITHUB_OUTPUT
44+
45+
- name: Create GitHub Release
46+
id: create_release
47+
uses: actions/create-release@v1
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
with:
51+
tag_name: v${{ steps.get_version.outputs.version }}
52+
release_name: Release ${{ steps.get_version.outputs.version }}
53+
draft: false
54+
prerelease: false
55+
56+
- name: Upload Wheel Asset
57+
uses: actions/upload-release-asset@v1
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
with:
61+
upload_url: ${{ steps.create_release.outputs.upload_url }}
62+
asset_path: ./dist/extend-${{ steps.get_version.outputs.version }}-py3-none-any.whl
63+
asset_name: extend-${{ steps.get_version.outputs.version }}-py3-none-any.whl
64+
asset_content_type: application/octet-stream

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export ENV ?= stage
2+
VENV_NAME ?= venv
3+
PIP ?= pip
4+
PYTHON ?= python3.11
5+
6+
venv: $(VENV_NAME)/bin/activate
7+
8+
$(VENV_NAME)/bin/activate: pyproject.toml
9+
@test -d $(VENV_NAME) || $(PYTHON) -m venv $(VENV_NAME)
10+
$(VENV_NAME)/bin/python -m pip install -e .
11+
@touch $(VENV_NAME)/bin/activate
12+
13+
test: venv
14+
$(VENV_NAME)/bin/python -m unittest discover tests
15+
16+
build: venv
17+
cp LICENSE LICENSE.bak
18+
$(VENV_NAME)/bin/python -m build
19+
rm LICENSE.bak

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ pip install -e .
3838

3939
```python
4040
import asyncio
41-
from extend import ExtendAPI
41+
from extend import ExtendClient
4242

4343

4444
async def main():
4545
# Initialize the client
46-
client = ExtendAPI(
46+
client = ExtendClient(
4747
api_key="your-api-key",
4848
api_secret="your-api-secret"
4949
)
5050

5151
# Get all virtual cards
52-
cards = await client.get_virtual_cards()
53-
print("Virtual Cards:", cards)
52+
response = await client.virtual_cards.get_virtual_cards()
53+
print("Virtual Cards:", response["virtualCards"])
5454

5555
# Get all transactions
56-
transactions = await client.get_transactions()
57-
print("Transactions:", transactions)
56+
response = await client.transactions.get_transactions()
57+
print("Transactions:", response["transactions"])
5858

5959

6060
# Run the async function

extend/client.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import httpx
55

6+
from .config import API_HOST, API_VERSION
7+
68

79
class APIClient:
810
"""Client for interacting with the Extend API.
@@ -17,8 +19,6 @@ class APIClient:
1719
cards = await client.get_virtual_cards()
1820
```
1921
"""
20-
BASE_URL = "https://apiv2.paywithextend.com"
21-
API_VERSION = "application/vnd.paywithextend.v2021-03-12+json"
2222

2323
_shared_instance: Optional["APIClient"] = None
2424

@@ -33,7 +33,7 @@ def __init__(self, api_key: str, api_secret: str):
3333
self.headers = {
3434
"x-extend-api-key": api_key,
3535
"Authorization": f"Basic {auth_value}",
36-
"Accept": self.API_VERSION
36+
"Accept": API_VERSION
3737
}
3838

3939
@classmethod
@@ -70,7 +70,8 @@ async def get(self, url: str, params: Optional[Dict] = None) -> Any:
7070
response = await client.get(
7171
self.build_full_url(url),
7272
headers=self.headers,
73-
params=params
73+
params=params,
74+
timeout=httpx.Timeout(30)
7475
)
7576
response.raise_for_status()
7677
return response.json()
@@ -79,7 +80,7 @@ async def post(self, url: str, data: Dict) -> Any:
7980
"""Make a POST request to the Extend API.
8081
8182
Args:
82-
url (str): The API endpoint path (e.g., "virtualcards")
83+
url (str): The API endpoint path (e.g., "/virtualcards")
8384
data (Dict): The JSON payload to send in the request body
8485
8586
Returns:
@@ -93,7 +94,8 @@ async def post(self, url: str, data: Dict) -> Any:
9394
response = await client.post(
9495
self.build_full_url(url),
9596
headers=self.headers,
96-
json=data
97+
json=data,
98+
timeout=httpx.Timeout(30)
9799
)
98100
response.raise_for_status()
99101
return response.json()
@@ -102,7 +104,7 @@ async def put(self, url: str, data: Dict) -> Any:
102104
"""Make a PUT request to the Extend API.
103105
104106
Args:
105-
url (str): The API endpoint path (e.g., "virtualcards/{card_id}")
107+
url (str): The API endpoint path (e.g., "/virtualcards/{card_id}")
106108
data (Dict): The JSON payload to send in the request body
107109
108110
Returns:
@@ -116,10 +118,11 @@ async def put(self, url: str, data: Dict) -> Any:
116118
response = await client.put(
117119
self.build_full_url(url),
118120
headers=self.headers,
119-
json=data
121+
json=data,
122+
timeout=httpx.Timeout(30)
120123
)
121124
response.raise_for_status()
122125
return response.json()
123126

124127
def build_full_url(self, url: Optional[str]):
125-
return f"{self.BASE_URL}{url or ''}"
128+
return f"https://{API_HOST}{url or ''}"

extend/config/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
3+
from dotenv import load_dotenv
4+
5+
load_dotenv()
6+
7+
env = os.getenv("ENV", "dev")
8+
9+
if env == "stage":
10+
from .config_stage import API_HOST, API_VERSION
11+
elif env == "prod":
12+
from .config_prod import API_HOST, API_VERSION
13+
else:
14+
from .config_stage import API_HOST, API_VERSION
15+
16+
__all__ = [
17+
"API_HOST",
18+
"API_VERSION"
19+
]

extend/config/config_prod.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
API_HOST = "apiv2.paywithextend.com"
2+
API_VERSION = "application/vnd.paywithextend.v2021-03-12+json"

extend/config/config_stage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
API_HOST = "apiv2-stage.paywithextend.com"
2+
API_VERSION = "application/vnd.paywithextend.v2021-03-12+json"

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ classifiers = [
1616
]
1717
requires-python = ">=3.8"
1818
dependencies = [
19+
"build",
1920
"httpx>=0.24.0",
2021
"typing-extensions>=4.0.0",
2122
"python-dotenv==1.0.1",
@@ -41,7 +42,7 @@ dev = [
4142
"jupyter>=1.0.0",
4243
"ipykernel>=6.0.0",
4344
"notebook>=7.0.0",
44-
"pytest-mock==3.14.0"
45+
"pytest-mock==3.14.0",
4546
]
4647

4748
[tool.pytest.ini_options]

requirements-dev.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)