-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnessie.py
94 lines (81 loc) · 2.46 KB
/
nessie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# This is written for PYTHON 3
# Don't forget to install requests package
import requests
import json
import nessie_auth
# GameMaster class for storing authentication related information for the duration of the game
class MasterAccount:
def __init__(self, buyIn):
self.apiKey = nessie_auth.getApiKey()
self.customerId = nessie_auth.getCustomerId()
self.url = 'http://api.reimaginebanking.com/customers/{}/accounts?key={}'.format(self.customerId, self.apiKey)
self.buyIn = buyIn
def createAccount(self, name):
payload = {
"type": "Checking",
"nickname": name,
"rewards": 0,
"balance": self.buyIn,
}
# Create a Checking Account
response = requests.post(
self.url,
data=json.dumps(payload),
headers={'content-type':'application/json'},
)
if response.status_code == 201:
print('Account Created')
data = response.json()
return data['objectCreated']['_id']
else:
print('Error Status Code: ' + str(response.status_code))
def transfer(self, payer, assassin):
tURL = 'http://api.reimaginebanking.com/accounts/{}/transfers?key={}'.format(payer, self.apiKey)
payload = {
"medium": "balance",
"payee_id": assassin.bankId,
"amount": self.buyIn,
"transaction_date": "2017-03-25",
"description": ("Loot from " + assassin.target.name)
}
response = requests.post(
tURL,
data=json.dumps(payload),
headers={'content-type':'application/json'}
)
if response.status_code == 201:
print('Transfer Complete')
print response.json()
else:
print('Error Status Code: ' + str(response.status_code))
def getBalance(self, player):
pURL = 'http://api.reimaginebanking.com/accounts/{}?key={}'.format(player, self.apiKey)
response = requests.get(pURL)
if response.status_code == 200:
print('Successfully obtained account balance')
data = response.json()
bal = float(data['balance'])
return bal
else:
print('Error Status Code: ' + str(response.status_code))
# participants = [person1, person2, person3, person4, person5, person6]
#
# for assassin in participants:
# payload = {
# "type": "Checking",
# "nickname": assassin['Name'],
# "rewards": 0,
# "balance": 5,
# }
#
# # Create a Checking Account
# response = requests.post(
# gm.url,
# data=json.dumps(payload),
# headers={'content-type':'application/json'},
# )
#
# if response.status_code == 201:
# print('account created')
# else:
# print('Error Status Code: ' + str(response.status_code))