コード例 #1
0
ファイル: plaid_client.py プロジェクト: DerekHXZ/Travelog
class Plaid:

    def __init__(self, clientId, clientSecret, accessToken=None):
        self.client = Client(client_id=clientId, secret=clientSecret, access_token=accessToken)

    def connect(self, accountType, username, password, email):
        connect = self.client.connect(account_type=accountType, username=username, password=password, email=email)
        if connect.ok:
            json_response = json.loads(connect.content)
            return json_response;

    def answerMFA(self, accountType, mfaAnswer):
        step = self.client.step(account_type=accountType, mfa=mfaAnswer)
        if step.ok:
            transactions = json.loads(step.content)
            return transactions

    def getTransactions(self, options=None):
        transactions = self.client.transactions(options)
        if transactions.ok:
            transactions = json.loads(transactions.content)
            return transactions

    def delete(self):
        self.client.delete_user()
コード例 #2
0
    def import_into_database(self, user, sub_account, access_token):
        # data = PlaidData.getData('wells', "joefarned3", "angela0816", '*****@*****.**')
        client = Client(client_id=self.client_id, secret=self.secret)
        client.set_access_token(access_token)
        connect = client.transactions()
        data = json.loads(connect.content)

        c = MongoClient()
        db = c['pava']

        accounts = db['accounts']
        transactions = db['transactions']

        for account in data['accounts']:
            account['_user_id'] = user.id
            account['_user_account'] = sub_account.id
            if not accounts.find({'_id': account['_id']}).count():
                print accounts.insert(account)
            else:
                accounts.update({'_id': account['_id']}, account)

        for transaction in data['transactions']:
            transaction['_user_id'] = user.id
            if not transactions.find({'_id': transaction['_id']}).count():
                print transactions.insert(transaction)

        return data
コード例 #3
0
def test_transactions_requires_access_token():
    client = Client('myclientid', 'mysecret')
    with pytest.raises(Exception):
        client.transactions()
コード例 #4
0
def test_transactions():
    with patch('requests.get') as mock_requests_get:
        client = Client('myclientid', 'mysecret', 'token')
        ret = client.transactions()
        assert mock_requests_get.called
        assert ret is not None