Skip to content

Commit

Permalink
added 'isRequired' parameter to doJsonRequest() and doRequest(), rena…
Browse files Browse the repository at this point in the history
…med 'b' to 'bytes' in some places, 'buffer' in others, renamed 'r' to 'request'
  • Loading branch information
JeffB42 committed Apr 8, 2021
1 parent acbaf89 commit 406cb7c
Show file tree
Hide file tree
Showing 41 changed files with 122 additions and 104 deletions.
6 changes: 3 additions & 3 deletions octoprintApis/BedOffsetRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type BedOffsetRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *BedOffsetRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := cmd.encode(b); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterToolApiUri, b, PrintToolErrors)
_, err := c.doJsonRequest("POST", PrinterToolApiUri, buffer, PrintToolErrors, true)
return err
}

Expand Down
8 changes: 4 additions & 4 deletions octoprintApis/BedStateRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ type BedStateRequest struct {
// Do sends an API request and returns the API response.
func (cmd *BedStateRequest) Do(c *Client) (*dataModels.TemperatureStateResponse, error) {
uri := fmt.Sprintf("%s?history=%t&limit=%d", PrinterBedApiUri, cmd.IncludeHistory, cmd.Limit)
b, err := c.doJsonRequest("GET", uri, nil, PrintBedErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, PrintBedErrors, true)
if err != nil {
return nil, err
}

r := &dataModels.TemperatureStateResponse{}
if err := json.Unmarshal(b, &r); err != nil {
response := &dataModels.TemperatureStateResponse{}
if err := json.Unmarshal(bytes, &response); err != nil {
return nil, err
}

return r, err
return response, err
}
6 changes: 3 additions & 3 deletions octoprintApis/BedTargetRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type BedTargetRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *BedTargetRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := cmd.encode(b); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterBedApiUri, b, PrintBedErrors)
_, err := c.doJsonRequest("POST", PrinterBedApiUri, buffer, PrintBedErrors, true)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/CancelRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func (cmd *CancelRequest) Do(c *Client) error {
return err
}

_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors)
_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true)
return err
}
6 changes: 3 additions & 3 deletions octoprintApis/CommandRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type CommandRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *CommandRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := json.NewEncoder(b).Encode(cmd); err != nil {
buffer := bytes.NewBuffer(nil)
if err := json.NewEncoder(buffer).Encode(cmd); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterCommandApiUri, b, nil)
_, err := c.doJsonRequest("POST", PrinterCommandApiUri, buffer, nil, true)
return err
}
6 changes: 3 additions & 3 deletions octoprintApis/ConnectRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ type ConnectRequest struct {
func (cmd *ConnectRequest) Do(client *Client) error {
logger.TraceEnter("ConnectRequest.Do()")

bytes := bytes.NewBuffer(nil)
if err := cmd.encode(bytes); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
logger.LogError("ConnectRequest.Do()", "cmd.encode()", err)
logger.TraceLeave("ConnectRequest.Do()")
return err
}

_, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors)
_, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true)
if err != nil {
logger.LogError("ConnectRequest.go()", "client.doJsonRequest(POST)", err)
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/ConnectionRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ConnectionRequest struct{}
func (cmd *ConnectionRequest) Do(client *Client) (*dataModels.ConnectionResponse, error) {
logger.TraceEnter("ConnectionRequest.Do()")

bytes, err := client.doJsonRequest("GET", ConnectionApiUri, nil, nil)
bytes, err := client.doJsonRequest("GET", ConnectionApiUri, nil, nil, true)
if err != nil {
logger.LogError("ConnectionRequest.Do()", "client.doJsonRequest(GET)", err)
logger.TraceLeave("ConnectionRequest.Do()")
Expand Down
8 changes: 4 additions & 4 deletions octoprintApis/CustomCommandsRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ type CustomCommandsRequest struct{}

// Do sends an API request and returns the API response.
func (cmd *CustomCommandsRequest) Do(c *Client) (*dataModels.CustomCommandsResponse, error) {
b, err := c.doJsonRequest("GET", PrinterCommandCustomApiUri, nil, nil)
bytes, err := c.doJsonRequest("GET", PrinterCommandCustomApiUri, nil, nil, true)
if err != nil {
return nil, err
}

r := &dataModels.CustomCommandsResponse{}
if err := json.Unmarshal(b, r); err != nil {
response := &dataModels.CustomCommandsResponse{}
if err := json.Unmarshal(bytes, response); err != nil {
return nil, err
}

return r, err
return response, err
}
2 changes: 1 addition & 1 deletion octoprintApis/DeleteFileRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type DeleteFileRequest struct {
// Do sends an API request and returns error if any.
func (req *DeleteFileRequest) Do(c *Client) error {
uri := fmt.Sprintf("%s/%s/%s", FilesApiUri, req.Location, req.Path)
if _, err := c.doJsonRequest("DELETE", uri, nil, FilesLocationDeleteErrors); err != nil {
if _, err := c.doJsonRequest("DELETE", uri, nil, FilesLocationDeleteErrors, true); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions octoprintApis/DisconnectRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ type DisconnectRequest struct{}
func (this *DisconnectRequest) Do(client *Client) error {
logger.TraceEnter("DisconnectRequest.Do()")

bytes := bytes.NewBuffer(nil)
if err := this.encode(bytes); err != nil {
buffer := bytes.NewBuffer(nil)
if err := this.encode(buffer); err != nil {
logger.LogError("DisconnectRequest.Do()", "this.encode(bytes)", err)
logger.TraceLeave("DisconnectRequest.Do()")
return err
}

_, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors)
_, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true)
if err != nil {
logger.LogError("DisconnectRequest.Do()", "client.doJsonRequest(POST)", err)
}
Expand Down
6 changes: 3 additions & 3 deletions octoprintApis/FakesAckRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ type FakesAckRequest struct{}
func (this *FakesAckRequest) Do(client *Client) error {
logger.TraceEnter("FakesAckRequest.Do()")

bytes := bytes.NewBuffer(nil)
if err := this.encode(bytes); err != nil {
buffer := bytes.NewBuffer(nil)
if err := this.encode(buffer); err != nil {
logger.LogError("FakesAckRequest.Do()", "this.encode(bytes)", err)
logger.TraceLeave("FakesAckRequest.Do()")
return err
}

_, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors)
_, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true)
if err != nil {
logger.LogError("FakesAckRequest.Do()", "client.doJsonRequest(POST)", err)
logger.LogError("main.findConfigFile()", "Current()", err)
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/FileRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (request *FileRequest) Do(c *Client) (*dataModels.FileResponse, error) {
request.Recursive,
)

bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors, true)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions octoprintApis/FilesRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ func (cmd *FilesRequest) Do(c *Client) (*dataModels.FilesResponse, error) {
uri = fmt.Sprintf("%s/%s?recursive=%t", FilesApiUri, cmd.Location, cmd.Recursive)
}

b, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors, true)
if err != nil {
return nil, err
}

r := &dataModels.FilesResponse{}
if err := json.Unmarshal(b, r); err != nil {
response := &dataModels.FilesResponse{}
if err := json.Unmarshal(bytes, response); err != nil {
return nil, err
}

if len(r.Children) > 0 {
r.Files = r.Children
if len(response.Children) > 0 {
response.Files = response.Children
}

return r, err
return response, err
}
2 changes: 1 addition & 1 deletion octoprintApis/FullStateRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (cmd *FullStateRequest) Do(c *Client) (*dataModels.FullStateResponse, error
*/


bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/JobRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type JobRequest struct{}

// Do sends an API request and returns the API response.
func (cmd *JobRequest) Do(client *Client) (*dataModels.JobResponse, error) {
bytes, err := client.doJsonRequest("GET", JobApiUri, nil, nil)
bytes, err := client.doJsonRequest("GET", JobApiUri, nil, nil, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/NotificationRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (this *NotificationRequest) Do(client *Client, uiState string) (*dataModels
}

target := fmt.Sprintf("%s?command=get_notification", PluginZBoltOctoScreenApiUri)
bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors)
bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/OctoScreenSettingsRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type OctoScreenSettingsRequest struct {

func (this *OctoScreenSettingsRequest) Do(client *Client, uiState string) (*dataModels.OctoScreenSettingsResponse, error) {
target := fmt.Sprintf("%s?command=get_settings", PluginZBoltOctoScreenApiUri)
bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors)
bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/PauseRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (cmd *PauseRequest) Do(c *Client) error {
return err
}

_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors)
_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/PluginManagerInfoRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (this *PluginManagerInfoRequest) Do(client *Client, uiState string) (*dataM
return nil, err
}

bytes, err := client.doJsonRequest("GET", pluginManagerRequestURI, params, ConnectionErrors)
bytes, err := client.doJsonRequest("GET", pluginManagerRequestURI, params, ConnectionErrors, true)
if err != nil {
logger.LogError("PluginManagerInfoRequest.Do()", "client.doJsonRequest()", err)
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions octoprintApis/PrintHeadHomeRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type PrintHeadHomeRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *PrintHeadHomeRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := cmd.encode(b); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, b, PrintHeadJobErrors)
_, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, buffer, PrintHeadJobErrors, true)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions octoprintApis/PrintHeadJogRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ type PrintHeadJogRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *PrintHeadJogRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := cmd.encode(b); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, b, PrintHeadJobErrors)
_, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, buffer, PrintHeadJobErrors, true)

return err
}
Expand Down
8 changes: 4 additions & 4 deletions octoprintApis/PrinterProfilesRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ type PrinterProfilesRequest struct {
// Do sends an API request and returns the API response.
func (cmd *PrinterProfilesRequest) Do(c *Client) (*dataModels.PrinterProfileResponse, error) {
uri := fmt.Sprintf("/api/printerprofiles/%s", cmd.Id)
b, err := c.doJsonRequest("GET", uri, nil, nil)
bytes, err := c.doJsonRequest("GET", uri, nil, nil, true)
if err != nil {
return nil, err
}

r := &dataModels.PrinterProfileResponse{}
if err := json.Unmarshal(b, r); err != nil {
response := &dataModels.PrinterProfileResponse{}
if err := json.Unmarshal(bytes, response); err != nil {
return nil, err
}

return r, err
return response, err
}
2 changes: 1 addition & 1 deletion octoprintApis/RestartRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ func (cmd *RestartRequest) Do(c *Client) error {
return err
}

_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors)
_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true)
return err
}
6 changes: 3 additions & 3 deletions octoprintApis/RunZOffsetCalibrationRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ type RunZOffsetCalibrationRequest struct {
func (this *RunZOffsetCalibrationRequest) Do(client *Client) error {
this.Command = "run_zoffset_calibration"

bytes := bytes.NewBuffer(nil)
if err := json.NewEncoder(bytes).Encode(this); err != nil {
buffer := bytes.NewBuffer(nil)
if err := json.NewEncoder(buffer).Encode(this); err != nil {
logger.LogError("RunZOffsetCalibrationRequest.Do()", "json.NewEncoder(params).Encode(this)", err)
return err
}

_, err := client.doJsonRequest("POST", PluginZBoltOctoScreenApiUri, bytes, ConnectionErrors)
_, err := client.doJsonRequest("POST", PluginZBoltOctoScreenApiUri, buffer, ConnectionErrors, true)
return err
}
9 changes: 5 additions & 4 deletions octoprintApis/SdStateRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ type SdStateRequest struct{}

// Do sends an API request and returns the API response.
func (cmd *SdStateRequest) Do(c *Client) (*dataModels.SdState, error) {
b, err := c.doJsonRequest("GET", PrinterSdApiUri, nil, PrintSdErrors)
bytes, err := c.doJsonRequest("GET", PrinterSdApiUri, nil, PrintSdErrors, true)
if err != nil {
return nil, err
}

r := &dataModels.SdState{}
if err := json.Unmarshal(b, r); err != nil {
// TODO: rename SdState to SdStateResponse or something.
response := &dataModels.SdState{}
if err := json.Unmarshal(bytes, response); err != nil {
return nil, err
}

return r, err
return response, err
}
6 changes: 3 additions & 3 deletions octoprintApis/SelectFileRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ type SelectFileRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *SelectFileRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := cmd.encode(b); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
return err
}

uri := fmt.Sprintf("%s/%s/%s", FilesApiUri, cmd.Location, cmd.Path)
_, err := c.doJsonRequest("POST", uri, b, FilesLocationPathPOSTErrors)
_, err := c.doJsonRequest("POST", uri, buffer, FilesLocationPathPOSTErrors, true)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/StartRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func (cmd *StartRequest) Do(c *Client) error {
return err
}

_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors)
_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true)
return err
}
2 changes: 1 addition & 1 deletion octoprintApis/TemperatureDataRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (cmd *TemperatureDataRequest) Do(c *Client) (*dataModels.TemperatureDataRes
*/


bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors, true)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 406cb7c

Please sign in to comment.