Add imports to API

This commit is contained in:
TrueTechy 2020-01-14 21:50:59 +00:00
commit c9a802b255
4 changed files with 11 additions and 22 deletions

View file

@ -5,7 +5,6 @@
provider-name="Jellyfin Contributors, angelblue05"> provider-name="Jellyfin Contributors, angelblue05">
<requires> <requires>
<import addon="xbmc.python" version="2.25.0"/> <import addon="xbmc.python" version="2.25.0"/>
<import addon="script.module.web-pdb" />
<import addon="script.module.requests" version="2.22.0"/> <import addon="script.module.requests" version="2.22.0"/>
<import addon="script.module.dateutil" version="2.7.3"/> <import addon="script.module.dateutil" version="2.7.3"/>
<import addon="script.module.six" /> <import addon="script.module.six" />

View file

@ -1,8 +1,7 @@
from __future__ import division, absolute_import, print_function, unicode_literals
import requests import requests
from helper.utils import settings from helper.utils import settings
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, print_function, unicode_literals
def jellyfin_url(client, handler): def jellyfin_url(client, handler):
@ -374,8 +373,10 @@ class API(object):
"x-emby-authorization": auth "x-emby-authorization": auth
} }
def send_request(self, method, url, path, timeout=self.default_timeout, headers=get_default_headers(), data=None): def send_request(self, method, url, path, timeout=None, headers=get_default_headers(), data=None):
import web_pdb; web_pdb.set_trace() if not timeout:
timeout = self.timeout
request_method = getattr(requests, method.lower(), "get") #Defaults to get request if none specified request_method = getattr(requests, method.lower(), "get") #Defaults to get request if none specified
url = "%s/%s" % (url, path) url = "%s/%s" % (url, path)
@ -394,7 +395,11 @@ class API(object):
headers = self.get_default_headers() headers = self.get_default_headers()
try: try:
response = requests.post(url, data=authData, timeout=self.default_timeout, headers=headers, verify=settings('sslverify')) if settings('sslverify'):
response = requests.post(url, data=authData, timeout=self.default_timeout, headers=headers)
else:
response = requests.post(url, data=authData, timeout=self.default_timeout, headers=headers, verify=False)
if response.status_code == 200: if response.status_code == 200:
return response.json() return response.json()
else: else:

View file

@ -12,15 +12,9 @@ from operator import itemgetter
import urllib3 import urllib3
<<<<<<< HEAD
from credentials import Credentials
from http import HTTP # noqa: I201,I100
from api import API
=======
from .credentials import Credentials from .credentials import Credentials
from .http import HTTP # noqa: I201,I100 from .http import HTTP # noqa: I201,I100
>>>>>>> 896c2fe6ec9f5fa03f7a4aa638bc8effd04ac182 from .api import API
################################################################################################# #################################################################################################
@ -38,7 +32,6 @@ class ConnectionManager(object):
user = {} user = {}
server_id = None server_id = None
timeout = 10
def __init__(self, client): def __init__(self, client):
@ -100,7 +93,6 @@ class ConnectionManager(object):
LOG.info("Failed to login as `"+username+"`") LOG.info("Failed to login as `"+username+"`")
return {} return {}
## TODO Change when moving to database storage of server details ## TODO Change when moving to database storage of server details
credentials = self.credentials.get() credentials = self.credentials.get()

View file

@ -1,7 +0,0 @@
from pprint import pprint
from operator import itemgetter
servers = [{'Id': u'd27a4f681a5746d79ee0bb29b52aad55', 'DateLastAccessed': '2019-12-02T21:53:55Z', 'Name': u'Testing Server', 'address': u'http://jelly.local'}, {'Id': u'd27a4f681a5746d79ee0bb29b52aad56', 'DateLastAccessed': '2019-12-27T20:53:55Z', 'Name': u'Other Testing Server', 'address': u'http://jelly2.local'}]
pprint(servers)
servers.sort(key=itemgetter('DateLastAccessed'), reverse=True)
pprint(servers)