CONTRIBUTING to pyshorteners¶
First of all, thanks for your intention to help with this project. It was built while i was learning some python magic features and it really makes me happy that you also want to be part of this.
Some steps to make our lives easier:
Before start making any code changes, please open an issue or check if your feature/bugfix is already being handled.
Please always make your changes on a separated branch, you choose the name of it.
Please follow PEP8.
Make sure
make test
passes before sending the Pull request.
Thanks for your help and let me buy you a 🍺 sometime
Building a new Shortener¶
If you want to build another implementation of a shortener API, you basically need to:
Create a new module under the
shorteners
folder with the shortener api name (e.g:adfly.py
)Create a
Shortener
class inheriting fromBaseShortener
(pyshorteners.base.BaseShortener
)add the
api_url
property with the API urlImplement
short
andexpand
methodsYou can add custom methods if you want. Just make sure to document it.
Add docstring for the new
Shortener
class following Google Style
Example:
# yourapi.py
from pyshorteners.base import BaseShortener
class Shortener(BaseShortener):
"""
Docstring
"""
api_url = 'http://the/link/for/the/api'
def short(self, url):
pass
def expand(self, url):
pass
def custom_method(self):
pass
Then, to use this new shortener, just try:
>>> import pyshorteners
>>> s = Shortener()
>>> s.yourapi.short('http://some.url')
'result'
>>> s.yourapi.expand('http://some.url')
'result2'
>>> s.yourapi.custom_method()
Check out the current implementations for more info
Precommit Hooks¶
This project uses the pre-commit project to manage git pre-commit hooks, that means hooks will be run before commiting that at the moment check for pylint and black style rules.
If you are following this guide and ran make test
then there is
nothign needed to enable this behavior, pre-commits area already
installed.
If you are not following this guide (you should) then you can enable pre-commit like
$ pip install pre-commit
$ pre-commit install