Skip to content

Commit

Permalink
Update to v6 and add methods
Browse files Browse the repository at this point in the history
 - sponsor
 - unusedSponsorships
 - sponsorshipStatus
  • Loading branch information
youngkidwarrior committed Aug 17, 2022
1 parent 2ade820 commit 50a6dfa
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 49 deletions.
6 changes: 6 additions & 0 deletions brightid/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
1 change: 1 addition & 0 deletions brightid/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ def get(self, group):
res = response.json()
self.node.check_error(res)
return res.get('data')

10 changes: 2 additions & 8 deletions brightid/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@


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)
self.verifications = verifications.Verifications(self)
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()
Expand Down
1 change: 1 addition & 0 deletions brightid/operations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import time


class Operations:
Expand Down
28 changes: 28 additions & 0 deletions brightid/sponsorships.py
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 0 additions & 26 deletions brightid/testblocks.py

This file was deleted.

9 changes: 3 additions & 6 deletions brightid/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion brightid/users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests


class Users:
def __init__(self, node):
self.node = node
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions brightid/verifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]',
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 = '[email protected], [email protected]',
url = 'https://github.com/BrightID/python-brightid',
download_url = 'https://github.com/BrightID/python-brightid/archive/main.zip',
keywords = ['Brightid'],
install_requires=[
'requests',
Expand All @@ -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',

Expand Down

0 comments on commit 50a6dfa

Please sign in to comment.