11"""This module contains the methods that the user will use directly to interact with MapRoulette users"""
22
3- import json
43from maproulette .api .maproulette_server import MapRouletteServer
54
65
@@ -9,3 +8,58 @@ class User(MapRouletteServer):
98
109 def __init__ (self , config ):
1110 super ().__init__ (configuration = config )
11+
12+ def find_user_by_username (self , username , limit = 10 , page = 0 ):
13+ """Method to search for a user based on a specific username
14+
15+ :param username: the username to search for.
16+ :param limit: the limit to the number of results returned in the response. Default is 10
17+ :param page: used in conjunction with the limit parameter to page through X number of responses. Default is 0.
18+ :returns: the API response from the GET request
19+ """
20+ query_params = {
21+ "limit" : str (limit ),
22+ "page" : str (page )
23+ }
24+ response = self .get (
25+ endpoint = f"/users/find/{ username } " ,
26+ params = query_params
27+ )
28+ return response
29+
30+ def add_user_to_project (self , user_id , project_id , group_type , is_osm_user_id = 'true' ):
31+ """Method to add a user to a project group
32+
33+ :param user_id: the user ID to add to the specified project group
34+ :param project_id: the ID of the project
35+ :param group_type: the group type to add the user to (1 - Admin, 2 - Write, 3 - Read)
36+ :param is_osm_user_id: whether or not the specified user ID is an OSM user ID. Default is 'false'.
37+ :returns: the API response from the POST request
38+ """
39+ query_params = {
40+ "isOSMUserId" : str (is_osm_user_id )
41+ }
42+ response = self .post (
43+ endpoint = f"/user/{ user_id } /project/{ project_id } /{ group_type } " ,
44+ params = query_params
45+ )
46+ return response
47+
48+ def add_user_list_to_project (self , user_ids , project_id , group_type , is_osm_user_id = 'true' ):
49+ """Method to add a user to a project group
50+
51+ :param user_ids: a list of user IDs to add to the specified project group. IDs should be integers.
52+ :param project_id: the ID of the project
53+ :param group_type: the group type to add the user to (1 - Admin, 2 - Write, 3 - Read)
54+ :param is_osm_user_id: whether or not the specified user ID is an OSM user ID. Default is 'false'.
55+ :returns: the API response from the PUT request
56+ """
57+ query_params = {
58+ "isOSMUserId" : str (is_osm_user_id )
59+ }
60+ response = self .put (
61+ endpoint = f"/user/project/{ project_id } /{ group_type } " ,
62+ params = query_params ,
63+ body = user_ids
64+ )
65+ return response
0 commit comments