Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 2dcd85c

Browse files
authored
v3.0.0 - complete overhaul for v2 API (#5)
* v3.0.0 - complete overhaul for v2 API * Mocks email/api_key for tests * Bumps version in setup.py * Move cassette directory * Pin dependencies * fix: updates tests * docs: correct examples * Update CHANGELOG date
1 parent 5bb772a commit 2dcd85c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1544
-234
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[flake8]
2-
max-line-length=100
2+
max-line-length=120

.github/workflows/build.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,27 @@ jobs:
1313
with:
1414
python-version: 3.9
1515
- name: Install Dependencies
16-
run: pip install -e ."[dev]"
16+
run: make install
1717
- name: Run linting
18-
run: |
19-
flake8 tuneuptechnology/*.py
20-
flake8 examples/*.py
18+
run: make lint
19+
test:
20+
runs-on: ubuntu-latest
21+
strategy:
22+
matrix:
23+
pythonversion: ["3.6", "3.7", "3.8", "3.9"]
24+
steps:
25+
- name: Checkout Repository
26+
uses: actions/checkout@v2
27+
- name: Set up Python
28+
uses: actions/setup-python@v2
29+
with:
30+
python-version: ${{ matrix.pythonversion }}
31+
- name: Install Dependencies
32+
run: make install
33+
- name: Run tests
34+
run: make coverage
35+
- name: Coveralls
36+
if: github.ref == 'refs/heads/main'
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
run: venv/bin/coveralls --service=github

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v2
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.9
18+
- name: Install pypa/build
19+
run: >-
20+
python -m
21+
pip install
22+
build
23+
--user
24+
- name: Build a binary wheel and a source tarball
25+
run: >-
26+
python -m
27+
build
28+
--sdist
29+
--wheel
30+
--outdir dist/
31+
.
32+
- name: Publish to PyPI
33+
uses: pypa/gh-action-pypi-publish@master
34+
with:
35+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ __pycache__
33
dist
44
build
55
*.egg-info
6+
venv
7+
htmlcov
8+
.coverage

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# CHANGELOG
22

3+
## v3.0.0 (2021-06-21)
4+
5+
* Updates entire library to be compliant with the new `v2` API (endpoints, HTTP methods, etc)
6+
* Build requests via a `Client` now providing your email and api_key
7+
* Added optional `base_url` and `timeout` options to client
8+
* Module names are now plural
9+
* The Client now checks if an email and api_key is provided and raises an error if not
10+
* Removed `utils` module (pretty print)
11+
* Added unit tests (closes #1)
12+
313
## v2.2.0 (2021-02-20)
414

515
* Adds timeout on HTTP requests

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
VIRTUALENV := python3 -m venv
2+
3+
## help - Display help about make targets for this Makefile
4+
help:
5+
@cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t
6+
7+
## venv - Install the virtual environment
8+
venv:
9+
$(VIRTUALENV) ~/.venv/tuneuptechnology/
10+
ln -snf ~/.venv/tuneuptechnology/ venv
11+
venv/bin/pip install -e ."[dev]"
12+
13+
## install - Install the project locally
14+
install: | venv
15+
16+
## run - Runs the flask server
17+
run:
18+
venv/bin/python tuneuptechnology/app.py
19+
20+
## clean - Remove the virtual environment and clear out .pyc files
21+
clean:
22+
rm -rf ~/.venv/tuneuptechnology/ venv
23+
find . -name '*.pyc' -delete
24+
rm -rf dist
25+
rm -rf build
26+
rm -rf *.egg-info
27+
28+
## lint - Lint the project
29+
lint:
30+
venv/bin/flake8 tuneuptechnology/*.py
31+
venv/bin/flake8 test/unit/*.py
32+
33+
## test - Test the project
34+
test:
35+
venv/bin/pytest
36+
37+
## coverage - Test the project and generate an HTML coverage report
38+
coverage:
39+
venv/bin/pytest --cov=tuneuptechnology --cov-branch --cov-report=html --cov-report=term-missing
40+
41+
.PHONY: help install run clean lint test coverage

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
The Python client library for the Tuneup Technology App.
44

55
[![Build Status](https://github.com/tuneuptechnology/tuneuptechnology-python/workflows/build/badge.svg)](https://github.com/tuneuptechnology/tuneuptechnology-python/actions)
6+
[![Coverage Status](https://coveralls.io/repos/github/tuneuptechnology/tuneuptechnology-python/badge.svg?branch=main)](https://coveralls.io/github/tuneuptechnology/tuneuptechnology-python?branch=main)
7+
[![PyPi](https://img.shields.io/pypi/v/tuneuptechnology-python)](https://pypi.org/project/tuneuptechnology-python)
68
[![Licence](https://img.shields.io/github/license/tuneuptechnology/tuneuptechnology-python)](LICENSE)
79

810
This library allows you to interact with the customers, tickets, inventory, and locations objects without needing to do the hard work of binding your calls and data to endpoints. Simply call an action such as `Customer.create` and pass some data and let the library do the rest.
911

1012
## Install
1113

1214
```bash
15+
# Install client library
1316
pip3 install tuneuptechnology
17+
18+
# Install locally
19+
make install
20+
21+
# Get Makefile help
22+
make help
1423
```
1524

1625
## Example
@@ -23,35 +32,48 @@ import tuneuptechnology
2332
API_EMAIL = os.getenv('API_EMAIL')
2433
API_KEY = os.getenv('API_KEY')
2534

26-
customer = tuneuptechnology.Customer.create(
27-
data={
28-
'auth': API_EMAIL,
29-
'api_key': API_KEY,
35+
client = tuneuptechnology.Client(API_EMAIL, API_KEY)
36+
37+
customer = client.Customers.create(
38+
{
3039
'firstname': 'Jake',
3140
'lastname': 'Peralta',
3241
'email': 'jake@example.com',
3342
'phone': '8015551234',
3443
'user_id': 1,
3544
'notes': 'Believes he is a good detective.',
36-
'location_id': 1,
45+
'location_id': 2,
3746
}
3847
)
3948

40-
tuneuptechnology.Util.pretty_print(customer)
49+
print(customer)
4150
```
4251

4352
Other examples can be found in the `/examples` directory. Alter according to your needs.
4453

4554
## Usage
4655

4756
```bash
48-
API_EMAIL=email@example.com API_KEY=123... python3 create_customer.py
57+
API_EMAIL=email@example.com API_KEY=123... venv/bin/python create_customer.py
4958
```
5059

5160
## Documentation
5261

5362
Up-to-date API documentation can be [found here](https://app.tuneuptechnology.com/docs/api).
5463

64+
## Development
65+
66+
```bash
67+
# Lint the project
68+
make lint
69+
70+
# Run tests
71+
API_EMAIL=email@example.com API_KEY=123... make test
72+
73+
# Run test coverage
74+
API_EMAIL=email@example.com API_KEY=123... make coverage
75+
```
76+
5577
## Releasing
5678

5779
As a separate PR from the feature/bug PR:

examples/create_customer.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
import tuneuptechnology
44

5-
API_EMAIL = os.getenv('API_EMAIL')
6-
API_KEY = os.getenv('API_KEY')
5+
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))
76

8-
customer = tuneuptechnology.Customer.create(
9-
data={
10-
'auth': API_EMAIL,
11-
'api_key': API_KEY,
7+
customer = client.Customers.create(
8+
{
129
'firstname': 'Jake',
1310
'lastname': 'Peralta',
1411
'email': 'jake@example.com',
1512
'phone': '8015551234',
1613
'user_id': 1,
1714
'notes': 'Believes he is a good detective.',
18-
'location_id': 1,
15+
'location_id': 2,
1916
}
2017
)
2118

22-
tuneuptechnology.Util.pretty_print(customer)
19+
print(customer)

examples/delete_customer.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@
22

33
import tuneuptechnology
44

5-
API_EMAIL = os.getenv('API_EMAIL')
6-
API_KEY = os.getenv('API_KEY')
5+
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))
76

8-
# Retrieve a single customer record
9-
customer = tuneuptechnology.Customer.delete(
10-
data={
11-
'auth': API_EMAIL,
12-
'api_key': API_KEY,
13-
'id': 23 # the ID of the customer you are deleting
14-
}
15-
)
7+
customer = client.Customers.delete(id=23)
168

17-
tuneuptechnology.Util.pretty_print(customer)
9+
print(customer)

examples/retrieve_customer.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22

33
import tuneuptechnology
44

5-
API_EMAIL = os.getenv('API_EMAIL')
6-
API_KEY = os.getenv('API_KEY')
5+
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))
76

8-
customer = tuneuptechnology.Customer.retrieve(
9-
data={
10-
'auth': API_EMAIL,
11-
'api_key': API_KEY,
12-
'id': 23 # the ID of the customer you are retrieving
13-
}
14-
)
7+
customer = client.Customers.retrieve(id=23)
158

16-
tuneuptechnology.Util.pretty_print(customer)
9+
print(customer)

examples/retrieve_customers.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22

33
import tuneuptechnology
44

5-
API_EMAIL = os.getenv('API_EMAIL')
6-
API_KEY = os.getenv('API_KEY')
5+
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))
76

8-
customers = tuneuptechnology.Customer.all(
9-
data={
10-
'auth': API_EMAIL,
11-
'api_key': API_KEY,
12-
}
13-
)
7+
customers = client.Customers.all()
148

15-
tuneuptechnology.Util.pretty_print(customers)
9+
print(customers)

examples/update_customer.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@
22

33
import tuneuptechnology
44

5-
API_EMAIL = os.getenv('API_EMAIL')
6-
API_KEY = os.getenv('API_KEY')
5+
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))
76

8-
customer = tuneuptechnology.Customer.update(
7+
customer = client.Customers.update(
8+
id=23,
99
data={
10-
'auth': API_EMAIL,
11-
'api_key': API_KEY,
12-
'id': 23, # the ID of the customer you are updating
1310
'firstname': 'Jake',
1411
'lastname': 'Peralta',
1512
'email': 'jake@example.com',
1613
'phone': '8015551234',
1714
'user_id': 1,
1815
'notes': 'Believes he is a good detective.',
19-
'location_id': 1,
16+
'location_id': 2,
2017
}
2118
)
2219

23-
tuneuptechnology.Util.pretty_print(customer)
20+
print(customer)

setup.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import setuptools
22

3-
with open("README.md", "r") as fh:
3+
with open('README.md', 'r') as fh:
44
long_description = fh.read()
55

6-
REQUIRES = [
7-
'requests >= 1.0.0',
6+
REQUIREMENTS = [
7+
'requests == 2.*',
8+
]
9+
10+
DEV_REQUIREMENTS = [
11+
'coveralls == 3.*',
12+
'flake8',
13+
'mock == 4.*',
14+
'pytest == 6.*',
15+
'pytest-cov == 2.*',
16+
'vcrpy == 4.*',
817
]
918

1019
setuptools.setup(
1120
name='tuneuptechnology',
12-
version='2.2.0',
21+
version='3.0.0',
1322
description='The Python client library for the Tuneup Technology App.',
1423
long_description=long_description,
1524
long_description_content_type="text/markdown",
@@ -23,11 +32,9 @@
2332
"License :: OSI Approved :: MIT License",
2433
"Operating System :: OS Independent",
2534
],
26-
install_requires=REQUIRES,
35+
install_requires=REQUIREMENTS,
2736
extras_require={
28-
'dev': [
29-
'flake8 >= 3.8.0',
30-
]
37+
'dev': DEV_REQUIREMENTS
3138
},
3239
python_requires='>=3.6',
3340
)

test/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)