-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.py
58 lines (46 loc) · 1.39 KB
/
example.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
import getpass
import logging
import sys
from pprint import pprint
from drf_client.connection import Api as RestApi
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger(__name__)
username = input("Email? ")
password = getpass.getpass()
options = {
"DOMAIN": "http://127.0.0.1:8000",
"API_PREFIX": "api/v1",
"TOKEN_TYPE": "jwt",
"TOKEN_FORMAT": "JWT {token}",
"USERNAME_KEY": "username",
"LOGIN": "auth/login/",
"LOGOUT": "auth/logout/",
"USE_DASHES": False,
"SESSION_TRIES": 3,
"SESSION_TIMEOUT": None,
"SESSION_VERIFY": False,
}
c = RestApi(options)
ok = c.login(username=username, password=password)
if ok:
# GET some data
my_objects = c.org.get()
for obj in my_objects["results"]:
pprint(obj)
logger.info("------------------------------")
logger.info("------------------------------")
logger.info("------------------------------")
# If the URL includes "-", add under parenthesis:
# GET: /api/v1/someresource/some-path/
my_object = c.someresource("some-path").get()
pprint(my_object)
logger.info("------------------------------")
logger.info("------------------------------")
payload = {
"data1": "val1",
"data2": "val2",
}
resp = c.someresource.post(data=payload)
pprint(resp)
logger.info("------------------------------")
c.logout()