def post(self, request, *args, **kwargs): data = request.data.copy() data['company'] = 'stokvel_io' RehiveSDK = Rehive() response = RehiveSDK.auth.login(data) return Response(response, status=status.HTTP_200_OK)
def validate(self, validated_data): rehive = Rehive(validated_data.get('token')) try: user = rehive.user.get() groups = [g['name'] for g in user['groups']] if len(set(["admin", "service"]).intersection(groups)) <= 0: raise serializers.ValidationError( {"token": ["Invalid admin user."]}) except APIException: raise serializers.ValidationError({"token": ["Invalid user."]}) try: company = rehive.admin.company.get() except APIException: raise serializers.ValidationError({"token": ["Invalid company."]}) if Company.objects.filter(identifier=company['identifier']).exists(): raise serializers.ValidationError( {"token": ["Company already activated."]}) try: currencies = rehive.company.currencies.get() except APIException: raise serializers.ValidationError({"non_field_errors": ["Unkown error."]}) validated_data['user'] = user validated_data['company'] = company validated_data['currencies'] = currencies return validated_data
def authenticate(self, request): token = self.get_auth_header(request) # token = "" #Overide token for testing rehive = Rehive(token) try: user = rehive.user.get() groups = [g['name'] for g in user['groups']] if len(set(["admin", "service"]).intersection(groups)) <= 0: raise exceptions.AuthenticationFailed(_('Invalid admin user')) except APIException: raise exceptions.AuthenticationFailed(_('Invalid user')) try: company = Company.objects.get(identifier=user['company']) except Company.DoesNotExist: raise exceptions.AuthenticationFailed( _("Inactive company. Please activate the company first.")) user, created = User.objects.get_or_create(identifier=uuid.UUID( user['identifier']).hex, company=company) # Return the permanent token for (not the request token) the company. return user, company.admin.token
def post(self, request, *args, **kwargs): # Disgusting hacks that need to be fixed rehive = Rehive() email_append = randint(1, 9999) password = ''.join(choices(string.ascii_uppercase + string.digits, k=8)) stokvel_user_data = { 'email': 'stokvel+' + str(email_append) + '@rehive.com', 'first_name': 'stokvel', 'last_name': 'stokvel', 'company': 'stokvel_io', 'password1': password, 'password2': password } try: response = rehive.auth.register(stokvel_user_data) data = response.get('data') mutable = request.data._mutable request.data._mutable = True request.data['rehive_identifier'] = data.get('user').get( 'identifier') request.data._mutable = mutable return super(StokvelView, self).post(request, *args, **kwargs) except APIException as e: return Response(e.data, status=e.status)
def __init__(self, username, token, channel, rehive_api_key): self.token = token self.channel = '#' + channel self.rehive = Rehive(rehive_api_key) # Create IRC bot connection server = 'irc.chat.twitch.tv' port = 6667 print('Connecting to ' + server + ' on port ' + str(port) + '...') irc.bot.SingleServerIRCBot.__init__(self, [(server, port, 'oauth:' + token)], username, username)
def create(self, request, *args, **kwargs): data = request.data.copy() data['company'] = 'stokvel_io' rehive = Rehive() try: response = rehive.auth.register(data) user = User( rehive_identifier=response['data']['user']['identifier'], email=response['data']['user']['email'], created=timezone.now(), updated=timezone.now()) user.save() except APIException as e: return Response(e.data, status=e.status) return Response(response, status=status.HTTP_201_CREATED)
def validate(self, validated_data): rehive = Rehive(validated_data.get('token')) try: user = rehive.user.get() groups = [g['name'] for g in user['groups']] if len(set(["admin", "service"]).intersection(groups)) <= 0: raise serializers.ValidationError( {"token": ["Invalid admin user."]}) except APIException: raise serializers.ValidationError({"token": ["Invalid user."]}) try: validated_data['company'] = Company.objects.get( identifier=user['company']) except Company.DoesNotExist: raise serializers.ValidationError( {"token": ["Company has not been activated yet."]}) return validated_data
def authenticate(self, request): token = self.get_auth_header(request) # token = "" #Overide token for testing rehive = Rehive(token) try: user = rehive.user.get() except APIException: raise exceptions.AuthenticationFailed(_('Invalid user')) try: company = Company.objects.get(identifier=user['company']) except Company.DoesNotExist: raise exceptions.AuthenticationFailed(_("Inactive company.")) user, created = User.objects.get_or_create(identifier=uuid.UUID( user['identifier']).hex, company=company) return user, token
def authenticate(self, request): try: token = self.get_token_value(request) RehiveSDK = Rehive(token) response = RehiveSDK.auth.get_current_user() if response: user = response['data'] try: stokvel_user = User.objects.get( rehive_identifier=user['identifier']) except User.DoesNotExist: raise exceptions.AuthenticationFailed( _('Invalid Stokvel user')) else: raise exceptions.AuthenticationFailed(_('Invalid user')) except Exception as e: raise exceptions.AuthenticationFailed('Authentication error.') return user, token
from rehive import Rehive import uuid rehive_client = Rehive( token="cc18ad2a05760628eaff7fefd73857879e6abbddafa1f477fc453c55666e31db") def who_am_i(): return rehive_client.user.get() def debit_account(amount): amount = amount * 100 user = who_am_i() user_balance = user.get('balance', 0) currency = user.get('currency', {}).get('code', '') if user_balance > 0 and user_balance >= amount: rehive_response = rehive_client.transactions.create_debit( amount=amount, currency=currency) print(rehive_response) if 'id' in rehive_response: return "Success" else: return "Failed" else: return "Not enough in balance" def credit_account(amount): amount = amount * 100 user = who_am_i()
def post(self, request, *args, **kwargs): if not request.data.get('pull_request'): return Response({ 'status': 'success', 'data': "FAIL" }, status=status.HTTP_200_OK) rehive = Rehive(os.environ.get('REHIVE_AUTH_TOKEN')) pull_request = request.data.get('pull_request') pr_id = pull_request.get('id') merged = pull_request.get('merged') user = pull_request.get('user') issue_url = pull_request.get('issue_url') body = pull_request.get('body') action = request.data.get('action') username = user.get('login') try: _user = User.objects.get(username=username) try: user = rehive.admin.users.get(str(_user.identifier)) except APIException: user = rehive.admin.users.create() except User.DoesNotExist: user = rehive.admin.users.create() User.objects.create(identifier=user.get('identifier'), username=username) r = re.search(r'\#([\d]+)', body) if r: try: amount = GithubIssueBounty.objects.get( issue_nr=r.group(1)).amount except GithubIssueBounty.DoesNotExist: amount = 1 if action == 'opened': tx = rehive.admin.transactions.create_credit( user=user.get('identifier'), amount=amount, currency='GITOS', status='pending', reference=str(pr_id)).get('id') elif action == 'closed': _tx = rehive.admin.transactions.get( filter={'reference': str(pr_id)})[0] if merged: tx = rehive.admin.transactions.confirm(_tx.get('id')) else: tx = rehive.admin.transactions.fail(_tx.get('id')) GithubIssueBounty.close(issue_url) return Response({ 'status': 'success', 'data': tx }, status=status.HTTP_201_CREATED)
from rehive import Rehive from rehive.api.exception import APIException from flask import Flask, request, Response from random import randint app = Flask(__name__) rehive = Rehive( '3fa887e364f8bab29a2f0d942b86268d884af20b2b802b00735d108904c95f26') TX_STORE = { '*****@*****.**': dict(identifier='81eee5a5-c08b-4f28-b5f1-61668912561c') } @app.route("/", methods=['POST', 'GET']) def main(): if not request.method == 'POST': return 'FOOL!' data = request.get_json() if not data.get('pull_request'): return Response('Derp') pull_request = data.get('pull_request') pr_id = pull_request.get('id') action = data.get('action') merged = data.get('merged') user = pull_request.get('user') username = user.get('login')
from slackclient import SlackClient from rehive import Rehive, APIException import pprint pp = pprint.PrettyPrinter(indent=4) SLACK_TOKEN=os.environ.get('SLACK_TOKEN') REHIVE_TOKEN=os.environ.get('REHIVE_TOKEN') # instantiate Slack client slack_client = SlackClient(SLACK_TOKEN) rehive = Rehive(REHIVE_TOKEN) # Sends the response back to the channel users = slack_client.api_call( "users.list", )['members'] users = [user for user in users if not user['deleted'] and not user['is_bot'] and user['name'] != 'slackbot'] for user in users: try: r = rehive.admin.users.create( id=user['id'], email=user['profile']['email'] ) except APIException as e: print('Error with ' + user['profile']['email']) print(str(e))
from rehive import Rehive, APIException from secret import REHIVE_API import csv rehive = Rehive(REHIVE_API) # rehive.auth.login(user="******", company="hackmission", password="******") # accounts = rehive.admin.users.get() # transaction = rehive.admin.transactions.create_credit(user='******', amount=10000, confirm_on_create=True) with open('cryptofund.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=',') for row in readCSV: print(row) print(row[0]) # print(accounts)
import os import time import re from rehive import Rehive import pprint pp = pprint.PrettyPrinter(indent=4) # Create a company on dashboard.rehive.com # ADD BCH as acurrency # Create an account configuration REHIVE_TOKEN=os.environ.get('REHIVE_TOKEN') API_KEY=REHIVE_TOKEN rehive = Rehive(API_KEY) # Creating users: #response = rehive.user.emails.get() # response = rehive.admin.users.create( # id="U1QCNFM60", # email='*****@*****.**' # ) # pp.pprint(response) # Deposit: # response = rehive.admin.transactions.create_credit( # user="******", # amount=1000,
from rehive import Rehive import pprint printer = pprint.PrettyPrinter(indent=1) rehive = Rehive( '9f93f74d1934c9df0a9bc5183987f25147617058b6df8384a60105c5f5383891') register = input("\nDo you want to register new users? Type 'yes' and enter: ") if register == 'yes': for num in range(0, 2): user = rehive.admin.users.create() printer.pprint(user) credit = input("\nLet's credit some users. Please type amount: ") users = rehive.admin.users.get() for user in users: group = user['groups'][0]['name'] if group == 'user': tx = rehive.admin.transactions.create_credit(amount=credit, currency='USD', user=user['identifier'], confirm_on_create=False) print(tx)