Module: Gitlab::Client::Snippets

Included in:
Gitlab::Client
Defined in:
lib/gitlab/client/snippets.rb

Overview

Defines methods related to snippets.

Instance Method Summary collapse

Instance Method Details

#create_snippet(project, options = {}) ⇒ Gitlab::ObjectifiedHash

Creates a new snippet.

Examples:

Gitlab.create_snippet(42, { title: 'REST', file_name: 'api.rb', code: 'some code', visibility: 'public'})

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :title (String) — default: required

    The title of a snippet.

  • :file_name (String) — default: required

    The name of a snippet file.

  • :code (String) — default: required

    The content of a snippet.

  • :lifetime (String) — default: optional

    The expiration date of a snippet.

  • :visibility (String) — default: required

    The visibility of a snippet

Returns:



44
45
46
# File 'lib/gitlab/client/snippets.rb', line 44

def create_snippet(project, options={})
  post("/projects/#{url_encode project}/snippets", body: options)
end

#delete_snippet(project, id) ⇒ Gitlab::ObjectifiedHash

Deletes a snippet.

Examples:

Gitlab.delete_snippet(2, 14)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a snippet.

Returns:



74
75
76
# File 'lib/gitlab/client/snippets.rb', line 74

def delete_snippet(project, id)
  delete("/projects/#{url_encode project}/snippets/#{id}")
end

#edit_snippet(project, id, options = {}) ⇒ Gitlab::ObjectifiedHash

Updates a snippet.

Examples:

Gitlab.edit_snippet(42, 34, { file_name: 'README.txt' })

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a snippet.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :title (String)

    The title of a snippet.

  • :file_name (String)

    The name of a snippet file.

  • :code (String)

    The content of a snippet.

  • :lifetime (String)

    The expiration date of a snippet.

  • :visibility (String) — default: optional

    The visibility of a snippet

Returns:



62
63
64
# File 'lib/gitlab/client/snippets.rb', line 62

def edit_snippet(project, id, options={})
  put("/projects/#{url_encode project}/snippets/#{id}", body: options)
end

#snippet(project, id) ⇒ Gitlab::ObjectifiedHash

Gets information about a snippet.

Examples:

Gitlab.snippet(2, 14)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a snippet.

Returns:



27
28
29
# File 'lib/gitlab/client/snippets.rb', line 27

def snippet(project, id)
  get("/projects/#{url_encode project}/snippets/#{id}")
end

#snippet_content(project, id) ⇒ Gitlab::ObjectifiedHash

Returns raw project snippet content as plain text.

Examples:

Gitlab.snippet_content(2, 14)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a snippet.

Returns:



86
87
88
89
90
91
# File 'lib/gitlab/client/snippets.rb', line 86

def snippet_content(project, id)
  get("/projects/#{url_encode project}/snippets/#{id}/raw",
      format: nil,
      headers: { Accept: 'text/plain' },
      parser: ::Gitlab::Request::Parser)
end

#snippets(project, options = {}) ⇒ Gitlab::ObjectifiedHash

Gets a list of project’s snippets.

Examples:

Gitlab.snippets(42)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



15
16
17
# File 'lib/gitlab/client/snippets.rb', line 15

def snippets(project, options={})
  get("/projects/#{url_encode project}/snippets", query: options)
end