@@ -1018,6 +1018,67 @@ class LicenseManager(BaseManager):
10181018 obj_cls = License
10191019
10201020
1021+ class Snippet (GitlabObject ):
1022+ _url = '/snippets'
1023+ _constructorTypes = {'author' : 'User' }
1024+ requiredCreateAttrs = ['title' , 'file_name' , 'content' ]
1025+ optionalCreateAttrs = ['lifetime' , 'visibility_level' ]
1026+ optionalUpdateAttrs = ['title' , 'file_name' , 'content' , 'visibility_level' ]
1027+ shortPrintAttr = 'title'
1028+
1029+ def content (self , streamed = False , action = None , chunk_size = 1024 , ** kwargs ):
1030+ """Return the raw content of a snippet.
1031+
1032+ Args:
1033+ streamed (bool): If True the data will be processed by chunks of
1034+ `chunk_size` and each chunk is passed to `action` for
1035+ treatment.
1036+ action (callable): Callable responsible of dealing with chunk of
1037+ data.
1038+ chunk_size (int): Size of each chunk.
1039+
1040+ Returns:
1041+ str: The snippet content
1042+
1043+ Raises:
1044+ GitlabConnectionError: If the server cannot be reached.
1045+ GitlabGetError: If the server fails to perform the request.
1046+ """
1047+ url = ("/snippets/%(snippet_id)s/raw" %
1048+ {'snippet_id' : self .id })
1049+ r = self .gitlab ._raw_get (url , ** kwargs )
1050+ raise_error_from_response (r , GitlabGetError )
1051+ return utils .response_content (r , streamed , action , chunk_size )
1052+
1053+
1054+ class SnippetManager (BaseManager ):
1055+ obj_cls = Snippet
1056+
1057+ def all (self , ** kwargs ):
1058+ """List all the snippets
1059+
1060+ Args:
1061+ all (bool): If True, return all the items, without pagination
1062+ **kwargs: Additional arguments to send to GitLab.
1063+
1064+ Returns:
1065+ list(gitlab.Gitlab.Snippet): The list of snippets.
1066+ """
1067+ return self .gitlab ._raw_list ("/snippets/public" , Snippet , ** kwargs )
1068+
1069+ def owned (self , ** kwargs ):
1070+ """List owned snippets.
1071+
1072+ Args:
1073+ all (bool): If True, return all the items, without pagination
1074+ **kwargs: Additional arguments to send to GitLab.
1075+
1076+ Returns:
1077+ list(gitlab.Gitlab.Snippet): The list of owned snippets.
1078+ """
1079+ return self .gitlab ._raw_list ("/snippets" , Snippet , ** kwargs )
1080+
1081+
10211082class Namespace (GitlabObject ):
10221083 _url = '/namespaces'
10231084 canGet = 'from_list'
0 commit comments