-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from barracksiot/BO-1555
Bo 1555 - Add get and update hook commands
- Loading branch information
Showing
14 changed files
with
698 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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,4 @@ | ||
#!/usr/bin/env node | ||
|
||
const GetHookCommand = require('../commands/hook/GetHookCommand'); | ||
new GetHookCommand().render(); |
This file contains 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,4 @@ | ||
#!/usr/bin/env node | ||
|
||
const UpdateHook = require('../commands/hook/UpdateHookCommand'); | ||
new UpdateHook().render(); |
This file contains 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 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 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 |
---|---|---|
|
@@ -77,7 +77,6 @@ class HTTPClient { | |
pageableStream.lastPage(); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = HTTPClient; |
This file contains 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 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,20 @@ | ||
const BarracksCommand = require('../BarracksCommand'); | ||
|
||
class GetHookCommand extends BarracksCommand { | ||
|
||
configureCommand(program) { | ||
return program.arguments('<hook-name>'); | ||
} | ||
|
||
validateCommand(program) { | ||
return !!(program.args && program.args.length === 1); | ||
} | ||
|
||
execute(program) { | ||
return this.getAuthenticationToken().then(token => { | ||
return this.barracks.getHook(token, program.args[0]); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = GetHookCommand; |
This file contains 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,41 @@ | ||
const BarracksCommand = require('../BarracksCommand'); | ||
|
||
function buildNewHook(currentHook, program) { | ||
return Object.assign({}, currentHook, { | ||
name: program.newName || currentHook.name, | ||
url: program.url || currentHook.url | ||
}); | ||
} | ||
|
||
class UpdateHookCommand extends BarracksCommand { | ||
|
||
configureCommand(program) { | ||
return program | ||
.option('--name [hookName]', 'The unique name of the webhook') | ||
.option('--newName [newHookName]', '(Optionnal) A new unique name for the webhook') | ||
.option('--url [newUrl]', '(Optionnal) A new URL for this webhook'); | ||
} | ||
|
||
validateCommand(program) { | ||
return !!( | ||
program.name && program.name !== true && | ||
( | ||
(program.newName && program.newName !== true) || | ||
(program.url && program.url !== true) | ||
) | ||
); | ||
} | ||
|
||
execute(program) { | ||
let token; | ||
return this.getAuthenticationToken().then(authToken => { | ||
token = authToken; | ||
return this.barracks.getHook(token, program.name); | ||
}).then(hook => { | ||
const newHook = buildNewHook(hook, program); | ||
return this.barracks.updateHook(token, program.name, newHook); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = UpdateHookCommand; |
This file contains 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
Oops, something went wrong.