-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Máximo Cuadros <[email protected]>
- Loading branch information
Showing
4 changed files
with
349 additions
and
1 deletion.
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,23 @@ | ||
package octoprint | ||
|
||
import "encoding/json" | ||
|
||
const URISettings = "/api/settings" | ||
|
||
// SettingsRequest retrieves the current configuration of OctoPrint. | ||
type SettingsRequest struct{} | ||
|
||
// Do sends an API request and returns the API response. | ||
func (cmd *SettingsRequest) Do(c *Client) (*Settings, error) { | ||
b, err := c.doJSONRequest("GET", URISettings, nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
r := &Settings{} | ||
if err := json.Unmarshal(b, r); err != nil { | ||
return nil, err | ||
} | ||
|
||
return r, err | ||
} |
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,17 @@ | ||
package octoprint | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSettingsRequest_Do(t *testing.T) { | ||
cli := NewClient("http://localhost:5000", "") | ||
|
||
r := &SettingsRequest{} | ||
settings, err := r.Do(cli) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, settings.API.Enabled, true) | ||
} |