diff options
author | JeffB42 <10328858+JeffB42@users.noreply.github.com> | 2021-04-18 01:05:24 +0300 |
---|---|---|
committer | JeffB42 <10328858+JeffB42@users.noreply.github.com> | 2021-04-18 01:05:24 +0300 |
commit | f042bffa9d621ee791db360a7ee9140408d39e70 (patch) | |
tree | e808df3107a796b685aaeb17df52bbfd2a8c3ed1 | |
parent | ab5baa1c9a028ec7de143b69f92aa356173103e3 (diff) |
moved SystemExecuteCommandRequest into its own file
-rw-r--r-- | octoprintApis/SystemExecuteCommandRequest.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/octoprintApis/SystemExecuteCommandRequest.go b/octoprintApis/SystemExecuteCommandRequest.go new file mode 100644 index 0000000..13eb51e --- /dev/null +++ b/octoprintApis/SystemExecuteCommandRequest.go @@ -0,0 +1,35 @@ +package octoprintApis + +import ( + // "encoding/json" + "fmt" + + "github.com/Z-Bolt/OctoScreen/logger" + "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" +) + + +var ExecuteErrors = StatusMapping { + 404: "The command could not be found for source and action", + 500: "The command didn’t define a command to execute, the command returned a non-zero return code and ignore was not true or some other internal server error occurred", +} + +// SystemExecuteCommandRequest retrieves all configured system commands. +type SystemExecuteCommandRequest struct { + // Source for which to list commands. + Source dataModels.CommandSource `json:"source"` + + // Action is the identifier of the command, action from its definition. + Action string `json:"action"` +} + +// Do sends an API request and returns an error if any. +func (this *SystemExecuteCommandRequest) Do(client *Client) error { + uri := fmt.Sprintf("%s/%s/%s", SystemCommandsApiUri, this.Source, this.Action) + _, err := client.doJsonRequest("POST", uri, nil, ExecuteErrors, true) + if err != nil { + logger.LogError("SystemExecuteCommandRequest.Do()", "client.doJsonRequest(POST)", err) + } + + return err +} |