From 51400fd8282441c3fe7f9de0d62588900c0078db Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Sun, 7 Aug 2016 19:57:11 -0500 Subject: [PATCH] Add JSONRPC class --- resources/lib/utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 12aba200..18a74b8e 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -51,6 +51,36 @@ def language(string_id): # Central string retrieval - unicode return xbmcaddon.Addon(id='plugin.video.emby').getLocalizedString(string_id) +class JSONRPC(object): + + id_ = 1 + jsonrpc = "2.0" + + def __init__(self, method, **kwargs): + + self.method = method + + for arg in kwargs: # id_(int), jsonrpc(str) + self.arg = arg + + def _query(self): + + query = { + + 'jsonrpc': self.jsonrpc, + 'id': self.id_, + 'method': self.method, + } + if self.params is not None: + query['params'] = self.params + + return json.dumps(query) + + def execute(self, params=None): + + self.params = params + return json.loads(xbmc.executeJSONRPC(self._query())) + ################################################################################################# # Database related methods