Skip to content

Commit 00be462

Browse files
Update to v6 and add methods
- sponsor - unusedSponsorships - sponsorshipStatus
1 parent 2ade820 commit 00be462

File tree

9 files changed

+38
-49
lines changed

9 files changed

+38
-49
lines changed

brightid/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ def get(self, app=''):
1010
res = response.json()
1111
self.node.check_error(res)
1212
return res.get('data').get('apps') or res.get('data')
13+
14+
def unusedSponsorships(self, app=''):
15+
response = requests.get(f'{self.node.url}/apps/{app}')
16+
res = response.json()
17+
self.node.check_error(res)
18+
return res.get('data').get('apps').get('unusedSponsorships')

brightid/groups.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ def get(self, group):
1010
res = response.json()
1111
self.node.check_error(res)
1212
return res.get('data')
13+

brightid/node.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44

55

66
class Node:
7-
def __init__(self, url='http://node.brightid.org/brightid/v5'):
8-
self.url = url
7+
def __init__(self):
8+
self.url = "http://node.brightid.org/brightid/v6"
99
self.users = users.Users(self)
1010
self.groups = groups.Groups(self)
1111
self.operations = operations.Operations(self)
1212
self.verifications = verifications.Verifications(self)
1313
self.testblocks = testblocks.Testblocks(self)
1414
self.apps = apps.Apps(self)
1515

16-
def ip(self):
17-
response = requests.get(f'{self.url}/ip')
18-
res = response.json()
19-
self.check_error(res)
20-
return res.get('data').get('ip')
21-
2216
def state(self):
2317
response = requests.get(f'{self.url}/state')
2418
res = response.json()

brightid/operations.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests
2+
import time
23

34

45
class Operations:
@@ -18,3 +19,18 @@ def get(self, hash):
1819
res = response.json()
1920
self.node.check_error(res)
2021
return res.get('data')
22+
23+
def sponsor(self, key, app, app_user_id):
24+
unusedSponsorships = self.node.apps.unusedSponsorships(app)
25+
if(unusedSponsorships < 1):
26+
raise RuntimeError(app + ' does not have any unused sponsorships')
27+
op = {
28+
'name': 'Sponsor',
29+
'app': app,
30+
'appUserId': app_user_id,
31+
'timestamp': int(time.time()*1000),
32+
'v': 6
33+
}
34+
op['sig'] = self.node.tools.sign(op, key)
35+
self.node.operations.post(op)
36+

brightid/testblocks.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

brightid/tools.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
import pyqrcode
55

66

7-
def create_deep_link(context, context_id, url='http://node.brightid.org', schema='https'):
8-
url = url.replace('/', '%2f')
9-
if schema == 'brightid':
10-
deep_link = f'brightid://link-verification/{url}/{context}/{context_id}'
11-
else:
12-
deep_link = f'https://app.brightid.org/link-verification/{url}/{context}/{context_id}/'
7+
def create_deep_link(app, app_user_id):
8+
url = "http://node.brightid.org".replace('/', '%2f')
9+
deep_link = f'brightid://link-verification/{url}/{app}/{app_user_id}'
1310
return deep_link
1411

1512

brightid/users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import requests
22

3+
34
class Users:
45
def __init__(self, node):
56
self.node = node
@@ -25,7 +26,7 @@ def connections(self, user, direction):
2526
self.node.check_error(res)
2627
return res.get('data').get('connections')
2728

28-
def profile(self, user, requestor):
29+
def profile(self, user, requestor=""):
2930
response = requests.get(
3031
f'{self.node.url}/users/{user}/profile/{requestor}')
3132
res = response.json()

brightid/verifications.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ class Verifications:
55
def __init__(self, node):
66
self.node = node
77

8-
def get(self, app, context_id='', **kwargs):
8+
def get(self, app, app_user_id='', **kwargs):
99
params = (
1010
('timestamp', kwargs.get('timestamp')),
1111
('signed', kwargs.get('signed')),
1212
('count_only', kwargs.get('count_only'))
1313
)
14-
response = requests.get(f'{self.node.url}/verifications/{app}/{context_id}', params=params)
14+
response = requests.get(f'{self.node.url}/verifications/{app}/{app_user_id}', params=params)
1515
res = response.json()
1616
self.node.check_error(res)
1717
if res.get('data').get('count') and kwargs.get('count_only'):

setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
setup(
33
name = 'python_brightid',
44
packages = ['brightid'],
5-
version = '1.2.0',
5+
version = '2.0.0',
66
license='MIT',
77
description = 'SDK for integrating with BrightId!',
8-
author = 'Pooya Fekri',
9-
author_email = 'pooyafekri79@gmail.com',
10-
url = 'https://github.com/PooyaFekri/python-brightid',
11-
download_url = 'https://github.com/PooyaFekri/python-brightid/archive/main.zip',
8+
author = 'Pooya Fekri, Victor Ginelli (@youngkidwarrior)',
9+
author_email = 'pooyafekri79@gmail.com, victor@she.energy',
10+
url = 'https://github.com/BrightID/python-brightid',
11+
download_url = 'https://github.com/BrightID/python-brightid/archive/main.zip',
1212
keywords = ['Brightid'],
1313
install_requires=[
1414
'requests',
@@ -19,7 +19,7 @@
1919
classifiers=[ # Optional
2020
# How mature is this project? Common values are
2121
# 3 - Alpha
22-
# 4 - Beta
22+
# 4 - Beta``
2323
# 5 - Production/Stable
2424
'Development Status :: 4 - Beta',
2525

0 commit comments

Comments
 (0)