Module: Gitlab::Client::UserSnippets

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

Overview

Defines methods related to user snippets.

Instance Method Summary collapse

Instance Method Details

#create_user_snippet(options = {}) ⇒ Gitlab::ObjectifiedHash

Create a new snippet.

Examples:

Gitlab.create_user_snippet({ title: 'REST', file_name: 'api.rb', content: 'some code', description: 'Hello World snippet', visibility: 'public'})

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :title (String) — default: required

    Title of a snippet.

  • :file_name (String) — default: required

    Name of a snippet file.

  • :content (String) — default: required

    Content of a snippet.

  • :description (String) — default: optional

    Description of a snippet.

  • :visibility (String) — default: optional

    visibility of a snippet.

Returns:



54
55
56
# File 'lib/gitlab/client/user_snippets.rb', line 54

def create_user_snippet(options = {})
  post('/snippets', body: options)
end

#delete_user_snippet(id) ⇒ void

This method returns an undefined value.

Delete an existing snippet.

Examples:

Gitlab.delete_user_snippet(14)

Parameters:

  • id (Integer)

    ID of snippet to delete.



83
84
85
# File 'lib/gitlab/client/user_snippets.rb', line 83

def delete_user_snippet(id)
  delete("/snippets/#{id}")
end

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

Update an existing snippet.

Examples:

Gitlab.edit_user_snippet(34, { file_name: 'README.txt' })
Gitlab.edit_user_snippet(34, { file_name: 'README.txt', title: 'New title' })

Parameters:

  • id (Integer)

    ID of snippet to update.

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

    A customizable set of options.

Options Hash (options):

  • :title (String) — default: optional

    Title of a snippet.

  • :file_name (String) — default: optional

    Name of a snippet file.

  • :content (String) — default: optional

    Content of a snippet.

  • :description (String) — default: optional

    Description of a snippet.

  • :visibility (String) — default: optional

    visibility of a snippet.

Returns:



72
73
74
# File 'lib/gitlab/client/user_snippets.rb', line 72

def edit_user_snippet(id, options = {})
  put("/snippets/#{id}", body: options)
end

#public_snippets(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

List all public snippets.

Examples:

Gitlab.public_snippets
Gitlab.public_snippets(per_page: 2, page: 1)

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :per_page (String) — default: optional

    Number of snippets to return per page.

  • :page (String) — default: optional

    Page to retrieve.

Returns:



98
99
100
# File 'lib/gitlab/client/user_snippets.rb', line 98

def public_snippets(options = {})
  get('/snippets/public', query: options)
end

#snippet_user_agent_details(id) ⇒ Array<Gitlab::ObjectifiedHash>

Get user agent details for a snippet.

Examples:

Gitlab.snippet_user_agent_details(1)

Parameters:

  • id (Integer)

    ID of snippet to delete.

Returns:



110
111
112
# File 'lib/gitlab/client/user_snippets.rb', line 110

def snippet_user_agent_details(id)
  get("/snippets/#{id}/user_agent_detail")
end

#user_snippet(id) ⇒ Gitlab::ObjectifiedHash

Get a single snippet.

Examples:

Gitlab.user_snippet(1)

Parameters:

  • id (Integer)

    ID of snippet to retrieve.

Returns:



24
25
26
# File 'lib/gitlab/client/user_snippets.rb', line 24

def user_snippet(id)
  get("/snippets/#{id}")
end

#user_snippet_raw(id) ⇒ String

Get raw contents of a single snippet.

Examples:

Gitlab.user_snippet_raw(1)

Parameters:

  • id (Integer)

    ID of snippet to retrieve.

Returns:

  • (String)

    User snippet text



35
36
37
38
39
40
# File 'lib/gitlab/client/user_snippets.rb', line 35

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

#user_snippetsArray<Gitlab::ObjectifiedHash>

Get a list of the snippets of the current user.

Examples:

Gitlab.user_snippets

Returns:



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

def user_snippets
  get('/snippets')
end