Skip to content

Commit 9b7d3b5

Browse files
committed
feat: added locales to the SDK
1 parent bc96aed commit 9b7d3b5

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
// Define the path to the JSON configuration file
13+
configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client with the HTTP client configuration
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Call function to get log flushing settings
22+
logFlushingSettings, err := client.GetLocales()
23+
if err != nil {
24+
log.Fatalf("Error fetching locales settings: %v", err)
25+
}
26+
27+
// Pretty print the JSON
28+
response, err := json.MarshalIndent(logFlushingSettings, "", " ") // Indent with 4 spaces
29+
if err != nil {
30+
log.Fatalf("Error marshaling locales settings data: %v", err)
31+
}
32+
fmt.Println("Fetched locales settings:\n", string(response))
33+
}

sdk/jamfpro/jamfproapi_locales.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// jamfproapi_locales.go
2+
// Jamf Pro Api - Locales
3+
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v1-locales
4+
// Jamf Pro API requires the structs to support a JSON data structure.
5+
package jamfpro
6+
7+
import "fmt"
8+
9+
const uriLocales = "/api/v1/locales"
10+
11+
// ResourceLocale represents a single locale in Jamf Pro
12+
type ResourceLocale struct {
13+
Description string `json:"description"`
14+
Identifier string `json:"identifier"`
15+
}
16+
17+
// GetLocales retrieves all available locales from Jamf Pro
18+
func (c *Client) GetLocales() ([]ResourceLocale, error) {
19+
endpoint := uriLocales
20+
21+
var locales []ResourceLocale
22+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &locales)
23+
if err != nil {
24+
return nil, fmt.Errorf(errMsgFailedGet, "locales", err)
25+
}
26+
27+
if resp != nil && resp.Body != nil {
28+
defer resp.Body.Close()
29+
}
30+
31+
return locales, nil
32+
}

0 commit comments

Comments
 (0)