22
33from __future__ import annotations
44
5- from typing import List , Optional , overload
5+ from collections import defaultdict
6+ from typing import TYPE_CHECKING , List , Optional , overload
67
78
89from requests import Session
1314from .bundles import Bundles
1415from .permissions import Permissions
1516from .resources import Resources , Resource
16- from .users import Users
1717
1818
1919class ContentItemOwner (Resource ):
20- """Owner information ."""
20+ """Content item owner resource ."""
2121
2222 @property
2323 def guid (self ) -> str :
@@ -153,6 +153,8 @@ def owner(self) -> ContentItemOwner:
153153 # It is possible to get a content item that does not contain owner.
154154 # "owner" is an optional additional request param.
155155 # If it's not included, we can retrieve the information by `owner_guid`
156+ from .users import Users
157+
156158 self ["owner" ] = Users (self .config , self .session ).get (
157159 self .owner_guid
158160 )
@@ -442,12 +444,41 @@ def update(self, *args, **kwargs) -> None:
442444
443445
444446class Content (Resources ):
445- """Content resource."""
447+ """Content resource.
448+
449+ Parameters
450+ ----------
451+ config : Config
452+ Configuration object.
453+ session : Session
454+ Requests session object.
455+ owner_guid : str, optional
456+ Content item owner identifier. Filters results to those owned by a specific user (the default is None, which implies not filtering results on owner identifier).
457+ """
446458
447- def __init__ (self , config : Config , session : Session ) -> None :
459+ def __init__ (
460+ self ,
461+ config : Config ,
462+ session : Session ,
463+ * ,
464+ owner_guid : str | None = None ,
465+ ) -> None :
448466 self .url = urls .append (config .url , "v1/content" )
449467 self .config = config
450468 self .session = session
469+ self .owner_guid = owner_guid
470+
471+ def _get_default_params (self ) -> dict :
472+ """Build default parameters for GET requests.
473+
474+ Returns
475+ -------
476+ dict
477+ """
478+ params = {}
479+ if self .owner_guid :
480+ params ["owner_guid" ] = self .owner_guid
481+ return params
451482
452483 def count (self ) -> int :
453484 """Count the number of content items.
@@ -456,8 +487,7 @@ def count(self) -> int:
456487 -------
457488 int
458489 """
459- results = self .session .get (self .url ).json ()
460- return len (results )
490+ return len (self .find ())
461491
462492 @overload
463493 def create (
@@ -600,18 +630,19 @@ def find(
600630 -------
601631 List[ContentItem]
602632 """
603- params = dict (* args , include = include , ** kwargs )
633+ params = self ._get_default_params ()
634+ params .update (args )
635+ params .update (kwargs )
636+ params ["include" ] = include
604637 response = self .session .get (self .url , params = params )
605- results = response .json ()
606- items = (
638+ return [
607639 ContentItem (
608640 config = self .config ,
609641 session = self .session ,
610642 ** result ,
611643 )
612- for result in results
613- )
614- return [item for item in items ]
644+ for result in response .json ()
645+ ]
615646
616647 @overload
617648 def find_one (
0 commit comments