Class SnippetsApi

  • All Implemented Interfaces:
    Constants

    public class SnippetsApi
    extends AbstractApi
    This class provides an entry point to all the GitLab Snippets API project calls.
    • Constructor Detail

      • SnippetsApi

        public SnippetsApi​(GitLabApi gitLabApi)
    • Method Detail

      • getSnippets

        public List<Snippet> getSnippets​(boolean downloadContent)
                                  throws GitLabApiException
        Get a list of the authenticated user's snippets.
        GitLab Endpoint: GET /snippets
        Parameters:
        downloadContent - indicating whether to download the snippet content
        Returns:
        a list of authenticated user's snippets
        Throws:
        GitLabApiException - if any exception occurs
      • getSnippets

        public List<Snippet> getSnippets()
                                  throws GitLabApiException
        Get a list of the authenticated user's snippets.
        GitLab Endpoint: GET /snippets
        Returns:
        a list of authenticated user's snippets
        Throws:
        GitLabApiException - if any exception occurs
      • getSnippets

        public Pager<Snippet> getSnippets​(int itemsPerPage)
                                   throws GitLabApiException
        Get a Pager of the authenticated user's snippets.
        GitLab Endpoint: GET /snippets
        Parameters:
        itemsPerPage - the number of snippets per page
        Returns:
        the Pager of snippets
        Throws:
        GitLabApiException - if any exception occurs
      • getSnippetsStream

        public Stream<Snippet> getSnippetsStream()
                                          throws GitLabApiException
        Get a Stream of the authenticated user's snippets.
        GitLab Endpoint: GET /snippets
        Returns:
        a Stream of authenticated user's snippets
        Throws:
        GitLabApiException - if any exception occurs
      • getSnippetContent

        public String getSnippetContent​(Integer snippetId)
                                 throws GitLabApiException
        Get the content of a Snippet.
        GitLab Endpoint: GET /snippets/:id/raw
        Parameters:
        snippetId - the snippet ID to remove
        Returns:
        the content of snippet
        Throws:
        GitLabApiException - if any exception occurs
      • getSnippet

        public Snippet getSnippet​(Integer snippetId,
                                  boolean downloadContent)
                           throws GitLabApiException
        Get a specific Snippet.
        Parameters:
        snippetId - the snippet ID to get
        downloadContent - indicating whether to download the snippet content
        Returns:
        the snippet with the given id
        Throws:
        GitLabApiException - if any exception occurs
      • getSnippet

        public Snippet getSnippet​(Integer snippetId)
                           throws GitLabApiException
        Get a specific Snippet.
        Parameters:
        snippetId - the snippet ID to get
        Returns:
        the snippet with the given id
        Throws:
        GitLabApiException - if any exception occurs
      • getOptionalSnippet

        public Optional<Snippet> getOptionalSnippet​(Integer snippetId)
        Get a specific snippet as an Optional instance.
        GitLab Endpoint: GET /snippets/:snippet_id
        Parameters:
        snippetId - the ID of the snippet to get the Optional instance for
        Returns:
        the specified Snippet as an Optional instance
      • getOptionalSnippet

        public Optional<Snippet> getOptionalSnippet​(Integer snippetId,
                                                    boolean downloadContent)
        Get a specific snippet as an Optional instance.
        GitLab Endpoint: GET /snippets/:snippet_id
        Parameters:
        snippetId - the ID of the snippet to get the Optional instance for
        downloadContent - indicating whether to download the snippet content
        Returns:
        the specified Snippet as an Optional instance
      • createSnippet

        public Snippet createSnippet​(String title,
                                     String fileName,
                                     String content)
                              throws GitLabApiException
        Create a new Snippet.
        Parameters:
        title - the title of the snippet
        fileName - the file name of the snippet
        content - the content of the snippet
        Returns:
        the created Snippet
        Throws:
        GitLabApiException - if any exception occurs
      • createSnippet

        public Snippet createSnippet​(String title,
                                     String fileName,
                                     String content,
                                     Visibility visibility,
                                     String description)
                              throws GitLabApiException
        Create a new Snippet.
        Parameters:
        title - the title of the snippet
        fileName - the file name of the snippet
        content - the content of the snippet
        visibility - the visibility (Public, Internal, Private) of the snippet
        description - the description of the snippet
        Returns:
        the created Snippet
        Throws:
        GitLabApiException - if any exception occurs
      • deleteSnippet

        public void deleteSnippet​(Integer snippetId)
                           throws GitLabApiException
        Removes Snippet.
        GitLab Endpoint: DELETE /snippets/:id
        Parameters:
        snippetId - the snippet ID to remove
        Throws:
        GitLabApiException - if any exception occurs