File: broadcast_messages.rb

package info (click to toggle)
ruby-gitlab 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,660 kB
  • sloc: ruby: 12,582; makefile: 7; sh: 4
file content (75 lines) | stat: -rw-r--r-- 2,922 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true

class Gitlab::Client
  # Defines methods related to broadcast messages (only accessible to administrators).
  # @see https://docs.gitlab.com/ce/api/broadcast_messages.html
  module BroadcastMessages
    # Get all broadcast messages
    #
    # @example
    #   Gitlab.broadcast_messages
    #
    # @return [Array<Gitlab::ObjectifiedHash>]
    def broadcast_messages
      get('/broadcast_messages')
    end

    # Get a specific broadcast message
    #
    # @example
    #   Gitlab.broadcast_message(3)
    #
    # @param  [Integer] id The ID of broadcast message
    # @return [Gitlab::ObjectifiedHash]
    def broadcast_message(id)
      get("/broadcast_messages/#{id}")
    end

    # Create a broadcast message.
    #
    # @example
    #   Gitlab.create_broadcast_message('Mayday')
    #   Gitlab.create_broadcast_message('Mayday', {starts_at: Time.zone.now, ends_at: Time.zone.now + 30.minutes, color: '#cecece', font: '#FFFFFF'})
    #
    # @param  [String] message Message to display
    # @param  [Hash] options A customizable set of options.
    # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time)
    # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time)
    # @option options [String] :color(optional) Background color hex code
    # @option options [String] :font(optional) Foreground color hex code
    # @return [Gitlab::ObjectifiedHash] Information about created broadcast message.
    def create_broadcast_message(message, options = {})
      body = { message: message }.merge(options)
      post('/broadcast_messages', body: body)
    end

    # Update a broadcast message
    #
    # @example
    #   Gitlab.edit_broadcast_message(6, { message: 'No Mayday' })
    #   Gitlab.edit_broadcast_message(6, { font: '#FEFEFE' })
    #
    # @param  [Integer] id The ID of a broadcast message
    # @param  [Hash] options A customizable set of options.
    # @option options [String] :message(optional) Message to display
    # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time)
    # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time)
    # @option options [String] :color(optional) Background color hex code
    # @option options [String] :font(optional) Foreground color hex code
    # @return [Gitlab::ObjectifiedHash] Information about updated broadcast message.
    def edit_broadcast_message(id, options = {})
      put("/broadcast_messages/#{id}", body: options)
    end

    # Delete a broadcast message.
    #
    # @example
    #   Gitlab.delete_broadcast_message(3)
    #
    # @param  [Integer] id The ID of a broadcast message.
    # @return [nil] This API call returns an empty response body.
    def delete_broadcast_message(id)
      delete("/broadcast_messages/#{id}")
    end
  end
end