Skip to content

Commit 986d85f

Browse files
committed
feat: added time zones to sdk
1 parent 9b7d3b5 commit 986d85f

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-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 the GetUsers function
22+
usersList, err := client.GetTimeZones()
23+
if err != nil {
24+
log.Fatalf("Error fetching users: %v", err)
25+
}
26+
27+
// Pretty print the user groups details in XML
28+
respJSON, err := json.MarshalIndent(usersList, "", " ") // Indent with 4 spaces
29+
if err != nil {
30+
log.Fatalf("Error marshaling user groups data: %v", err)
31+
}
32+
fmt.Println("User Groups Details:\n", string(respJSON))
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// jamfproapi_time_zones.go
2+
// Jamf Pro Api - Time Zones
3+
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v1-time-zones
4+
// Jamf Pro API requires the structs to support a JSON data structure.
5+
6+
package jamfpro
7+
8+
import (
9+
"fmt"
10+
)
11+
12+
const uriTimeZones = "/api/v1/time-zones"
13+
14+
// Resource structure
15+
type ResourceTimeZone struct {
16+
ZoneId string `json:"zoneId"`
17+
Region string `json:"region"`
18+
DisplayName string `json:"displayName"`
19+
}
20+
21+
// CRUD
22+
23+
// GetTimeZones retrieves the list of available time zones from Jamf Pro.
24+
func (c *Client) GetTimeZones() ([]ResourceTimeZone, error) {
25+
endpoint := uriTimeZones
26+
27+
var timeZones []ResourceTimeZone
28+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &timeZones)
29+
if err != nil {
30+
return nil, fmt.Errorf(errMsgFailedGet, "time zones", err)
31+
}
32+
33+
if resp != nil && resp.Body != nil {
34+
defer resp.Body.Close()
35+
}
36+
37+
return timeZones, nil
38+
}

0 commit comments

Comments
 (0)