File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ import json
2+ import socket
3+
4+ import requests
5+
6+ from bunq .sdk .context import ApiContext , ApiEnvironmentType
7+ from bunq .sdk .exception import BunqException
8+ from bunq .sdk .model .generated import endpoint
9+
10+ _ERROR_COULD_NOT_CREATE_NEW_SANDBOX_USER = "Could not create new sandbox" \
11+ " user."
12+
13+
14+ def automatic_sandbox_install (file_path = None ):
15+ sandbox_user = __generate_new_sandbox_user ()
16+ ApiContext (
17+ ApiEnvironmentType .SANDBOX ,
18+ sandbox_user .api_key ,
19+ socket .gethostname ()
20+ ).save (file_path )
21+
22+
23+ def __generate_new_sandbox_user ():
24+ """
25+ :rtype: endpoint.SandboxUser
26+ """
27+
28+ url = "https://sandbox.public.api.bunq.com/v1/sandbox-user"
29+
30+ headers = {
31+ 'x-bunq-client-request-id' : "uniqueness-is-required" ,
32+ 'cache-control' : "no-cache" ,
33+ 'x-bunq-geolocation' : "0 0 0 0 NL" ,
34+ 'x-bunq-language' : "en_US" ,
35+ 'x-bunq-region' : "en_US" ,
36+ }
37+
38+ response = requests .request ("POST" , url , headers = headers )
39+
40+ if response .status_code is 200 :
41+ response_json = json .loads (response .text )
42+ return endpoint .SandboxUser .from_json (
43+ json .dumps (response_json ["Response" ][0 ]["ApiKey" ]))
44+
45+ raise BunqException (_ERROR_COULD_NOT_CREATE_NEW_SANDBOX_USER )
You can’t perform that action at this time.
0 commit comments