diff --git a/brightid/apps.py b/brightid/apps.py index 603e582..a6d41c7 100644 --- a/brightid/apps.py +++ b/brightid/apps.py @@ -10,3 +10,9 @@ def get(self, app=''): res = response.json() self.node.check_error(res) return res.get('data').get('apps') or res.get('data') + + def unusedSponsorships(self, app=''): + response = requests.get(f'{self.node.url}/apps/{app}') + res = response.json() + self.node.check_error(res) + return res.get('data').get('apps').get('unusedSponsorships') diff --git a/brightid/groups.py b/brightid/groups.py index d79556f..01aa75b 100644 --- a/brightid/groups.py +++ b/brightid/groups.py @@ -10,3 +10,4 @@ def get(self, group): res = response.json() self.node.check_error(res) return res.get('data') + diff --git a/brightid/node.py b/brightid/node.py index 5db1959..5759f24 100644 --- a/brightid/node.py +++ b/brightid/node.py @@ -4,8 +4,8 @@ class Node: - def __init__(self, url='http://node.brightid.org/brightid/v5'): - self.url = url + def __init__(self): + self.url = "http://node.brightid.org/brightid/v6" self.users = users.Users(self) self.groups = groups.Groups(self) self.operations = operations.Operations(self) @@ -13,12 +13,6 @@ def __init__(self, url='http://node.brightid.org/brightid/v5'): self.testblocks = testblocks.Testblocks(self) self.apps = apps.Apps(self) - def ip(self): - response = requests.get(f'{self.url}/ip') - res = response.json() - self.check_error(res) - return res.get('data').get('ip') - def state(self): response = requests.get(f'{self.url}/state') res = response.json() diff --git a/brightid/operations.py b/brightid/operations.py index 483244f..c58e04b 100644 --- a/brightid/operations.py +++ b/brightid/operations.py @@ -1,4 +1,5 @@ import requests +import time class Operations: diff --git a/brightid/sponsorships.py b/brightid/sponsorships.py new file mode 100644 index 0000000..28723ef --- /dev/null +++ b/brightid/sponsorships.py @@ -0,0 +1,28 @@ +import requests +import time + + +class Sponsorships: + def __init__(self, node): + self.node = node + + def sponsorshipStatus(self, app_user_id): + response = requests.get( + f'{self.node.url}/sponsorships/{app_user_id}') + res = response.json() + self.node.check_error(res) + return res.get('data') + + def sponsor(self, key, app, app_user_id): + unusedSponsorships = self.node.apps.unusedSponsorships(app) + if (unusedSponsorships < 1): + raise RuntimeError(app + ' does not have any unused sponsorships') + op = { + 'name': 'Sponsor', + 'app': app, + 'appUserId': app_user_id, + 'timestamp': int(time.time()*1000), + 'v': 6 + } + op['sig'] = self.node.tools.sign(op, key) + self.node.operations.post(op) diff --git a/brightid/testblocks.py b/brightid/testblocks.py deleted file mode 100644 index 1de5987..0000000 --- a/brightid/testblocks.py +++ /dev/null @@ -1,26 +0,0 @@ -import requests - - -class Testblocks: - def __init__(self, node): - self.node = node - - def put(self, app, action, context_id, testing_key): - params = ( - ('testingKey', testing_key), - ) - response = requests.put( - f'{self.node.url}/testblocks/{app}/{action}/{context_id}', params=params) - if not response.ok: - res = response.json() - self.node.check_error(res) - - def delete(self, app, action, context_id, testing_key): - params = ( - ('testingKey', testing_key), - ) - response = requests.delete( - f'{self.node.url}/testblocks/{app}/{action}/{context_id}', params=params) - if not response.ok: - res = response.json() - self.node.check_error(res) diff --git a/brightid/tools.py b/brightid/tools.py index 9c06c00..1e93cda 100644 --- a/brightid/tools.py +++ b/brightid/tools.py @@ -4,12 +4,9 @@ import pyqrcode -def create_deep_link(context, context_id, url='http://node.brightid.org', schema='https'): - url = url.replace('/', '%2f') - if schema == 'brightid': - deep_link = f'brightid://link-verification/{url}/{context}/{context_id}' - else: - deep_link = f'https://app.brightid.org/link-verification/{url}/{context}/{context_id}/' +def create_deep_link(app, app_user_id): + url = "http://node.brightid.org".replace('/', '%2f') + deep_link = f'brightid://link-verification/{url}/{app}/{app_user_id}' return deep_link diff --git a/brightid/users.py b/brightid/users.py index dc2877f..781bb8f 100644 --- a/brightid/users.py +++ b/brightid/users.py @@ -1,5 +1,6 @@ import requests + class Users: def __init__(self, node): self.node = node @@ -25,7 +26,7 @@ def connections(self, user, direction): self.node.check_error(res) return res.get('data').get('connections') - def profile(self, user, requestor): + def profile(self, user, requestor=""): response = requests.get( f'{self.node.url}/users/{user}/profile/{requestor}') res = response.json() diff --git a/brightid/verifications.py b/brightid/verifications.py index 64f5b6e..1bc6ac1 100644 --- a/brightid/verifications.py +++ b/brightid/verifications.py @@ -5,13 +5,13 @@ class Verifications: def __init__(self, node): self.node = node - def get(self, app, context_id='', **kwargs): + def get(self, app, app_user_id='', **kwargs): params = ( ('timestamp', kwargs.get('timestamp')), ('signed', kwargs.get('signed')), ('count_only', kwargs.get('count_only')) ) - response = requests.get(f'{self.node.url}/verifications/{app}/{context_id}', params=params) + response = requests.get(f'{self.node.url}/verifications/{app}/{app_user_id}', params=params) res = response.json() self.node.check_error(res) if res.get('data').get('count') and kwargs.get('count_only'): diff --git a/setup.py b/setup.py index a9c7f3d..31f9545 100644 --- a/setup.py +++ b/setup.py @@ -2,13 +2,13 @@ setup( name = 'python_brightid', packages = ['brightid'], - version = '1.2.0', + version = '2.0.0', license='MIT', description = 'SDK for integrating with BrightId!', - author = 'Pooya Fekri', - author_email = 'pooyafekri79@gmail.com', - url = 'https://github.com/PooyaFekri/python-brightid', - download_url = 'https://github.com/PooyaFekri/python-brightid/archive/main.zip', + author = 'Pooya Fekri, Victor Ginelli (@youngkidwarrior)', + author_email = 'pooyafekri79@gmail.com, victor@she.energy', + url = 'https://github.com/BrightID/python-brightid', + download_url = 'https://github.com/BrightID/python-brightid/archive/main.zip', keywords = ['Brightid'], install_requires=[ 'requests', @@ -19,7 +19,7 @@ classifiers=[ # Optional # How mature is this project? Common values are # 3 - Alpha - # 4 - Beta + # 4 - Beta`` # 5 - Production/Stable 'Development Status :: 4 - Beta',