List supported currencies in API under api/currencies

This commit is contained in:
petermaksymo 2021-12-04 14:43:56 -05:00
parent 915c832acc
commit 2b0f134f74
3 changed files with 30 additions and 0 deletions

View file

@ -242,3 +242,23 @@ You can get some project stats with a `GET` on
"balance": -10.5
}
]
### Currencies
You can get a list of supported currencies with a `GET` on
`/api/currencies`:
$ curl --basic https://ihatemoney.org/api/currencies
[
"XXX",
"AED",
"AFN",
.
.
.
"ZAR",
"ZMW",
"ZWL"
]

View file

@ -5,6 +5,7 @@ from flask_restful import Resource, abort
from werkzeug.security import check_password_hash
from wtforms.fields.core import BooleanField
from ihatemoney.currency_convertor import CurrencyConverter
from ihatemoney.emails import send_creation_email
from ihatemoney.forms import EditProjectForm, MemberForm, ProjectForm, get_billform_for
from ihatemoney.models import Bill, Person, Project, db
@ -49,6 +50,13 @@ def need_auth(f):
return wrapper
class CurrenciesHandler(Resource):
currency_helper = CurrencyConverter()
def get(self):
return self.currency_helper.get_currencies()
class ProjectsHandler(Resource):
def post(self):
form = ProjectForm(meta={"csrf": False})

View file

@ -5,6 +5,7 @@ from flask_restful import Api
from ihatemoney.api.common import (
BillHandler,
BillsHandler,
CurrenciesHandler,
MemberHandler,
MembersHandler,
ProjectHandler,
@ -17,6 +18,7 @@ api = Blueprint("api", __name__, url_prefix="/api")
CORS(api)
restful_api = Api(api)
restful_api.add_resource(CurrenciesHandler, "/currencies")
restful_api.add_resource(ProjectsHandler, "/projects")
restful_api.add_resource(ProjectHandler, "/projects/<string:project_id>")
restful_api.add_resource(TokenHandler, "/projects/<string:project_id>/token")