forked from freelancer/freelancer-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_users.py
68 lines (53 loc) · 1.68 KB
/
get_users.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
from freelancersdk.session import Session
from freelancersdk.resources.users.users import get_users, get_user_by_id
from freelancersdk.resources.users.helpers import (
create_get_users_object, create_get_users_details_object,
)
from freelancersdk.resources.users.exceptions import \
UsersNotFoundException
import os
import json
def sample_get_users():
url = os.environ.get('FLN_URL')
oauth_token = os.environ.get('FLN_OAUTH_TOKEN')
session = Session(oauth_token=oauth_token, url=url)
query = create_get_users_object(
user_ids=[
110013,
221202,
231203,
],
user_details=create_get_users_details_object(
basic=True,
profile_description=True,
reputation=True,
),
)
try:
p = get_users(session, query)
except UsersNotFoundException as e:
print(('Error message: {}'.format(e.message)))
print(('Server response: {}'.format(e.error_code)))
return None
else:
return p
def sample_get_user_by_id():
url = os.environ.get('FLN_URL')
oauth_token = os.environ.get('FLN_OAUTH_TOKEN')
session = Session(oauth_token=oauth_token, url=url)
try:
p = get_user_by_id(session, 110013)
except UserNotFoundException as e:
print(('Error message: {}'.format(e.message)))
print(('Server response: {}'.format(e.error_code)))
return None
else:
return p
print("Getting a list of users...")
p = sample_get_users()
if p:
print('Users found!\n{}'.format(json.dumps(p)))
print("Getting just a single user...")
p = sample_get_user_by_id()
if p:
print('User found!\n{}'.format(json.dumps(p)))