Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit e60e71b

Browse files
committed
Add db.events() poc
1 parent 9bf5bde commit e60e71b

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

orbitdbapi/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .version import version, version_info
2+
from .client import OrbitDbAPI
3+
from .db import DB
4+
__version__ = version

orbitdbapi/__version__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

orbitdbapi/client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ def __init__ (self, **kwargs):
1515
self.__session = requests.Session()
1616
self.__session.mount(self.__base_url, HTTP20Adapter(timeout=self.__timeout))
1717

18+
@property
19+
def session(self):
20+
return self.__session
21+
22+
@property
23+
def base_url(self):
24+
return self.__base_url
25+
1826
@property
1927
def use_db_cache(self):
2028
return self.__use_db_cache
@@ -27,9 +35,12 @@ def _do_request(self, *args, **kwargs):
2735
self.logger.exception('Exception during api call')
2836
raise
2937

30-
def _call(self, method, endpoint, body=None):
38+
def _call_raw(self, method, endpoint, **kwargs):
3139
url = '/'.join([self.__base_url, endpoint])
32-
res = self._do_request(method, url, json=body)
40+
return self._do_request(method, url, **kwargs)
41+
42+
def _call(self, method, endpoint, body=None):
43+
res = self._call_raw(method, endpoint, json=body)
3344
try:
3445
result = res.json()
3546
except:

orbitdbapi/db.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
from copy import deepcopy
4+
from sseclient import SSEClient
45
from collections.abc import Hashable, Iterable
56
from urllib.parse import quote as urlquote
67

@@ -172,6 +173,12 @@ def unload(self):
172173
endpoint = '/'.join(['db', self.__id_safe])
173174
return self.__client._call('delete', endpoint)
174175

176+
def events(self, eventname):
177+
endpoint = '/'.join(['db', self.__id_safe,'events', eventname])
178+
#return SSEClient('{}/{}'.format(self.__client.base_url, endpoint), session=self.__client.session)
179+
req = self.__client._call_raw('get', endpoint, stream=True)
180+
return SSEClient(req).events()
181+
175182
class CapabilityError(Exception):
176183
pass
177184

orbitdbapi/version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = '0.2.2-dev0'
2+
version_info = tuple([int(d) for d in version.split("-")[0].split(".")])

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env python
22

3-
from orbitdbapi.__version__ import __version__
43
from setuptools import setup, find_packages
54

5+
version = None
6+
exec(open('orbitdbapi/version.py').read())
7+
68
setup(
79
name='orbitdbapi',
8-
version=__version__,
10+
version=version,
911
description='A Python HTTP Orbitdb API Client',
1012
author='Phillip Mackintosh',
1113
url='https://github.com/phillmac/py-orbit-db-http-client',

0 commit comments

Comments
 (0)