@@ -142,7 +142,6 @@ class QueryMultiple:
142142 """
143143 A QueryMultiple runs a query against a connection. The results can be iterated or fetched in bulk.
144144 """
145-
146145 def __init__ (self , connection , object_type , url_params = None , query_params = None ):
147146 # type: (Connection, str, list, dict) -> None
148147 """
@@ -234,16 +233,18 @@ class UsersQuery(QueryMultiple):
234233 Query for users meeting (optional) criteria
235234 """
236235
237- def __init__ (self , connection , in_group = "" , in_domain = "" ):
236+ def __init__ (self , connection , in_group = "" , in_domain = "" , identity_type = "" ):
238237 """
239238 Create a query for all users, or for those in a group or domain or both
240239 :param connection: Connection to run the query against
241240 :param in_group: (optional) name of the group to restrict the query to
242241 :param in_domain: (optional) name of the domain to restrict the query to
243242 """
244243 groups = [in_group ] if in_group else []
245- domains = {"domain" : in_domain } if in_domain else {}
246- QueryMultiple .__init__ (self , connection = connection , object_type = "user" , url_params = groups , query_params = domains )
244+ params = {}
245+ if in_domain : params ["domain" ] = str (in_domain )
246+ if identity_type : params ["type" ] = str (identity_type )
247+ QueryMultiple .__init__ (self , connection = connection , object_type = "user" , url_params = groups , query_params = params )
247248
248249
249250class GroupsQuery (QueryMultiple ):
@@ -257,3 +258,59 @@ def __init__(self, connection):
257258 :param connection: Connection to run the query against
258259 """
259260 QueryMultiple .__init__ (self , connection = connection , object_type = "group" )
261+
262+ class QuerySingle :
263+ """
264+ Look for a single object
265+ """
266+ def __init__ (self , connection , object_type , url_params = None , query_params = None ):
267+ # type: (Connection, str, list, dict) -> None
268+ """
269+ Provide the connection and query parameters when you create the query.
270+
271+ :param connection: The Connection to run the query against
272+ :param object_type: The type of object being queried (e.g., "user" or "group")
273+ :param url_params: Query qualifiers that go in the URL path (e.g., a group name when querying users)
274+ :param query_params: Query qualifiers that go in the query string (e.g., a domain name)
275+ """
276+ self .conn = connection
277+ self .object_type = object_type
278+ self .url_params = url_params if url_params else []
279+ self .query_params = query_params if query_params else {}
280+ self ._result = None
281+
282+ def reload (self ):
283+ """
284+ Rerun the query (lazily).
285+ The result will contain a value on the server side that have changed since the last run.
286+ :return: None
287+ """
288+ self ._result = None
289+
290+ def _fetch_result (self ):
291+ """
292+ Fetch the queried object.
293+ """
294+ self ._result = self .conn .query_single (self .object_type , self .url_params , self .query_params )
295+
296+ def result (self ):
297+ """
298+ Fetch the result, if we haven't already or if reload has been called.
299+ :return: the result object of the query.
300+ """
301+ if self ._result is None :
302+ self ._fetch_result ()
303+ return self ._result
304+
305+ class UserQuery (QuerySingle ):
306+ """
307+ Query for a single user
308+ """
309+
310+ def __init__ (self , connection , email ):
311+ """
312+ Create a query for the user with the given email
313+ :param connection: Connection to run the query against
314+ :param email: email of user to query for
315+ """
316+ QuerySingle .__init__ (self , connection = connection , object_type = "user" , url_params = [str (email )])
0 commit comments