From 1e662dc3b5db84b4fb2549622f75fee12a6e4215 Mon Sep 17 00:00:00 2001 From: "Chris Davis (a)" Date: Tue, 26 Dec 2023 20:27:10 -0500 Subject: [PATCH] added endpoints and updated readme --- .github/workflows/release.yml | 26 +++++ .github/workflows/test.yml | 30 ++++++ .gitignore | 138 +++++++++++++++++++++++++ LICENSE | 21 ++++ MANIFEST.in | 4 + README.md | 69 +++++++++++++ pyproject.toml | 3 + setup.cfg | 3 + setup.py | 53 ++++++++++ src/__init__.py | 0 src/client.py | 44 ++++++++ src/clutch_api_python.py | 42 ++++++++ src/clutch_api_python/campaigns.py | 9 ++ src/clutch_api_python/cards.py | 21 ++++ src/clutch_api_python/coupons.py | 9 ++ src/clutch_api_python/events.py | 9 ++ src/clutch_api_python/requests.py | 9 ++ src/clutch_api_python/subscriptions.py | 9 ++ src/clutch_api_python/transactions.py | 18 ++++ tests/__init__.py | 0 tox.ini | 13 +++ 21 files changed, 530 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/campaigns.py create mode 100644 src/clutch_api_python/cards.py create mode 100644 src/clutch_api_python/coupons.py create mode 100644 src/clutch_api_python/events.py create mode 100644 src/clutch_api_python/requests.py create mode 100644 src/clutch_api_python/subscriptions.py create mode 100644 src/clutch_api_python/transactions.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..3164620 --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# ClutchPy + +## Endpoint Grouping/Scope +Link to API Documentation: https://apidocs.clutch.com/ + +``` +Card Operations: +- allocateChildCard +- allocate +- reactivate +- updateAccount +- updateBalance + +Transaction and History: +- cardHistory +- voidTransaction +- returnMerchandise +- checkout +- transfer + +Coupon Operations: +- allocateCoupon +- couponDetails + +Event Handling: +- createEventType +- listEventTypes + +Request and Lookup: +- listRequests +- requestLookup + +Value and Subscription Lists: +- listValueTypes +- listSubscriptionLists + +Template and Campaign Handling: +- renderTemplate +- triggerCustomCampaigns +``` + +## 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.cards.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..d2441ae --- /dev/null +++ b/src/client.py @@ -0,0 +1,44 @@ +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 + + if env == 'prod': + self.env = '' + else: + self.env = '-stage' + + # Note: All endpoints accept HTTP POST requests only. In the future if other + # method request types are supported, the client request methods below can be uncommented + + # def get(self, url, params={}, headers={}): + # return requests.get(url=url, params=params, headers=headers, timeout=self.timeout) + + # def patch(self, url, params={}, headers={}): + # return requests.patch(url=url, params=params, headers=headers, timeout=self.timeout) + + # def put(self, url, params={}, headers={}): + # return requests.put(url=url, params=params, headers=headers, timeout=self.timeout) + + # def delete(self, url, headers={}): + # return requests.delete(url=url, headers=headers, timeout=self.timeout) + + def post(self, url, params={}, headers={}): + return requests.post(url=url, params=params, headers=headers, timeout=self.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..36f3a83 --- /dev/null +++ b/src/clutch_api_python.py @@ -0,0 +1,42 @@ +from client import Client +from clutch_api_python.campaigns import Campaigns +from clutch_api_python.cards import Cards +from clutch_api_python.coupons import Coupons +from clutch_api_python.events import Events +from clutch_api_python.requests import Requests +from clutch_api_python.subscriptions import Subscriptions +from clutch_api_python.transactions import Transactions + +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.campaigns = Campaigns(self.client) + self.cards = Cards(self.client) + self.coupons = Coupons(self.client) + self.events = Events(self.client) + self.requests = Requests(self.client) + self.subscriptions = Subscriptions(self.client) + self.transactions = Transactions(self.client) diff --git a/src/clutch_api_python/campaigns.py b/src/clutch_api_python/campaigns.py new file mode 100644 index 0000000..585c5d6 --- /dev/null +++ b/src/clutch_api_python/campaigns.py @@ -0,0 +1,9 @@ +class Campaigns: + def __init__(self, client): + self.client = client + + def render_template(self, params={}, headers={}): + return self.client.request('post', '/renderTemplate', params=params, headers=headers) + + def trigger_custom_campaigns(self, params={}, headers={}): + return self.client.request('post', '/triggerCustomCampaigns', params=params, headers=headers) diff --git a/src/clutch_api_python/cards.py b/src/clutch_api_python/cards.py new file mode 100644 index 0000000..5e37fba --- /dev/null +++ b/src/clutch_api_python/cards.py @@ -0,0 +1,21 @@ +class Cards: + def __init__(self, client): + self.client = client + + def allocate_child_card(self, params={}, headers={}): + return self.client.request('post', '/allocateChildCard', params=params, headers=headers) + + def allocate_card(self, params={}, headers={}): + return self.client.request('post', '/allocate', params=params, headers=headers) + + def reactivate_card(self, params={}, headers={}): + return self.client.request('post', '/reactivate', params=params, headers=headers) + + def update_card_balance(self, params={}, headers={}): + return self.client.request('post', '/updateBalance', params=params, headers=headers) + + def update_card_account(self, params={}, headers={}): + return self.client.request('post', '/updateAccount', params=params, headers=headers) + +def search(self, params={}, headers={}): + return self.client.request('post', '/search', params=params, headers=headers) diff --git a/src/clutch_api_python/coupons.py b/src/clutch_api_python/coupons.py new file mode 100644 index 0000000..d62f53c --- /dev/null +++ b/src/clutch_api_python/coupons.py @@ -0,0 +1,9 @@ +class Coupons: + def __init__(self, client): + self.client = client + + def get_coupon_details(self, params={}, headers={}): + return self.client.request('post', '/couponDetails', params=params, headers=headers) + + def allocate_coupon(self, params={}, headers={}): + return self.client.request('post', '/allocateCoupon', params=params, headers=headers) diff --git a/src/clutch_api_python/events.py b/src/clutch_api_python/events.py new file mode 100644 index 0000000..9759b6b --- /dev/null +++ b/src/clutch_api_python/events.py @@ -0,0 +1,9 @@ +class Events: + def __init__(self, client): + self.client = client + + def create_event_type(self, params={}, headers={}): + return self.client.request('post', '/createEventType', params=params, headers=headers) + + def list_event_types(self, params={}, headers={}): + return self.client.request('post', '/listEventTypes', params=params, headers=headers) diff --git a/src/clutch_api_python/requests.py b/src/clutch_api_python/requests.py new file mode 100644 index 0000000..63b1cbe --- /dev/null +++ b/src/clutch_api_python/requests.py @@ -0,0 +1,9 @@ +class Requests: + def __init__(self, client): + self.client = client + + def list_requests(self, params={}, headers={}): + return self.client.request('post', '/listRequests', params=params, headers=headers) + + def request_lookup(self, params={}, headers={}): + return self.client.request('post', '/requestLookup', params=params, headers=headers) diff --git a/src/clutch_api_python/subscriptions.py b/src/clutch_api_python/subscriptions.py new file mode 100644 index 0000000..04a01be --- /dev/null +++ b/src/clutch_api_python/subscriptions.py @@ -0,0 +1,9 @@ +class Subscriptions: + def __init__(self, client): + self.client = client + + def list_value_types(self, params={}, headers={}): + return self.client.request('post', '/listValueTypes', params=params, headers=headers) + + def list_subscription_lists(self, params={}, headers={}): + return self.client.request('post', '/listSubscriptionLists', params=params, headers=headers) diff --git a/src/clutch_api_python/transactions.py b/src/clutch_api_python/transactions.py new file mode 100644 index 0000000..8c20a4e --- /dev/null +++ b/src/clutch_api_python/transactions.py @@ -0,0 +1,18 @@ +class Transactions: + def __init__(self, client): + self.client = client + + def void_transaction(self, params={}, headers={}): + return self.client.request('post', '/voidTransaction', params=params, headers=headers) + + def return_merchandise(self, params={}, headers={}): + return self.client.request('post', '/returnMerchandise', params=params, headers=headers) + + def create_checkout(self, params={}, headers={}): + return self.client.request('post', '/checkout', params=params, headers=headers) + + def transfer(self, params={}, headers={}): + return self.client.request('post', '/transfer', params=params, headers=headers) + + def get_card_history(self, params={}, headers={}): + return self.client.request('post', '/cardHistory', params=params, headers=headers) 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}