Files
onspring-api-sdk-go/apps.go
T
Stevan Freeborn c00998eed6 docs: add documentation comments for apps and paging types
- add doc comments to `AppsEndpoint`, `App` struct, and the `Get` method
in `apps.go`.
- add doc comments to the `Page` struct in `page.go`.
- add doc comments to `PagingRequest`, `PagingOption`, and paging helper
functions in `pagingRequest.go`.
2026-01-15 17:10:41 -06:00

59 lines
1.2 KiB
Go

package onspring
import (
"context"
"net/http"
)
const (
appsPath = "/apps"
)
// AppsEndpoint provides access to apps in an Onspring instance.
type AppsEndpoint struct {
client *Client
}
// App represents an Onspring app
type App struct {
Href string `json:"href"`
Id int `json:"id"`
Name string `json:"name"`
}
// Get retrieves a paginated list of apps from the Onspring API.
//
// Parameters:
// - ctx: The context for the request
// - pagingOpts: Optional paging configuration functions (e.g., ForPageNumber, WithPageSize)
//
// Returns:
// - Page[App]: A page of apps with pagination metadata
// - error: An error if the request fails
func (p *AppsEndpoint) Get(ctx context.Context, pagingOpts ...PagingOption) (Page[App], error) {
pagingRequest := &PagingRequest{
pageNumber: 1,
pageSize: 50,
}
for _, opt := range pagingOpts {
opt(pagingRequest)
}
req, requestCreationErr := p.client.newRequest(ctx, http.MethodGet, appsPath, pagingRequest.ToParams(), nil)
var page Page[App]
if requestCreationErr != nil {
return page, requestCreationErr
}
responseErr := p.client.doWithJsonResponse(req, &page)
if responseErr != nil {
return page, responseErr
}
return page, nil
}