diff options
author | Guyzmo <guyzmo+github@m0g.net> | 2016-11-27 13:43:38 +0100 |
---|---|---|
committer | Guyzmo <guyzmo+github@m0g.net> | 2016-12-24 12:04:22 +0100 |
commit | 6022dfec44c67f7f45b0c3274f5eef02e8ac93f0 (patch) | |
tree | 42e07d92219cac401cb434142d90842b885ddaa8 /gitlab/objects.py | |
parent | 15d336256c0dca756e189fb9746ab60be2d3c886 (diff) | |
download | gitlab-6022dfec44c67f7f45b0c3274f5eef02e8ac93f0.tar.gz |
Added support for Snippets (new API in Gitlab 8.15)
cf [Gitlab-CE MR !6373](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6373)
Signed-off-by: Guyzmo <guyzmo+github@m0g.net>
Diffstat (limited to 'gitlab/objects.py')
-rw-r--r-- | gitlab/objects.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/gitlab/objects.py b/gitlab/objects.py index 4d1e7b8..dcf5d5c 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -1018,6 +1018,67 @@ class LicenseManager(BaseManager): obj_cls = License +class Snippet(GitlabObject): + _url = '/snippets' + _constructorTypes = {'author': 'User'} + requiredCreateAttrs = ['title', 'file_name', 'content'] + optionalCreateAttrs = ['lifetime', 'visibility_level'] + optionalUpdateAttrs = ['title', 'file_name', 'content', 'visibility_level'] + shortPrintAttr = 'title' + + def content(self, streamed=False, action=None, chunk_size=1024, **kwargs): + """Return the raw content of a snippet. + + Args: + streamed (bool): If True the data will be processed by chunks of + `chunk_size` and each chunk is passed to `action` for + treatment. + action (callable): Callable responsible of dealing with chunk of + data. + chunk_size (int): Size of each chunk. + + Returns: + str: The snippet content + + Raises: + GitlabConnectionError: If the server cannot be reached. + GitlabGetError: If the server fails to perform the request. + """ + url = ("/snippets/%(snippet_id)s/raw" % + {'snippet_id': self.id}) + r = self.gitlab._raw_get(url, **kwargs) + raise_error_from_response(r, GitlabGetError) + return utils.response_content(r, streamed, action, chunk_size) + + +class SnippetManager(BaseManager): + obj_cls = Snippet + + def all(self, **kwargs): + """List all the snippets + + Args: + all (bool): If True, return all the items, without pagination + **kwargs: Additional arguments to send to GitLab. + + Returns: + list(gitlab.Gitlab.Snippet): The list of snippets. + """ + return self.gitlab._raw_list("/snippets/public", Snippet, **kwargs) + + def owned(self, **kwargs): + """List owned snippets. + + Args: + all (bool): If True, return all the items, without pagination + **kwargs: Additional arguments to send to GitLab. + + Returns: + list(gitlab.Gitlab.Snippet): The list of owned snippets. + """ + return self.gitlab._raw_list("/snippets", Snippet, **kwargs) + + class Namespace(GitlabObject): _url = '/namespaces' canGet = 'from_list' |