Skip to content
Snippets Groups Projects
Verified Commit 124aca7b authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added /sources endpoint

parent b5a9a5fb
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ application = ProtocolTypeRouter( ...@@ -18,6 +18,7 @@ application = ProtocolTypeRouter(
{ {
"http": URLRouter( "http": URLRouter(
[ [
url(r"^v1/sources$", consumers.SourcesConsumer),
url(r"^v1/providers$", consumers.ProvidersConsumer), url(r"^v1/providers$", consumers.ProvidersConsumer),
url(r"^v1/search/$", consumers.SearchMultipleConsumer), url(r"^v1/search/$", consumers.SearchMultipleConsumer),
url( url(
......
...@@ -195,3 +195,13 @@ class ProvidersConsumer(AsyncHttpConsumer): ...@@ -195,3 +195,13 @@ class ProvidersConsumer(AsyncHttpConsumer):
for _, p in sorted(providers.registry, key=lambda v: v[0]) for _, p in sorted(providers.registry, key=lambda v: v[0])
] ]
await json_response(self, 200, data) await json_response(self, 200, data)
class SourcesConsumer(AsyncHttpConsumer):
@wrapper_500
async def handle(self, body):
data = [
{"id": p.id, "label": p.label, "example": p.example}
for p in sorted(sources.registry._data.values(), key=lambda v: v.id)
]
await json_response(self, 200, data)
...@@ -26,6 +26,8 @@ registry = Registry() ...@@ -26,6 +26,8 @@ registry = Registry()
class Source(object): class Source(object):
id = None id = None
label = None
example = None
async def get(self, lookup): async def get(self, lookup):
raise NotImplementedError() raise NotImplementedError()
...@@ -34,6 +36,8 @@ class Source(object): ...@@ -34,6 +36,8 @@ class Source(object):
@registry.register @registry.register
class Activitypub(Source): class Activitypub(Source):
id = "activitypub" id = "activitypub"
label = "ActivityPub URL"
example = "https://mastodon.domain/@username"
excluded_tags = [ excluded_tags = [
"#noretribute", "#noretribute",
# '#nobot', # '#nobot',
...@@ -73,6 +77,8 @@ class Activitypub(Source): ...@@ -73,6 +77,8 @@ class Activitypub(Source):
@registry.register @registry.register
class Webfinger(Source): class Webfinger(Source):
id = "webfinger" id = "webfinger"
label = "Fediverse/Webfinger username"
example = "username@mastodon.domain"
async def get(self, lookup, session, cache): async def get(self, lookup, session, cache):
webfinger_data = await webfinger.lookup(lookup, session, cache=cache) webfinger_data = await webfinger.lookup(lookup, session, cache=cache)
...@@ -86,6 +92,8 @@ class Webfinger(Source): ...@@ -86,6 +92,8 @@ class Webfinger(Source):
@registry.register @registry.register
class MusicBrainz(Source): class MusicBrainz(Source):
id = "musicbrainz" id = "musicbrainz"
label = "MusicBrainz Artist ID"
example = "a2e55cf5-ca3a-4c26-ba62-fc4a4f2bc603"
async def get(self, lookup, session, cache): async def get(self, lookup, session, cache):
......
...@@ -142,3 +142,18 @@ async def test_providers(loop, application, mocker, coroutine_mock): ...@@ -142,3 +142,18 @@ async def test_providers(loop, application, mocker, coroutine_mock):
(b"Access-Control-Allow-Origin", b"*"), (b"Access-Control-Allow-Origin", b"*"),
] ]
assert response["body"] == json.dumps(expected, indent=2, sort_keys=True).encode() assert response["body"] == json.dumps(expected, indent=2, sort_keys=True).encode()
async def test_sources(loop, application, mocker, coroutine_mock):
expected = [
{"id": p.id, "label": p.label, "example": p.example}
for p in sorted(sources.registry._data.values(), key=lambda v: v.id)
]
communicator = HttpCommunicator(application, "GET", "/v1/sources")
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment