Skip to content

Commit

Permalink
Merge pull request #3 from deploymenttheory/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ShocOne authored Oct 20, 2023
2 parents a40e3c2 + 9c4b1b7 commit 35adc96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To effectively use the `go-api-sdk-jamfpro` SDK, you'll need to set up and confi

### 1. Setting Constants

At the start of your main program, define some constants that will be used to configure the client:
At the start of your main program, you can optionally define define some constants that will be used to configure the client for http client. If you don't set any then defaults from `shared_api_client.go` will be used.

```go
const (
Expand Down Expand Up @@ -67,13 +67,10 @@ With the OAuth credentials loaded, you can now configure the HTTP client:
config := http_client.Config{
DebugMode: true,
Logger: http_client.NewDefaultLogger(),
MaxConcurrentRequests: maxConcurrentRequestsAllowed,
TokenLifespan: defaultTokenLifespan,
TokenRefreshBufferPeriod: defaultBufferPeriod,
}
```

Here, the DebugMode is set to true, which means the client will print debug information. The Logger uses the SDK's default logger. The other fields are set using the constants we defined earlier.
Here, the DebugMode is set to true, which means the client will print debug information. The Logger uses the SDK's default logger.

4. Initializing the Jamf Pro Client
Once the HTTP client is configured, initialize the Jamf Pro client:
Expand Down
12 changes: 6 additions & 6 deletions sdk/jamfpro/classicapi_computer_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

const uriComputerGroups = "/JSSResource/computergroups"

type ComputerGroupsResponse struct {
Size int `xml:"size"`
Results []ComputerGroupListResponse `xml:"computer_group"`
type ComputerGroupsListResponse struct {
Size int `xml:"size"`
Results []ComputerGroupListItem `xml:"computer_group"`
}

type ComputerGroupListResponse struct {
type ComputerGroupListItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
IsSmart bool `xml:"is_smart,omitempty"`
Expand Down Expand Up @@ -65,10 +65,10 @@ const (
)

// GetComputerGroups gets a list of all computer groups
func (c *Client) GetComputerGroups() (*ComputerGroupsResponse, error) {
func (c *Client) GetComputerGroups() (*ComputerGroupsListResponse, error) {
endpoint := uriComputerGroups

var computerGroups ComputerGroupsResponse
var computerGroups ComputerGroupsListResponse
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerGroups)
if err != nil {
return nil, fmt.Errorf("failed to fetch all Computer Groups: %v", err)
Expand Down
9 changes: 4 additions & 5 deletions sdk/jamfpro/shared_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import (
)

const (
concurrentRequests = 10 // Number of simultaneous requests.
maxConcurrentRequestsAllowed = 5 // Maximum allowed concurrent requests.
defaultTokenLifespan = 30 * time.Minute
defaultBufferPeriod = 5 * time.Minute
maxConcurrentRequestsAllowed = 5 // Maximum allowed concurrent requests.
defaultTokenLifespan = 30 * time.Minute // Set default token lifespan
defaultTokenBufferPeriod = 5 * time.Minute // Set default token buffer period before attempting a token refresh
)

type Client struct {
Expand Down Expand Up @@ -49,7 +48,7 @@ func NewClient(config Config) (*Client, error) {
config.TokenLifespan = defaultTokenLifespan
}
if config.TokenRefreshBufferPeriod == 0 {
config.TokenRefreshBufferPeriod = defaultBufferPeriod
config.TokenRefreshBufferPeriod = defaultTokenBufferPeriod
}
// Initialise http client
httpConfig := http_client.Config{
Expand Down

0 comments on commit 35adc96

Please sign in to comment.