Verified Commit 975e2aac authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added /providers endpoint

parent 72122ea3
......@@ -18,6 +18,7 @@ application = ProtocolTypeRouter(
{
"http": URLRouter(
[
url(r"^v1/providers$", consumers.ProvidersConsumer),
url(r"^v1/search/$", consumers.SearchMultipleConsumer),
url(
r"^v1/search/(?P<lookup_type>.+):(?P<lookup>.+)$",
......
......@@ -64,24 +64,32 @@ class BasicUsernameInDomainProvider(Provider):
@registry.register
class Patreon(BasicUsernameInPathProvider):
id = "patreon"
label = "Patreon"
url = "https://patreon.com"
domain_regex = r"^(\w+\.)*patreon\.com"
@registry.register
class Paypal(BasicUsernameInPathProvider):
id = "paypal"
label = "PayPal"
url = "https://paypal.me"
domain_regex = r"^(\w+\.)*paypal\.me"
@registry.register
class Tipeee(BasicUsernameInPathProvider):
id = "tipeee"
label = "Tipeee"
url = "https://tipeee.com"
domain_regex = r"^(\w+\.)*tipeee\.com"
@registry.register
class Liberapay(BasicUsernameInPathProvider):
id = "liberapay"
label = "Liberapay"
url = "https://liberapay.com"
domain_regex = r"^(\w+\.)*liberapay\.com"
......@@ -89,6 +97,8 @@ class Liberapay(BasicUsernameInPathProvider):
class KoFi(BasicUsernameInPathProvider):
id = "ko-fi"
additional_ids = ["kofi"]
label = "Ko-Fi"
url = "http://ko-fi.com"
domain_regex = r"^(\w+\.)*ko-fi\.com"
......@@ -96,6 +106,8 @@ class KoFi(BasicUsernameInPathProvider):
class OpenCollective(BasicUsernameInPathProvider):
id = "opencollective"
additional_ids = ["open collective"]
label = "Open Collective"
url = "https://opencollective.com"
domain_regex = r"^(\w+\.)*opencollective\.com"
......@@ -103,4 +115,7 @@ class OpenCollective(BasicUsernameInPathProvider):
class BandCamp(BasicUsernameInDomainProvider):
id = "bandcamp"
additional_ids = ["band camp"]
label = "Bandcamp"
url = "https://bandcamp.com"
username_regex = r"^(\w+)\.bandcamp\.com"
......@@ -6,6 +6,7 @@ import ssl
from channels.generic.http import AsyncHttpConsumer
from .. import cache
from .. import providers
from . import exceptions
from . import sources
from . import serializers
......@@ -176,3 +177,13 @@ class SearchMultipleConsumer(AsyncHttpConsumer):
await json_response(self, 500, {})
raise
await json_response(self, 200, results)
class ProvidersConsumer(AsyncHttpConsumer):
@wrapper_500
async def handle(self, body):
data = [
{"id": p.id, "label": p.label, "url": p.url}
for _, p in sorted(providers.registry, key=lambda v: v[0])
]
await json_response(self, 200, data)
......@@ -71,6 +71,7 @@ testpaths = tests
env =
DJANGO_SETTINGS_MODULE=config.settings.base
SECRET_KEY=test
DJANGO_ALLOWED_HOSTS=*
EMAIL_CONFIG=consolemail://
DEBUG_TOOLBAR_ENABLED=False
DEBUG=False
......
......@@ -2,6 +2,7 @@ import json
import aiohttp
from channels.testing import HttpCommunicator
from retribute_api import providers
from retribute_api.search import consumers
from retribute_api.search import exceptions
from retribute_api.search import sources
......@@ -75,3 +76,18 @@ async def test_search_multiple(loop, application, mocker, coroutine_mock, dummyc
(b"Access-Control-Allow-Origin", b"*"),
]
assert response["body"] == json.dumps(expected, indent=2, sort_keys=True).encode()
async def test_providers(loop, application, mocker, coroutine_mock):
expected = [
{"id": p.id, "label": p.label, "url": p.url}
for _, p in sorted(providers.registry, key=lambda v: v[0])
]
communicator = HttpCommunicator(application, "GET", "/v1/providers")
response = await communicator.get_response()
assert response["status"] == 200
assert response["headers"] == [
(b"Content-Type", b"application/json"),
(b"Access-Control-Allow-Origin", b"*"),
]
assert response["body"] == json.dumps(expected, indent=2, sort_keys=True).encode()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment