-
-
Notifications
You must be signed in to change notification settings - Fork 400
Added BroadcastMessages API #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NARKOZ
merged 2 commits into
NARKOZ:master
from
akashdotsrivastava:436-broadcast_messages_api
Nov 20, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "message":"Deploy in progress", | ||
| "starts_at":"2016-08-24T23:21:16.078Z", | ||
| "ends_at":"2016-08-26T23:21:16.080Z", | ||
| "color":"#cecece", | ||
| "font":"#FFFFFF", | ||
| "id":1, | ||
| "active":false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [ | ||
| { | ||
| "message":"Example broadcast message", | ||
| "starts_at":"2016-08-24T23:21:16.078Z", | ||
| "ends_at":"2016-08-26T23:21:16.080Z", | ||
| "color":"#E75E40", | ||
| "font":"#FFFFFF", | ||
| "id":1, | ||
| "active": false | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'spec_helper' | ||
|
|
||
| describe Gitlab::Client do | ||
| describe '.broadcast_messages' do | ||
| before do | ||
| stub_get('/broadcast_messages', 'broadcast_messages') | ||
| @broadcast_messages = Gitlab.broadcast_messages | ||
| end | ||
|
|
||
| it 'gets the correct resource' do | ||
| expect(a_get('/broadcast_messages')).to have_been_made | ||
| end | ||
|
|
||
| it 'returns a paginated response of broadcast messages' do | ||
| expect(@broadcast_messages).to be_a Gitlab::PaginatedResponse | ||
| end | ||
| end | ||
|
|
||
| describe '.broadcast_message' do | ||
| before do | ||
| stub_get('/broadcast_messages/1', 'broadcast_message') | ||
| @broadcast_message = Gitlab.broadcast_message(1) | ||
| end | ||
|
|
||
| it 'gets the correct resource' do | ||
| expect(a_get('/broadcast_messages/1')).to have_been_made | ||
| end | ||
|
|
||
| it 'returns correct information about the broadcast message' do | ||
| expect(@broadcast_message.id).to eq 1 | ||
| end | ||
| end | ||
|
|
||
| describe '.create_broadcast_message' do | ||
| before do | ||
| stub_post('/broadcast_messages', 'broadcast_message') | ||
| @broadcast_message = Gitlab.create_broadcast_message('Deploy in progress', color: '#cecece') | ||
| end | ||
|
|
||
| it 'gets the correct resource' do | ||
| expect(a_post('/broadcast_messages') | ||
| .with(body: { message: 'Deploy in progress', color: '#cecece' })).to have_been_made | ||
| end | ||
|
|
||
| it 'returns correct information about the broadcast message created' do | ||
| expect(@broadcast_message.message).to eq 'Deploy in progress' | ||
| expect(@broadcast_message.color).to eq '#cecece' | ||
| end | ||
| end | ||
|
|
||
| describe '.edit_broadcast_message' do | ||
| before do | ||
| stub_put('/broadcast_messages/1', 'broadcast_message') | ||
| @broadcast_message = Gitlab.edit_broadcast_message(1, font: '#FFFFFF') | ||
| end | ||
|
|
||
| it 'gets the correct resource' do | ||
| expect(a_put('/broadcast_messages/1') | ||
| .with(body: { font: '#FFFFFF' })).to have_been_made | ||
| end | ||
|
|
||
| it 'returns correct information about the edited broadcast message' do | ||
| expect(@broadcast_message.font).to eq '#FFFFFF' | ||
| end | ||
| end | ||
|
|
||
| describe '.delete_broadcast_message' do | ||
| before do | ||
| stub_delete('/broadcast_messages/1', 'empty') | ||
| @broadcast_message = Gitlab.delete_broadcast_message(1) | ||
| end | ||
|
|
||
| it 'gets the correct resource' do | ||
| expect(a_delete('/broadcast_messages/1')).to have_been_made | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space before the parenthesis