Skip to content

Commit 0ea6555

Browse files
committed
feat: add microsoft_mac_apps_version_tracker
1 parent 0f0d252 commit 0ea6555

File tree

18 files changed

+1914
-0
lines changed

18 files changed

+1914
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"log"
8+
9+
msapps "github.com/deploymenttheory/go-api-sdk-apple/microsoft_mac_apps_version_tracker"
10+
"github.com/deploymenttheory/go-api-sdk-apple/microsoft_mac_apps_version_tracker/services/apps"
11+
)
12+
13+
func main() {
14+
fmt.Println("=== Microsoft Mac Apps - Get App By Bundle ID Example ===")
15+
fmt.Println()
16+
17+
// Create a new client with default configuration
18+
client, err := msapps.NewClient(nil)
19+
if err != nil {
20+
log.Fatalf("Failed to create client: %v", err)
21+
}
22+
defer client.Close()
23+
24+
ctx := context.Background()
25+
26+
// Example 1: Find Microsoft Excel by bundle ID
27+
fmt.Println("=== Example 1: Find Microsoft Excel ===")
28+
29+
excel, err := client.Apps.GetAppByBundleID(ctx, apps.BundleIDExcel)
30+
if err != nil {
31+
log.Fatalf("Error finding Excel: %v", err)
32+
}
33+
34+
fmt.Printf("Found: %s\n", excel.Name)
35+
fmt.Printf("Bundle ID: %s\n", excel.BundleID)
36+
fmt.Printf("Version: %s\n", excel.Version)
37+
fmt.Printf("Package ID: %s\n", excel.PackageID)
38+
fmt.Printf("Download URL: %s\n", excel.DownloadURL)
39+
fmt.Printf("Direct URL: %s\n", excel.DirectURL)
40+
fmt.Printf("Size: %.2f MB (%.2f GB)\n", excel.SizeMB, excel.SizeMB/1024)
41+
fmt.Printf("SHA256: %s\n", excel.SHA256)
42+
fmt.Printf("ETag: %s\n", excel.ETag)
43+
44+
if excel.InstallKB != nil {
45+
fmt.Printf("Install Size: %d KB (%.2f MB)\n", *excel.InstallKB, float64(*excel.InstallKB)/1024)
46+
}
47+
if excel.NumFiles != nil {
48+
fmt.Printf("Number of Files: %d\n", *excel.NumFiles)
49+
}
50+
51+
// Display components
52+
if excel.ComponentCount > 0 {
53+
fmt.Printf("\nBundled Components (%d):\n", excel.ComponentCount)
54+
for _, comp := range excel.Components {
55+
fmt.Printf(" - %s (v%s)\n", comp.Name, comp.Version)
56+
if comp.BundleID != nil {
57+
fmt.Printf(" Bundle ID: %s\n", *comp.BundleID)
58+
}
59+
fmt.Printf(" Package ID: %s\n", comp.PackageID)
60+
}
61+
}
62+
63+
// Example 2: Find Microsoft Teams
64+
fmt.Println("\n=== Example 2: Find Microsoft Teams ===")
65+
66+
teams, err := client.Apps.GetAppByBundleID(ctx, apps.BundleIDTeams)
67+
if err != nil {
68+
log.Printf("Error finding Teams: %v", err)
69+
} else {
70+
fmt.Printf("Found: %s\n", teams.Name)
71+
fmt.Printf("Version: %s\n", teams.Version)
72+
fmt.Printf("Bundle ID: %s\n", teams.BundleID)
73+
fmt.Printf("Size: %.2f MB\n", teams.SizeMB)
74+
fmt.Printf("Download URL: %s\n", teams.DownloadURL)
75+
76+
if len(teams.Components) > 0 {
77+
fmt.Printf("\nComponents:\n")
78+
for _, comp := range teams.Components {
79+
fmt.Printf(" - %s (v%s)\n", comp.Name, comp.Version)
80+
}
81+
}
82+
}
83+
84+
// Example 3: Check for multiple specific applications
85+
fmt.Println("\n=== Example 3: Check Multiple Applications ===")
86+
87+
appsToCheck := []struct {
88+
name string
89+
bundleID string
90+
}{
91+
{"Excel", apps.BundleIDExcel},
92+
{"Word", apps.BundleIDWord},
93+
{"PowerPoint", apps.BundleIDPowerPoint},
94+
{"Outlook", apps.BundleIDOutlook},
95+
{"Teams", apps.BundleIDTeams},
96+
{"OneDrive", apps.BundleIDOneDrive},
97+
{"Defender", apps.BundleIDDefender},
98+
{"VS Code", apps.BundleIDVSCode},
99+
{"Edge", apps.BundleIDEdge},
100+
{"Company Portal", apps.BundleIDCompanyPortal},
101+
}
102+
103+
fmt.Println("Checking for common Microsoft applications:")
104+
for _, appInfo := range appsToCheck {
105+
app, err := client.Apps.GetAppByBundleID(ctx, appInfo.bundleID)
106+
if err != nil {
107+
fmt.Printf(" ✗ %s: Not found\n", appInfo.name)
108+
} else {
109+
fmt.Printf(" ✓ %s: v%s (%.2f MB)\n", app.Name, app.Version, app.SizeMB)
110+
}
111+
}
112+
113+
// Example 4: Find apps with specific components
114+
fmt.Println("\n=== Example 4: Find Apps with AutoUpdate ===")
115+
116+
allApps, err := client.Apps.GetLatestApps(ctx)
117+
if err != nil {
118+
log.Printf("Error getting apps: %v", err)
119+
} else {
120+
fmt.Println("Applications bundled with Microsoft AutoUpdate:")
121+
for _, app := range allApps.Apps {
122+
for _, comp := range app.Components {
123+
if comp.BundleID != nil && *comp.BundleID == apps.BundleIDAutoUpdate {
124+
fmt.Printf(" - %s (v%s) includes AutoUpdate v%s\n",
125+
app.Name,
126+
app.Version,
127+
comp.Version)
128+
break
129+
}
130+
}
131+
}
132+
}
133+
134+
// Example 5: Try to find a non-existent app (error handling)
135+
fmt.Println("\n=== Example 5: Error Handling ===")
136+
137+
_, err = client.Apps.GetAppByBundleID(ctx, "com.nonexistent.app")
138+
if err != nil {
139+
fmt.Printf("Expected error: %v\n", err)
140+
}
141+
142+
// Example 6: Pretty print full JSON response
143+
fmt.Println("\n=== Example 6: Full JSON Response ===")
144+
145+
jsonData, err := json.MarshalIndent(excel, "", " ")
146+
if err != nil {
147+
log.Printf("Error marshaling response to JSON: %v", err)
148+
} else {
149+
fmt.Println(string(jsonData))
150+
}
151+
152+
fmt.Println("\n=== Example Complete ===")
153+
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"log"
8+
"time"
9+
10+
msapps "github.com/deploymenttheory/go-api-sdk-apple/microsoft_mac_apps_version_tracker"
11+
"github.com/deploymenttheory/go-api-sdk-apple/microsoft_mac_apps_version_tracker/services/apps"
12+
)
13+
14+
func main() {
15+
fmt.Println("=== Microsoft Mac Apps - Get App By Name Example ===")
16+
fmt.Println()
17+
18+
// Create a new client with default configuration
19+
client, err := msapps.NewClient(nil)
20+
if err != nil {
21+
log.Fatalf("Failed to create client: %v", err)
22+
}
23+
defer client.Close()
24+
25+
ctx := context.Background()
26+
27+
// Example 1: Find Microsoft Teams by name
28+
fmt.Println("=== Example 1: Find Microsoft Teams ===")
29+
30+
teams, err := client.Apps.GetAppByName(ctx, apps.AppNameTeams)
31+
if err != nil {
32+
log.Fatalf("Error finding Teams: %v", err)
33+
}
34+
35+
fmt.Printf("Found: %s\n", teams.Name)
36+
fmt.Printf("Bundle ID: %s\n", teams.BundleID)
37+
fmt.Printf("Version: %s\n", teams.Version)
38+
fmt.Printf("Size: %.2f MB (%.2f GB)\n", teams.SizeMB, teams.SizeMB/1024)
39+
fmt.Printf("Package ID: %s\n", teams.PackageID)
40+
fmt.Printf("Download URL: %s\n", teams.DownloadURL)
41+
fmt.Printf("Direct URL: %s\n", teams.DirectURL)
42+
43+
// Display components
44+
if len(teams.Components) > 0 {
45+
fmt.Printf("\nBundled Components (%d):\n", teams.ComponentCount)
46+
for _, comp := range teams.Components {
47+
fmt.Printf(" - %s (v%s)\n", comp.Name, comp.Version)
48+
}
49+
}
50+
51+
// Display timestamps
52+
detected, err := teams.ParseDetectedTime()
53+
if err == nil {
54+
fmt.Printf("\nDetected: %s\n", detected.Format("2006-01-02 15:04:05"))
55+
}
56+
57+
lastModified, err := teams.ParseLastModifiedTime()
58+
if err == nil {
59+
fmt.Printf("Last Modified: %s\n", lastModified.Format("2006-01-02 15:04:05"))
60+
}
61+
62+
// Example 2: Find Microsoft Defender
63+
fmt.Println("\n=== Example 2: Find Defender for Mac ===")
64+
65+
defender, err := client.Apps.GetAppByName(ctx, apps.AppNameDefender)
66+
if err != nil {
67+
log.Printf("Error finding Defender: %v", err)
68+
} else {
69+
fmt.Printf("Found: %s\n", defender.Name)
70+
fmt.Printf("Version: %s\n", defender.Version)
71+
fmt.Printf("Bundle ID: %s\n", defender.BundleID)
72+
fmt.Printf("Size: %.2f MB\n", defender.SizeMB)
73+
74+
// Show DLP components
75+
if len(defender.Components) > 0 {
76+
fmt.Printf("\nDefender includes %d components:\n", len(defender.Components))
77+
for _, comp := range defender.Components {
78+
fmt.Printf(" - %s (v%s)\n", comp.Name, comp.Version)
79+
}
80+
}
81+
}
82+
83+
// Example 3: Find Office 365 Suite
84+
fmt.Println("\n=== Example 3: Find Office 365 for Mac ===")
85+
86+
office, err := client.Apps.GetAppByName(ctx, apps.AppNameOffice365)
87+
if err != nil {
88+
log.Printf("Error finding Office 365: %v", err)
89+
} else {
90+
fmt.Printf("Found: %s\n", office.Name)
91+
fmt.Printf("Version: %s\n", office.Version)
92+
fmt.Printf("Size: %.2f GB\n", office.SizeMB/1024)
93+
fmt.Printf("\nOffice 365 Suite includes:\n")
94+
for _, comp := range office.Components {
95+
if comp.BundleID != nil {
96+
fmt.Printf(" - %s (v%s)\n", comp.Name, comp.Version)
97+
}
98+
}
99+
}
100+
101+
// Example 4: Check for multiple apps by name
102+
fmt.Println("\n=== Example 4: Check Multiple Applications ===")
103+
104+
appNames := []string{
105+
apps.AppNameExcel,
106+
apps.AppNameWord,
107+
apps.AppNamePowerPoint,
108+
apps.AppNameOutlook,
109+
apps.AppNameOneNote,
110+
apps.AppNameTeams,
111+
apps.AppNameOneDrive,
112+
apps.AppNameEdge,
113+
apps.AppNameVSCode,
114+
}
115+
116+
fmt.Println("Checking for Microsoft applications:")
117+
for _, appName := range appNames {
118+
app, err := client.Apps.GetAppByName(ctx, appName)
119+
if err != nil {
120+
fmt.Printf(" ✗ %s: Not found\n", appName)
121+
} else {
122+
fmt.Printf(" ✓ %s: v%s\n", app.Name, app.Version)
123+
}
124+
}
125+
126+
// Example 5: Compare versions and timestamps
127+
fmt.Println("\n=== Example 5: Version and Update Analysis ===")
128+
129+
allApps, err := client.Apps.GetLatestApps(ctx)
130+
if err != nil {
131+
log.Printf("Error getting all apps: %v", err)
132+
} else {
133+
fmt.Println("Recent updates (within last 30 days):")
134+
thirtyDaysAgo := time.Now().AddDate(0, 0, -30)
135+
136+
for _, app := range allApps.Apps {
137+
detected, err := app.ParseDetectedTime()
138+
if err == nil && detected.After(thirtyDaysAgo) {
139+
fmt.Printf(" - %s (v%s) - detected %s\n",
140+
app.Name,
141+
app.Version,
142+
detected.Format("2006-01-02"))
143+
}
144+
}
145+
}
146+
147+
// Example 6: Generate deployment script
148+
fmt.Println("\n=== Example 6: Generate Download Script for Specific Apps ===")
149+
150+
targetApps := []string{
151+
apps.AppNameExcel,
152+
apps.AppNameWord,
153+
apps.AppNamePowerPoint,
154+
apps.AppNameTeams,
155+
}
156+
157+
fmt.Println("#!/bin/bash")
158+
fmt.Println("# Microsoft Mac Apps Download Script")
159+
fmt.Println("# Generated:", time.Now().Format("2006-01-02 15:04:05"))
160+
fmt.Println()
161+
162+
for _, appName := range targetApps {
163+
app, err := client.Apps.GetAppByName(ctx, appName)
164+
if err != nil {
165+
fmt.Printf("# Error: %s not found\n", appName)
166+
continue
167+
}
168+
169+
fmt.Printf("# %s v%s (%.2f MB)\n", app.Name, app.Version, app.SizeMB)
170+
fmt.Printf("curl -L '%s' -o '%s.pkg'\n", app.DownloadURL, app.PackageID)
171+
fmt.Printf("# SHA256: %s\n", app.SHA256)
172+
fmt.Println()
173+
}
174+
175+
// Example 7: Try to find a non-existent app (error handling)
176+
fmt.Println("=== Example 7: Error Handling ===")
177+
178+
_, err = client.Apps.GetAppByName(ctx, "Non-existent Application")
179+
if err != nil {
180+
fmt.Printf("Expected error: %v\n", err)
181+
}
182+
183+
// Example 8: Pretty print full JSON response
184+
fmt.Println("\n=== Example 8: Full JSON Response ===")
185+
186+
jsonData, err := json.MarshalIndent(teams, "", " ")
187+
if err != nil {
188+
log.Printf("Error marshaling response to JSON: %v", err)
189+
} else {
190+
fmt.Println(string(jsonData))
191+
}
192+
193+
fmt.Println("\n=== Example Complete ===")
194+
}

0 commit comments

Comments
 (0)