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('gitlab',
  {:title => 'REST', :file_name => 'api.rb', :code => 'some code'})

Parameters:

  • project (Integer, String)

    The ID or code name of a project.

  • 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.

Returns:



30
31
32
# File 'lib/gitlab/client/snippets.rb', line 30

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

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

Deletes a snippet.

Examples:

Gitlab.delete_snippet(2, 14)
Gitlab.delete_snippet('gitlab', 34)

Parameters:

  • project (Integer, String)

    The ID or code name of a project.

  • id (Integer)

    The ID of a snippet.

Returns:



60
61
62
# File 'lib/gitlab/client/snippets.rb', line 60

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

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

Updates a snippet.

Examples:

Gitlab.edit_snippet('gitlab', 34, :file_name => 'README.txt')

Parameters:

  • project (Integer, String)

    The ID or code 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.

Returns:



47
48
49
# File 'lib/gitlab/client/snippets.rb', line 47

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

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

Gets information about a snippet.

Examples:

Gitlab.snippet(2, 14)
Gitlab.snippet('gitlab', 34)

Parameters:

  • project (Integer, String)

    The ID or code name of a project.

  • id (Integer)

    The ID of a snippet.

Returns:



13
14
15
# File 'lib/gitlab/client/snippets.rb', line 13

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