From 5a3c32b1edf1892001c17b7b09511758b9cef204 Mon Sep 17 00:00:00 2001 From: "Chris Davis (a)" Date: Tue, 26 Dec 2023 20:27:10 -0500 Subject: [PATCH] added additional files --- .github/workflows/release.yml | 26 ++++++ .github/workflows/test.yml | 30 +++++++ .gitignore | 138 ++++++++++++++++++++++++++++++ LICENSE | 21 +++++ MANIFEST.in | 4 + README.md | 33 +++++++ pyproject.toml | 3 + setup.cfg | 3 + setup.py | 53 ++++++++++++ src/__init__.py | 0 src/client.py | 43 ++++++++++ src/clutch_api_python.py | 34 ++++++++ src/clutch_api_python/cards.py | 3 + src/clutch_api_python/checkout.py | 3 + src/clutch_api_python/search.py | 3 + tests/__init__.py | 0 tox.ini | 13 +++ 17 files changed, 410 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 src/__init__.py create mode 100644 src/client.py create mode 100644 src/clutch_api_python.py create mode 100644 src/clutch_api_python/cards.py create mode 100644 src/clutch_api_python/checkout.py create mode 100644 src/clutch_api_python/search.py create mode 100644 tests/__init__.py create mode 100644 tox.ini diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..91100b4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Release + +on: + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + python setup.py sdist bdist_wheel + twine upload --repository pypi dist/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7be9344 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Test + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python: [3.6, 3.7, 3.8, 3.9] + + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install Tox and any other packages + run: pip install tox + - name: Run Tox + # Run tox using the version of Python in `PATH` + run: tox -e py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a81c8ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,138 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..373e60f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Tom Chen (tomchen.org) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..b1dbe7e --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include pyproject.toml +include *.md +include LICENSE +recursive-include tests test*.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..d7fed88 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# ClutchPy + + +Link to API Documentation: https://apidocs.clutch.com/ + +## Installation +``` +$ pip install clutchpy +``` + +Note: This python module has not been publish to the PyPI (Python Package Index) yet so this installation command will not work yet. + +## Usage +```python +import clutchpy + +# initialize the clutch api client +client = ClutchAPI( + brand='YOUR BRAND', + location='YOUR LOCATION', + terminal='YOUR TERMINAL', + key='YOUR PRIVATE KEY', + secret='YOUR PRIVATE SECRET', + timeout='YOUR DESIRED DEFAULT TIMEOUT', + env='stage' # valid environment values are 'stage' and 'prod' +) + +# define search parameters +params = {} + +# send a search request +client.search(params) +``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ead8162 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=46.4.0", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..040b134 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[metadata] +version = attr: examplepy.__version__ +license_files = LICENSE diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ebe7074 --- /dev/null +++ b/setup.py @@ -0,0 +1,53 @@ +import setuptools + +with open('README.md', 'r', encoding='utf-8') as fh: + long_description = fh.read() + +setuptools.setup( + name='example_pypi_package', + author='Tom Chen', + author_email='tomchen.org@gmail.com', + description='Example PyPI (Python Package Index) Package', + keywords='example, pypi, package', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://github.com/tomchen/example_pypi_package', + project_urls={ + 'Documentation': 'https://github.com/tomchen/example_pypi_package', + 'Bug Reports': + 'https://github.com/tomchen/example_pypi_package/issues', + 'Source Code': 'https://github.com/tomchen/example_pypi_package', + # 'Funding': '', + # 'Say Thanks!': '', + }, + package_dir={'': 'src'}, + packages=setuptools.find_packages(where='src'), + classifiers=[ + # see https://pypi.org/classifiers/ + 'Development Status :: 5 - Production/Stable', + + 'Intended Audience :: Developers', + 'Topic :: Software Development :: Build Tools', + + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3 :: Only', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + ], + python_requires='>=3.6', + # install_requires=['Pillow'], + extras_require={ + 'dev': ['check-manifest'], + # 'test': ['coverage'], + }, + # entry_points={ + # 'console_scripts': [ # This can provide executable scripts + # 'run=examplepy:main', + # You can execute `run` in bash to run `main()` in src/examplepy/__init__.py + # ], + # }, +) diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/client.py b/src/client.py new file mode 100644 index 0000000..60152a5 --- /dev/null +++ b/src/client.py @@ -0,0 +1,43 @@ +import requests + +class Client: + def __init__(self, brand, location, terminal, key, secret, timeout, env): + self.key = key + self.secret = secret + self.location = location + self.terminal = terminal + self.brand = brand + self.headers = { + 'brand': self.brand, + 'location': self.location, + 'terminal': self.terminal + } + self.timeout = timeout + + try: + if env == 'stage': + self.env = '-stage' + elif env == 'prod': + self.env = '' + except TypeError: + print(f'Value {env} is not a valid environment. Only valid values are prod and stage.') + + def get(self, url, timeout, params={}, headers={}): + return requests.get(url=url, params=params, headers=headers, timeout=timeout) + + def post(self, url, timeout, params={}, headers={}): + return requests.post(url=url, params=params, headers=headers, timeout=timeout) + + def patch(self, url, timeout, params={}, headers={}): + return requests.patch(url=url, params=params, headers=headers, timeout=timeout) + + def put(self, url, timeout, params={}, headers={}): + return requests.put(url=url, params=params, headers=headers, timeout=timeout) + + def delete(self, url, timeout, headers={}): + return requests.delete(url=url, headers=headers, timeout=timeout) + + def request(self, method, path, params={}, headers={}): + url = f'https://api{self.env}.clutch.com/merchant' + path + method = getattr(self, method) + return method(url, params=params, headers=headers, timeout=self.timeout) diff --git a/src/clutch_api_python.py b/src/clutch_api_python.py new file mode 100644 index 0000000..d9bef44 --- /dev/null +++ b/src/clutch_api_python.py @@ -0,0 +1,34 @@ +from client import Client +from clutch_api_python.cards import Cards +from clutch_api_python.checkout import Checkout +from clutch_api_python.search import Search + +class ClutchAPI(Client): + def __init__(self, brand, location, terminal, key, secret, timeout, env): + self.brand = brand + self.location = location + self.terminal = terminal + self.key = key + self.secret = secret + self.headers = { + 'brand': self.brand, + 'location': self.location, + 'terminal': self.terminal + } + self.timeout = timeout + self.env = env # stage or prod + + self.client = Client( + self.host, + self.brand, + self.location, + self.terminal, + self.key, + self.secret, + self.timeout, + self.env + ) + + self.cards = Cards(self.client) + self.checkout = Checkout(self.client) + self.search = Search(self.client) diff --git a/src/clutch_api_python/cards.py b/src/clutch_api_python/cards.py new file mode 100644 index 0000000..9f54bf9 --- /dev/null +++ b/src/clutch_api_python/cards.py @@ -0,0 +1,3 @@ +class Cards: + def __init__(self, client): + self.client = client diff --git a/src/clutch_api_python/checkout.py b/src/clutch_api_python/checkout.py new file mode 100644 index 0000000..d532226 --- /dev/null +++ b/src/clutch_api_python/checkout.py @@ -0,0 +1,3 @@ +class Checkout: + def __init__(self, client): + self.client = client diff --git a/src/clutch_api_python/search.py b/src/clutch_api_python/search.py new file mode 100644 index 0000000..01a476e --- /dev/null +++ b/src/clutch_api_python/search.py @@ -0,0 +1,3 @@ +class Search: + def __init__(self, client): + self.client = client diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..1174245 --- /dev/null +++ b/tox.ini @@ -0,0 +1,13 @@ +[tox] +envlist = py{36,37,38,39} +minversion = 3.3.0 +isolated_build = true + +[testenv] +deps = + check-manifest >= 0.42 + pytest +commands = + check-manifest --ignore 'tox.ini,tests/**,.editorconfig,vscode.env,.vscode/**' + python setup.py check -m -s + pytest tests {posargs}