...

Source file src/github.com/xanzy/go-gitlab/broadcast_messages.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Sander van Harmelen
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  	"time"
    23  )
    24  
    25  // BroadcastMessagesService handles communication with the broadcast
    26  // messages methods of the GitLab API.
    27  //
    28  // GitLab API docs: https://docs.gitlab.com/ee/api/broadcast_messages.html
    29  type BroadcastMessagesService struct {
    30  	client *Client
    31  }
    32  
    33  // BroadcastMessage represents a GitLab issue board.
    34  //
    35  // GitLab API docs:
    36  // https://docs.gitlab.com/ee/api/broadcast_messages.html#get-all-broadcast-messages
    37  type BroadcastMessage struct {
    38  	Message            string             `json:"message"`
    39  	StartsAt           *time.Time         `json:"starts_at"`
    40  	EndsAt             *time.Time         `json:"ends_at"`
    41  	Font               string             `json:"font"`
    42  	ID                 int                `json:"id"`
    43  	Active             bool               `json:"active"`
    44  	TargetAccessLevels []AccessLevelValue `json:"target_access_levels"`
    45  	TargetPath         string             `json:"target_path"`
    46  	BroadcastType      string             `json:"broadcast_type"`
    47  	Dismissable        bool               `json:"dismissable"`
    48  
    49  	// Deprecated: This parameter was removed in GitLab 15.6.
    50  	Color string `json:"color"`
    51  }
    52  
    53  // ListBroadcastMessagesOptions represents the available ListBroadcastMessages()
    54  // options.
    55  //
    56  // GitLab API docs:
    57  // https://docs.gitlab.com/ee/api/broadcast_messages.html#get-all-broadcast-messages
    58  type ListBroadcastMessagesOptions ListOptions
    59  
    60  // ListBroadcastMessages gets a list of all broadcasted messages.
    61  //
    62  // GitLab API docs:
    63  // https://docs.gitlab.com/ee/api/broadcast_messages.html#get-all-broadcast-messages
    64  func (s *BroadcastMessagesService) ListBroadcastMessages(opt *ListBroadcastMessagesOptions, options ...RequestOptionFunc) ([]*BroadcastMessage, *Response, error) {
    65  	req, err := s.client.NewRequest(http.MethodGet, "broadcast_messages", opt, options)
    66  	if err != nil {
    67  		return nil, nil, err
    68  	}
    69  
    70  	var bs []*BroadcastMessage
    71  	resp, err := s.client.Do(req, &bs)
    72  	if err != nil {
    73  		return nil, resp, err
    74  	}
    75  
    76  	return bs, resp, nil
    77  }
    78  
    79  // GetBroadcastMessage gets a single broadcast message.
    80  //
    81  // GitLab API docs:
    82  // https://docs.gitlab.com/ee/api/broadcast_messages.html#get-a-specific-broadcast-message
    83  func (s *BroadcastMessagesService) GetBroadcastMessage(broadcast int, options ...RequestOptionFunc) (*BroadcastMessage, *Response, error) {
    84  	u := fmt.Sprintf("broadcast_messages/%d", broadcast)
    85  
    86  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
    87  	if err != nil {
    88  		return nil, nil, err
    89  	}
    90  
    91  	b := new(BroadcastMessage)
    92  	resp, err := s.client.Do(req, &b)
    93  	if err != nil {
    94  		return nil, resp, err
    95  	}
    96  
    97  	return b, resp, nil
    98  }
    99  
   100  // CreateBroadcastMessageOptions represents the available CreateBroadcastMessage()
   101  // options.
   102  //
   103  // GitLab API docs:
   104  // https://docs.gitlab.com/ee/api/broadcast_messages.html#create-a-broadcast-message
   105  type CreateBroadcastMessageOptions struct {
   106  	Message            *string            `url:"message" json:"message"`
   107  	StartsAt           *time.Time         `url:"starts_at,omitempty" json:"starts_at,omitempty"`
   108  	EndsAt             *time.Time         `url:"ends_at,omitempty" json:"ends_at,omitempty"`
   109  	Font               *string            `url:"font,omitempty" json:"font,omitempty"`
   110  	TargetAccessLevels []AccessLevelValue `url:"target_access_levels,omitempty" json:"target_access_levels,omitempty"`
   111  	TargetPath         *string            `url:"target_path,omitempty" json:"target_path,omitempty"`
   112  	BroadcastType      *string            `url:"broadcast_type,omitempty" json:"broadcast_type,omitempty"`
   113  	Dismissable        *bool              `url:"dismissable,omitempty" json:"dismissable,omitempty"`
   114  
   115  	// Deprecated: This parameter was removed in GitLab 15.6.
   116  	Color *string `url:"color,omitempty" json:"color,omitempty"`
   117  }
   118  
   119  // CreateBroadcastMessage creates a message to broadcast.
   120  //
   121  // GitLab API docs:
   122  // https://docs.gitlab.com/ee/api/broadcast_messages.html#create-a-broadcast-message
   123  func (s *BroadcastMessagesService) CreateBroadcastMessage(opt *CreateBroadcastMessageOptions, options ...RequestOptionFunc) (*BroadcastMessage, *Response, error) {
   124  	req, err := s.client.NewRequest(http.MethodPost, "broadcast_messages", opt, options)
   125  	if err != nil {
   126  		return nil, nil, err
   127  	}
   128  
   129  	b := new(BroadcastMessage)
   130  	resp, err := s.client.Do(req, &b)
   131  	if err != nil {
   132  		return nil, resp, err
   133  	}
   134  
   135  	return b, resp, nil
   136  }
   137  
   138  // UpdateBroadcastMessageOptions represents the available CreateBroadcastMessage()
   139  // options.
   140  //
   141  // GitLab API docs:
   142  // https://docs.gitlab.com/ee/api/broadcast_messages.html#update-a-broadcast-message
   143  type UpdateBroadcastMessageOptions struct {
   144  	Message            *string            `url:"message,omitempty" json:"message,omitempty"`
   145  	StartsAt           *time.Time         `url:"starts_at,omitempty" json:"starts_at,omitempty"`
   146  	EndsAt             *time.Time         `url:"ends_at,omitempty" json:"ends_at,omitempty"`
   147  	Font               *string            `url:"font,omitempty" json:"font,omitempty"`
   148  	TargetAccessLevels []AccessLevelValue `url:"target_access_levels,omitempty" json:"target_access_levels,omitempty"`
   149  	TargetPath         *string            `url:"target_path,omitempty" json:"target_path,omitempty"`
   150  	BroadcastType      *string            `url:"broadcast_type,omitempty" json:"broadcast_type,omitempty"`
   151  	Dismissable        *bool              `url:"dismissable,omitempty" json:"dismissable,omitempty"`
   152  
   153  	// Deprecated: This parameter was removed in GitLab 15.6.
   154  	Color *string `url:"color,omitempty" json:"color,omitempty"`
   155  }
   156  
   157  // UpdateBroadcastMessage update a broadcasted message.
   158  //
   159  // GitLab API docs:
   160  // https://docs.gitlab.com/ee/api/broadcast_messages.html#update-a-broadcast-message
   161  func (s *BroadcastMessagesService) UpdateBroadcastMessage(broadcast int, opt *UpdateBroadcastMessageOptions, options ...RequestOptionFunc) (*BroadcastMessage, *Response, error) {
   162  	u := fmt.Sprintf("broadcast_messages/%d", broadcast)
   163  
   164  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   165  	if err != nil {
   166  		return nil, nil, err
   167  	}
   168  
   169  	b := new(BroadcastMessage)
   170  	resp, err := s.client.Do(req, &b)
   171  	if err != nil {
   172  		return nil, resp, err
   173  	}
   174  
   175  	return b, resp, nil
   176  }
   177  
   178  // DeleteBroadcastMessage deletes a broadcasted message.
   179  //
   180  // GitLab API docs:
   181  // https://docs.gitlab.com/ee/api/broadcast_messages.html#delete-a-broadcast-message
   182  func (s *BroadcastMessagesService) DeleteBroadcastMessage(broadcast int, options ...RequestOptionFunc) (*Response, error) {
   183  	u := fmt.Sprintf("broadcast_messages/%d", broadcast)
   184  
   185  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   186  	if err != nil {
   187  		return nil, err
   188  	}
   189  
   190  	return s.client.Do(req, nil)
   191  }
   192  

View as plain text