From daefd398ed8c0ac3aab8175fb76fb490000510aa Mon Sep 17 00:00:00 2001 From: Alice Date: Sat, 6 Aug 2016 02:48:55 +0000 Subject: [PATCH] Add /api/locations --- ccvpn/urls.py | 1 + lambdainst/views.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/ccvpn/urls.py b/ccvpn/urls.py index d4731de..d3e6927 100644 --- a/ccvpn/urls.py +++ b/ccvpn/urls.py @@ -13,6 +13,7 @@ urlpatterns = [ url(r'^admin/referrers$', account_views.admin_ref, name='admin_ref'), url(r'^admin/', include(admin.site.urls)), + url(r'^api/locations$', account_views.api_locations), url(r'^api/auth$', account_views.api_auth), url(r'^$', views.index, name='index'), diff --git a/lambdainst/views.py b/lambdainst/views.py index eb5226b..67e5463 100644 --- a/lambdainst/views.py +++ b/lambdainst/views.py @@ -300,6 +300,18 @@ def api_auth(request): return JsonResponse(dict(status='ok')) +def api_locations(request): + def format_loc(cc, l): + return { + 'country_name': l['country_name'], + 'country_code': cc, + 'hostname': l['hostname'], + 'bandwidth': l['bandwidth'], + 'servers': l['servers'], + } + return JsonResponse(dict(locations=[format_loc(cc, l) for cc, l in get_locations()])) + + def status(request): locations = get_locations()