-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi.py
32 lines (26 loc) · 923 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__copyright__ = '2018, BookFusion <[email protected]>'
__license__ = 'GPL v3'
from PyQt5.Qt import QNetworkRequest, QUrl, QUrlQuery
import base64
from calibre_plugins.bookfusion.config import prefs
from calibre_plugins.bookfusion import BookFusionPlugin
def build_request(path, params={}):
url = QUrl(prefs['api_base'] + path)
query = QUrlQuery()
for key in params:
query.addQueryItem(key, params[key])
url.setQuery(query)
req = QNetworkRequest(url)
req.setRawHeader(
u'User-Agent'.encode('utf-8'),
u'BookFusion Calibre Plugin {0}'.format(
str('.'.join(str(x) for x in BookFusionPlugin.version))
).encode('utf-8')
)
req.setRawHeader(
u'Authorization'.encode('utf-8'),
u'Basic {}'.format(
base64.b64encode(u'{}:'.format(prefs['api_key']).encode('utf-8')).decode('ascii')
).encode('utf-8')
)
return req