Skip to content

Latest commit

 

History

History
393 lines (293 loc) · 17.1 KB

README.md

File metadata and controls

393 lines (293 loc) · 17.1 KB

Meters

(Meters)

Overview

Available Operations

List

List meters.

Scopes: meters:read meters:write

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.Meters.List(ctx, operations.MetersListRequest{})
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceMeter != 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.MetersListRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.MetersListResponse, error

Errors

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

Create

Create a meter.

Scopes: meters:write

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.Meters.Create(ctx, components.MeterCreate{
        Name: "<value>",
        Filter: components.Filter{
            Conjunction: components.FilterConjunctionAnd,
            Clauses: []components.Clauses{

            },
        },
        Aggregation: components.CreateMeterCreateAggregationAvg(
            components.PropertyAggregation{
                Func: components.FuncSum,
                Property: "<value>",
            },
        ),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Meter != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.MetersCreateResponse, error

Errors

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

Get

Get a meter by ID.

Scopes: meters:read meters:write

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.Meters.Get(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.Meter != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.MetersGetResponse, 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 meter.

Scopes: meters:write

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.Meters.Update(ctx, "<value>", components.MeterUpdate{})
    if err != nil {
        log.Fatal(err)
    }
    if res.Meter != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.MetersUpdateResponse, error

Errors

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

Events

Get events matching the filter of a meter.

Scopes: meters:read meters:write

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.Meters.Events(ctx, "<value>", nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceEvent != 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.
id string ✔️ The meter ID.
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.MetersEventsResponse, error

Errors

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

Quantities

Get quantities of a meter over a time period.

Scopes: meters:read meters:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/types"
	"github.com/polarsource/polar-go/models/components"
	"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.Meters.Quantities(ctx, operations.MetersQuantitiesRequest{
        ID: "<value>",
        StartTimestamp: types.MustTimeFromString("2023-09-17T00:45:34.608Z"),
        EndTimestamp: types.MustTimeFromString("2023-07-21T18:11:39.069Z"),
        Interval: components.TimeIntervalHour,
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.MeterQuantities != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.MetersQuantitiesResponse, error

Errors

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