make calls to manuals resouce
This commit is contained in:
parent
8762705cb5
commit
2f9a2edb44
|
@ -98,6 +98,7 @@ class DevicehubConfig(Config):
|
|||
API_DLT = config('API_DLT', None)
|
||||
API_DLT_TOKEN = config('API_DLT_TOKEN', None)
|
||||
ID_FEDERATED = config('ID_FEDERATED', None)
|
||||
URL_MANUALS = config('URL_MANUALS', None)
|
||||
|
||||
"""Definition of oauth jwt details."""
|
||||
OAUTH2_JWT_ENABLED = config('OAUTH2_JWT_ENABLED', False)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
|
||||
import flask
|
||||
import requests
|
||||
from ereuseapi.methods import API
|
||||
from flask import Blueprint
|
||||
from flask import current_app as app
|
||||
|
@ -183,5 +184,28 @@ class DidView(View):
|
|||
dpps.append(rr)
|
||||
return {'data': dpps}
|
||||
|
||||
def get_manuals(self):
|
||||
self.params = "{} {}".format(self.device.manufacturer, self.model)
|
||||
manuals = {'ifixit': {}, 'icecat': {}}
|
||||
manuals['ifixit'] = self.request_manuals('ifixit')
|
||||
manuals['icecat'] = self.request_manuals('icecat')
|
||||
return manuals
|
||||
|
||||
def request_manuals(self, prefix):
|
||||
url = app.config('URL_MANUALS')
|
||||
if not url:
|
||||
return {}
|
||||
|
||||
res = requests.post(url + "/" + prefix, self.params)
|
||||
if res.status_code > 299:
|
||||
return {}
|
||||
|
||||
try:
|
||||
response = res.json()
|
||||
except Exception:
|
||||
response = {}
|
||||
|
||||
return response
|
||||
|
||||
|
||||
did.add_url_rule('/<string:id_dpp>', view_func=DidView.as_view('did'))
|
||||
|
|
Reference in New Issue