Prechádzať zdrojové kódy

Add realms endpoint to server

Frans Bergman 7 rokov pred
rodič
commit
d748140c38
2 zmenil súbory, kde vykonal 12 pridanie a 1 odobranie
  1. 2 1
      server/wac/api.py
  2. 10 0
      server/wac/rest.py

+ 2 - 1
server/wac/api.py

@@ -14,8 +14,9 @@ except IOError as e:
     )
     raise e
 
-def get_json(method):
+def get_json(method, **kwargs):
     params = dict(config['api'])
     params['method'] = method
+    params.update(kwargs)
     r = requests.get("{url}{method}?locale={locale}&apiKey={key}".format(**params))
     return r.json()

+ 10 - 0
server/wac/rest.py

@@ -22,5 +22,15 @@ def search(query):
         results = searcher.search(query, limit=10)
         return jsonify([dict(r) for r in results])
 
+@app.route("/realms/<region>")
+@cross_origin()
+def realms(region):
+    return jsonify([realm['name'] for realm in api.get_json("/wow/realm/status", url="https://{}.api.battle.net".format(region))['realms']])
+
+@app.after_request
+def apply_json(response):
+    response.headers["Content-Type"] = "application/json"
+    return response
+
 if __name__ == '__main__':
     app.run()