Skip to content

Commit fdad4da

Browse files
authored
Merge pull request #41 from deploymenttheory/dev
+ ebooks sdk coverage with examples
2 parents 07e88ba + 391cb56 commit fdad4da

File tree

12 files changed

+897
-3
lines changed

12 files changed

+897
-3
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,44 @@ This documentation provides details on the API endpoints available for managing
677677
- [x] ✅ **DELETE** `/JSSResource/dockitems/name/{name}`
678678
`DeleteDockItemsByName` deletes a dock item by its name.
679679
680+
### Jamf Pro Classic API - eBooks
681+
682+
This documentation provides details on the API endpoints available for managing dock items within Jamf Pro using the Classic API, which requires XML data structure support.
683+
684+
## Endpoints
685+
686+
- [x] ✅ **GET** `/JSSResource/ebooks`
687+
`GetEbooks` retrieves a serialized list of all ebooks.
688+
689+
- [x] ✅ **GET** `/JSSResource/ebooks/id/{id}`
690+
`GetEbooksByID` fetches a single ebook by its ID.
691+
692+
- [x] ✅ **GET** `/JSSResource/ebooks/name/{name}`
693+
`GetEbooksByName` retrieves an ebook by its name.
694+
695+
- [x] ✅ **GET** `/JSSResource/ebooks/name/{name}/subset/{subset}`
696+
`GetEbooksByNameAndDataSubset` retrieves a specific subset (General, Scope, or SelfService) of an ebook by its name.
697+
698+
- [x] ✅ **POST** `/JSSResource/ebooks/id/0`
699+
`CreateEbook` creates a new ebook with the provided details. The ID `0` in the endpoint indicates creation.
700+
701+
- [x] ✅ **PUT** `/JSSResource/ebooks/id/{id}`
702+
`UpdateEbookByID` updates an existing ebook by its ID.
703+
704+
- [x] ✅ **PUT** `/JSSResource/ebooks/name/{name}`
705+
`UpdateEbookByName` updates an existing ebook by its name.
706+
707+
- [x] ✅ **DELETE** `/JSSResource/ebooks/id/{id}`
708+
`DeleteEbookByID` deletes an ebook by its ID.
709+
710+
- [x] ✅ **DELETE** `/JSSResource/ebooks/name/{name}`
711+
`DeleteEbookByName` deletes an ebook by its name.
712+
680713
681714
## Progress Summary
682715
683-
- Total Endpoints: 235
684-
- Covered: 216
716+
- Total Endpoints: 244
717+
- Covered: 225
685718
- Not Covered: 19
686719
- Partially Covered: 0
687720
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
9+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
10+
)
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
15+
16+
// Load the client OAuth credentials from the configuration file
17+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
20+
}
21+
22+
// Instantiate the default logger and set the desired log level
23+
logger := http_client.NewDefaultLogger()
24+
logLevel := http_client.LogLevelDebug
25+
26+
// Configuration for the jamfpro client
27+
config := jamfpro.Config{
28+
InstanceName: authConfig.InstanceName,
29+
LogLevel: logLevel,
30+
Logger: logger,
31+
ClientID: authConfig.ClientID,
32+
ClientSecret: authConfig.ClientSecret,
33+
}
34+
35+
// Create a new jamfpro client instance
36+
client, err := jamfpro.NewClient(config)
37+
if err != nil {
38+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
39+
}
40+
41+
// Define the ebook to be created
42+
newEbook := jamfpro.ResponseEbooks{
43+
General: jamfpro.EbooksDataSubsetGeneral{
44+
Name: "iPhone User Guide for iOS 10.3",
45+
Author: "Apple Inc.",
46+
Version: "1",
47+
Free: true,
48+
URL: "https://itunes.apple.com/us/book/iphone-user-guide-for-ios-10-3/id1134772174?mt=11&uo=4",
49+
DeploymentType: "Install Automatically/Prompt Users to Install",
50+
FileType: "PDF",
51+
DeployAsManaged: true,
52+
Category: jamfpro.EbooksDataSubsetCategory{ID: -1, Name: "Unknown"},
53+
Site: jamfpro.EbooksDataSubsetSite{ID: -1, Name: "None"},
54+
},
55+
// Add Scope and SelfService if needed
56+
}
57+
58+
// Call CreateEbook function
59+
createdEbook, err := client.CreateEbook(newEbook)
60+
if err != nil {
61+
log.Fatalf("Error creating ebook: %v", err)
62+
}
63+
64+
// Pretty print the created ebook in XML
65+
ebookXML, err := xml.MarshalIndent(createdEbook, "", " ")
66+
if err != nil {
67+
log.Fatalf("Error marshaling ebook data: %v", err)
68+
}
69+
fmt.Println("Created Ebook:\n", string(ebookXML))
70+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client"
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
13+
14+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
15+
if err != nil {
16+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
17+
}
18+
19+
logger := http_client.NewDefaultLogger()
20+
logLevel := http_client.LogLevelDebug
21+
22+
config := jamfpro.Config{
23+
InstanceName: authConfig.InstanceName,
24+
LogLevel: logLevel,
25+
Logger: logger,
26+
ClientID: authConfig.ClientID,
27+
ClientSecret: authConfig.ClientSecret,
28+
}
29+
30+
client, err := jamfpro.NewClient(config)
31+
if err != nil {
32+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
33+
}
34+
35+
ebookID := 1 // Replace with the actual eBook ID
36+
37+
err = client.DeleteEbookByID(ebookID)
38+
if err != nil {
39+
log.Fatalf("Error deleting ebook by ID: %v", err)
40+
}
41+
42+
fmt.Println("Ebook successfully deleted by ID")
43+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
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/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
14+
15+
// Load the client OAuth credentials from the configuration file
16+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
19+
}
20+
21+
// Instantiate the default logger and set the desired log level
22+
logger := http_client.NewDefaultLogger()
23+
logLevel := http_client.LogLevelDebug
24+
25+
// Configuration for the jamfpro client
26+
config := jamfpro.Config{
27+
InstanceName: authConfig.InstanceName,
28+
LogLevel: logLevel,
29+
Logger: logger,
30+
ClientID: authConfig.ClientID,
31+
ClientSecret: authConfig.ClientSecret,
32+
}
33+
34+
// Create a new jamfpro client instance
35+
client, err := jamfpro.NewClient(config)
36+
if err != nil {
37+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
38+
}
39+
40+
ebookName := "iPhone User Guide for iOS 10.3" // Replace with the actual eBook name
41+
42+
err = client.DeleteEbookByName(ebookName)
43+
if err != nil {
44+
log.Fatalf("Error deleting ebook by Name: %v", err)
45+
}
46+
47+
fmt.Println("Ebook successfully deleted by Name")
48+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client"
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
// Define the path to the JSON configuration file for OAuth credentials
13+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
14+
15+
// Load the client OAuth credentials from the configuration file
16+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
19+
}
20+
21+
// Configuration for the jamfpro client
22+
config := jamfpro.Config{
23+
InstanceName: authConfig.InstanceName,
24+
LogLevel: http_client.LogLevelDebug,
25+
Logger: http_client.NewDefaultLogger(),
26+
ClientID: authConfig.ClientID,
27+
ClientSecret: authConfig.ClientSecret,
28+
}
29+
30+
// Create a new jamfpro client instance
31+
client, err := jamfpro.NewClient(config)
32+
if err != nil {
33+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
34+
}
35+
36+
// Call the GetEbooks function
37+
ebooks, err := client.GetEbooks()
38+
if err != nil {
39+
log.Fatalf("Error fetching eBooks: %v", err)
40+
}
41+
42+
// Output the fetched eBooks
43+
fmt.Printf("Fetched eBooks: %+v\n", ebooks)
44+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
9+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
10+
)
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
15+
16+
// Load the client OAuth credentials from the configuration file
17+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
20+
}
21+
22+
// Instantiate the default logger and set the desired log level
23+
logger := http_client.NewDefaultLogger()
24+
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
25+
26+
// Configuration for the jamfpro
27+
config := jamfpro.Config{
28+
InstanceName: authConfig.InstanceName,
29+
LogLevel: logLevel,
30+
Logger: logger,
31+
ClientID: authConfig.ClientID,
32+
ClientSecret: authConfig.ClientSecret,
33+
}
34+
35+
// Create a new jamfpro client instance
36+
client, err := jamfpro.NewClient(config)
37+
if err != nil {
38+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
39+
}
40+
41+
// Define the department ID you want to retrieve
42+
eBooksID := 1 // Replace with the desired department ID
43+
44+
// Call GetEbooksByID function
45+
ebook, err := client.GetEbooksByID(eBooksID)
46+
if err != nil {
47+
log.Fatalf("Error fetching department by ID: %v", err)
48+
}
49+
50+
// Pretty print the department in XML
51+
ebookXML, err := xml.MarshalIndent(ebook, "", " ") // Indent with 4 spaces
52+
if err != nil {
53+
log.Fatalf("Error marshaling ebooks data: %v", err)
54+
}
55+
fmt.Println("Fetched Ebook:\n", string(ebookXML))
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
9+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
10+
)
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
15+
16+
// Load the client OAuth credentials from the configuration file
17+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
20+
}
21+
22+
// Instantiate the default logger and set the desired log level
23+
logger := http_client.NewDefaultLogger()
24+
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
25+
26+
// Configuration for the jamfpro
27+
config := jamfpro.Config{
28+
InstanceName: authConfig.InstanceName,
29+
LogLevel: logLevel,
30+
Logger: logger,
31+
ClientID: authConfig.ClientID,
32+
ClientSecret: authConfig.ClientSecret,
33+
}
34+
35+
// Create a new jamfpro client instance
36+
client, err := jamfpro.NewClient(config)
37+
if err != nil {
38+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
39+
}
40+
41+
// Define the name of the ebook you want to retrieve
42+
ebookName := "iPhone User Guide for iOS 10.3" // Replace with the desired ebook name
43+
44+
// Call GetEbooksByName function
45+
ebook, err := client.GetEbooksByName(ebookName)
46+
if err != nil {
47+
log.Fatalf("Error fetching ebook by name: %v", err)
48+
}
49+
50+
// Pretty print the ebook in XML
51+
ebookXML, err := xml.MarshalIndent(ebook, "", " ") // Indent with 4 spaces
52+
if err != nil {
53+
log.Fatalf("Error marshaling ebook data: %v", err)
54+
}
55+
fmt.Println("Fetched Ebook:\n", string(ebookXML))
56+
}

0 commit comments

Comments
 (0)