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

Commit

Permalink
v3.0.0 - complete overhaul for v2 API (#5)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Justintime50 committed Jun 22, 2021
1 parent 5bb772a commit 2dcd85c
Show file tree
Hide file tree
Showing 51 changed files with 1,544 additions and 234 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[flake8]
max-line-length=100
max-line-length=120
27 changes: 23 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,27 @@ jobs:
with:
python-version: 3.9
- name: Install Dependencies
run: pip install -e ."[dev]"
run: make install
- name: Run linting
run: |
flake8 tuneuptechnology/*.py
flake8 examples/*.py
run: make lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
pythonversion: ["3.6", "3.7", "3.8", "3.9"]
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.pythonversion }}
- name: Install Dependencies
run: make install
- name: Run tests
run: make coverage
- name: Coveralls
if: github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: venv/bin/coveralls --service=github
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: release

on:
push:
tags:
- "*"

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ __pycache__
dist
build
*.egg-info
venv
htmlcov
.coverage
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## v3.0.0 (2021-06-21)

* Updates entire library to be compliant with the new `v2` API (endpoints, HTTP methods, etc)
* Build requests via a `Client` now providing your email and api_key
* Added optional `base_url` and `timeout` options to client
* Module names are now plural
* The Client now checks if an email and api_key is provided and raises an error if not
* Removed `utils` module (pretty print)
* Added unit tests (closes #1)

## v2.2.0 (2021-02-20)

* Adds timeout on HTTP requests
Expand Down
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
VIRTUALENV := python3 -m venv

## help - Display help about make targets for this Makefile
help:
@cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t

## venv - Install the virtual environment
venv:
$(VIRTUALENV) ~/.venv/tuneuptechnology/
ln -snf ~/.venv/tuneuptechnology/ venv
venv/bin/pip install -e ."[dev]"

## install - Install the project locally
install: | venv

## run - Runs the flask server
run:
venv/bin/python tuneuptechnology/app.py

## clean - Remove the virtual environment and clear out .pyc files
clean:
rm -rf ~/.venv/tuneuptechnology/ venv
find . -name '*.pyc' -delete
rm -rf dist
rm -rf build
rm -rf *.egg-info

## lint - Lint the project
lint:
venv/bin/flake8 tuneuptechnology/*.py
venv/bin/flake8 test/unit/*.py

## test - Test the project
test:
venv/bin/pytest

## coverage - Test the project and generate an HTML coverage report
coverage:
venv/bin/pytest --cov=tuneuptechnology --cov-branch --cov-report=html --cov-report=term-missing

.PHONY: help install run clean lint test coverage
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
The Python client library for the Tuneup Technology App.

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

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.

## Install

```bash
# Install client library
pip3 install tuneuptechnology

# Install locally
make install

# Get Makefile help
make help
```

## Example
Expand All @@ -23,35 +32,48 @@ import tuneuptechnology
API_EMAIL = os.getenv('API_EMAIL')
API_KEY = os.getenv('API_KEY')

customer = tuneuptechnology.Customer.create(
data={
'auth': API_EMAIL,
'api_key': API_KEY,
client = tuneuptechnology.Client(API_EMAIL, API_KEY)

customer = client.Customers.create(
{
'firstname': 'Jake',
'lastname': 'Peralta',
'email': 'jake@example.com',
'phone': '8015551234',
'user_id': 1,
'notes': 'Believes he is a good detective.',
'location_id': 1,
'location_id': 2,
}
)

tuneuptechnology.Util.pretty_print(customer)
print(customer)
```

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

## Usage

```bash
API_EMAIL=email@example.com API_KEY=123... python3 create_customer.py
API_EMAIL=email@example.com API_KEY=123... venv/bin/python create_customer.py
```

## Documentation

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

## Development

```bash
# Lint the project
make lint

# Run tests
API_EMAIL=email@example.com API_KEY=123... make test

# Run test coverage
API_EMAIL=email@example.com API_KEY=123... make coverage
```

## Releasing

As a separate PR from the feature/bug PR:
Expand Down
13 changes: 5 additions & 8 deletions examples/create_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import tuneuptechnology

API_EMAIL = os.getenv('API_EMAIL')
API_KEY = os.getenv('API_KEY')
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))

customer = tuneuptechnology.Customer.create(
data={
'auth': API_EMAIL,
'api_key': API_KEY,
customer = client.Customers.create(
{
'firstname': 'Jake',
'lastname': 'Peralta',
'email': 'jake@example.com',
'phone': '8015551234',
'user_id': 1,
'notes': 'Believes he is a good detective.',
'location_id': 1,
'location_id': 2,
}
)

tuneuptechnology.Util.pretty_print(customer)
print(customer)
14 changes: 3 additions & 11 deletions examples/delete_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

import tuneuptechnology

API_EMAIL = os.getenv('API_EMAIL')
API_KEY = os.getenv('API_KEY')
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))

# Retrieve a single customer record
customer = tuneuptechnology.Customer.delete(
data={
'auth': API_EMAIL,
'api_key': API_KEY,
'id': 23 # the ID of the customer you are deleting
}
)
customer = client.Customers.delete(id=23)

tuneuptechnology.Util.pretty_print(customer)
print(customer)
13 changes: 3 additions & 10 deletions examples/retrieve_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

import tuneuptechnology

API_EMAIL = os.getenv('API_EMAIL')
API_KEY = os.getenv('API_KEY')
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))

customer = tuneuptechnology.Customer.retrieve(
data={
'auth': API_EMAIL,
'api_key': API_KEY,
'id': 23 # the ID of the customer you are retrieving
}
)
customer = client.Customers.retrieve(id=23)

tuneuptechnology.Util.pretty_print(customer)
print(customer)
12 changes: 3 additions & 9 deletions examples/retrieve_customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

import tuneuptechnology

API_EMAIL = os.getenv('API_EMAIL')
API_KEY = os.getenv('API_KEY')
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))

customers = tuneuptechnology.Customer.all(
data={
'auth': API_EMAIL,
'api_key': API_KEY,
}
)
customers = client.Customers.all()

tuneuptechnology.Util.pretty_print(customers)
print(customers)
13 changes: 5 additions & 8 deletions examples/update_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

import tuneuptechnology

API_EMAIL = os.getenv('API_EMAIL')
API_KEY = os.getenv('API_KEY')
client = tuneuptechnology.Client(os.getenv('API_EMAIL'), os.getenv('API_KEY'))

customer = tuneuptechnology.Customer.update(
customer = client.Customers.update(
id=23,
data={
'auth': API_EMAIL,
'api_key': API_KEY,
'id': 23, # the ID of the customer you are updating
'firstname': 'Jake',
'lastname': 'Peralta',
'email': 'jake@example.com',
'phone': '8015551234',
'user_id': 1,
'notes': 'Believes he is a good detective.',
'location_id': 1,
'location_id': 2,
}
)

tuneuptechnology.Util.pretty_print(customer)
print(customer)
23 changes: 15 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import setuptools

with open("README.md", "r") as fh:
with open('README.md', 'r') as fh:
long_description = fh.read()

REQUIRES = [
'requests >= 1.0.0',
REQUIREMENTS = [
'requests == 2.*',
]

DEV_REQUIREMENTS = [
'coveralls == 3.*',
'flake8',
'mock == 4.*',
'pytest == 6.*',
'pytest-cov == 2.*',
'vcrpy == 4.*',
]

setuptools.setup(
name='tuneuptechnology',
version='2.2.0',
version='3.0.0',
description='The Python client library for the Tuneup Technology App.',
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -23,11 +32,9 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
install_requires=REQUIRES,
install_requires=REQUIREMENTS,
extras_require={
'dev': [
'flake8 >= 3.8.0',
]
'dev': DEV_REQUIREMENTS
},
python_requires='>=3.6',
)
Empty file added test/__init__.py
Empty file.

0 comments on commit 2dcd85c

Please sign in to comment.