Skip to content

Latest commit

 

History

History
387 lines (292 loc) · 20.1 KB

README.md

File metadata and controls

387 lines (292 loc) · 20.1 KB

Benefits

(Benefits)

Overview

Available Operations

List

List benefits.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Benefits.List(ctx, nil, nil, nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceBenefit != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
organizationID *operations.BenefitsListQueryParamOrganizationIDFilter Filter by organization ID.
typeFilter *operations.BenefitTypeFilter Filter by benefit type.
page *int64 Page number, defaults to 1.
limit *int64 Size of a page, defaults to 10. Maximum is 100.
opts []operations.Option The options for this request.

Response

*operations.BenefitsListResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Create

Create a benefit.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Benefits.Create(ctx, components.CreateBenefitCreateBenefitDownloadablesCreate(
        components.BenefitDownloadablesCreate{
            Description: "yuck forager beneath please shadowy foodstuffs welcome",
            Properties: components.BenefitDownloadablesCreateProperties{
                Files: []string{
                    "<value>",
                },
            },
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.Benefit != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.BenefitCreate ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.BenefitsCreateResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Get

Get a benefit by ID.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Benefits.Get(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.Benefit != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.BenefitsGetResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Update

Update a benefit.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Benefits.Update(ctx, "<value>", operations.CreateBenefitsUpdateBenefitUpdateBenefitGitHubRepositoryUpdate(
        components.BenefitGitHubRepositoryUpdate{
            Properties: &components.BenefitGitHubRepositoryCreateProperties{
                RepositoryOwner: "polarsource",
                RepositoryName: "private_repo",
                Permission: components.BenefitGitHubRepositoryCreatePropertiesPermissionTriage,
            },
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.Benefit != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ N/A
requestBody operations.BenefitsUpdateBenefitUpdate ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.BenefitsUpdateResponse, error

Errors

Error Type Status Code Content Type
apierrors.NotPermitted 403 application/json
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Delete

Delete a benefit.

Warning

Every grants associated with the benefit will be revoked. Users will lose access to the benefit.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Benefits.Delete(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.BenefitsDeleteResponse, error

Errors

Error Type Status Code Content Type
apierrors.NotPermitted 403 application/json
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Grants

List the individual grants for a benefit.

It's especially useful to check if a user has been granted a benefit.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Benefits.Grants(ctx, operations.BenefitsGrantsRequest{
        ID: "<value>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceBenefitGrant != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.BenefitsGrantsRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.BenefitsGrantsResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*