octane

package module
v0.4.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 4 Imported by: 2

README

Octane Go Library

GoDoc GitHub Actions status

Octane

The Octane Go library provides programmatic access to the Octane API for Go applications.


Getting started

First, obtain an API key from within the Octane portal, and set it in your environment:

export OCTANE_API_KEY="<insert_octane_api_key_here>"

Then, from within your application, import the module and create a client:

package main

import (
	"os"

	"github.com/getoctane/octane-go"
)

func main() {
	client := octane.NewClient(os.Getenv("OCTANE_API_KEY"))
	// ...
}

Update your project's go.mod to include the new import, and vendor the dependencies:

go mod tidy && go mod vendor

Example apps

The following demo applications found in the examples/ directory display how to use the Octane Go library in real-world settings:

Making API calls

The Client type (returned by octane.NewClient("<token>")) provides programmatic access to the Octane API.

Customers API

The Customers namespace on a Client instance provides the ability to make calls to the Octane Customers API.

Example: Creating a new customer
customerName := "r2d2"

args := octane.CreateCustomerArgs{
    Name: customerName,
    MeasurementMappings: []octane.CustomerMeasurementMappingInputArgs{
        {
            Label:      "customer_name",
            ValueRegex: customerName,
        },
    },
}

customer, resp, err := client.Customers.Create(args)
Example: Subscribe a customer to a price plan
customerName := "r2d2"

args := octane.CreateSubscriptionArgs{
    PricePlanName: "droidplan",
}

subscription, resp, err := client.Customers.CreateSubscription(customerName, args)
Meters API

The Meters namespace on a Client instance provides the ability to make calls to the Octane Meters API.

Example: Creating a new meter
meterName := "droidrepairs"

args := octane.MeterInputArgs{
    Name:           meterName,
    MeterType:      "COUNTER",
    IsIncremental:  true,
    ExpectedLabels: []string{"customer_name"},
}

meter, resp, err := client.Meters.Create(args)
Price Plans API

The PricePlans namespace on a Client instance provides the ability to make calls to the Octane Price Plans API.

Example: Creating a new price plan
pricePlanName := "droidplan"
pricePlanRate := 10000 // $100.00
meterName := "droidrepairs"

args := octane.CreatePricePlanArgs{
    Name:   pricePlanName,
    Period: "month",
    MeteredComponents: []octane.MeteredComponentInputArgs{
        {
            MeterName: meterName,
            PriceScheme: &octane.PriceSchemeInputArgs{
                Prices: []octane.PriceInputArgs{
                    {
                        Price: float64(pricePlanRate),
                    },
                },
                SchemeType: "FLAT",
            },
        },
    },
}

pricePlan, resp, err := client.PricePlans.Create(args)
Measurements API

The Measurements namespace on a Client instance provides the ability to make calls to the Octane Measurements API.

Example: Sending a measurement
meterName := "droidrepairs"
customerName := "r2d2"

args := octane.Measurement{
    MeterName: meterName,
    Value: 1,
    Labels: map[string]string{
        "customer_name": customerName,
    },
}

measurement, resp, err := client.Measurements.Create(args)

Development

In the root of this repo, download required dependencies:

go mod vendor

To regenerate files in internal/swagger/ from latest Octane OpenAPI spec, run the following (requires Docker):

make codegen

These files should then be checked into git:

git add internal/swagger/

Contributing

Contributions are welcome!

Prior to submitting a pull request, please check the list of open issues. If there is not an existing issue related to your changes, please open a new issue to first discuss your thoughts with the project maintainers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddOnInputArgs

type AddOnInputArgs struct {
	Feature *FeatureInputArgs `json:"feature,omitempty"`
	Price   int32             `json:"price,omitempty"`
}

type Client

type Client struct {
	Customers    *customersAPI
	Measurements *measurementsAPI
	Meters       *metersAPI
	PricePlans   *pricePlansAPI
	Credits      *creditsAPI
}

Client is a client for accessing the Octane API.

func NewClient

func NewClient(token string, options ...ClientOption) *Client

NewClient returns a new client for the Octane API.

type ClientOption

type ClientOption func(*clientSettings)

ClientOption is used to customize a Client.

func ClientOptWithBasePath

func ClientOptWithBasePath(basePath string) ClientOption

func ClientOptWithDefaultHeader

func ClientOptWithDefaultHeader(defaultHeader map[string]string) ClientOption

func ClientOptWithHTTPClient

func ClientOptWithHTTPClient(httpClient *http.Client) ClientOption

func ClientOptWithHost

func ClientOptWithHost(host string) ClientOption

func ClientOptWithScheme

func ClientOptWithScheme(scheme string) ClientOption

func ClientOptWithUserAgent

func ClientOptWithUserAgent(userAgent string) ClientOption

type ContactInfoInputArgs

type ContactInfoInputArgs struct {
	Country      string `json:"country,omitempty"`
	AddressLine1 string `json:"address_line_1,omitempty"`
	State        string `json:"state,omitempty"`
	Zipcode      string `json:"zipcode,omitempty"`
	Email        string `json:"email,omitempty"`
	AddressLine2 string `json:"address_line_2,omitempty"`
	City         string `json:"city,omitempty"`
	Url          string `json:"url,omitempty"`
	Phone        string `json:"phone,omitempty"`
	LegalName    string `json:"legal_name,omitempty"`
}

type CreateCreditGrantArgs added in v0.4.7

type CreateCreditGrantArgs struct {
	// The date at which the grant is effective
	EffectiveAt *time.Time `json:"effective_at,omitempty"`
	// Number of credits to grant
	Amount float64 `json:"amount"`
	// The date at which this grant expires
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	// Name of the customer receving the grant
	CustomerName string `json:"customer_name"`
	// Optional description. This is only viewable internally
	Description string `json:"description,omitempty"`
	// Total price paid for the credits in cents. Defaults to $1 (100 cents) per credit if not specified
	Price int32 `json:"price"`
}

type CreateCustomerArgs

type CreateCustomerArgs struct {
	VendorId                           int32                                 `json:"vendor_id,omitempty"`
	Tags                               []string                              `json:"tags,omitempty"`
	DisplayName                        string                                `json:"display_name,omitempty"`
	ContactInfo                        *ContactInfoInputArgs                 `json:"contact_info,omitempty"`
	Name                               string                                `json:"name,omitempty"`
	MeasurementMappings                []CustomerMeasurementMappingInputArgs `json:"measurement_mappings,omitempty"`
	PricePlanName                      string                                `json:"price_plan_name,omitempty"`
	PricePlanTag                       string                                `json:"price_plan_tag,omitempty"`
	AutogeneratePaymentGatewayCustomer bool                                  `json:"autogenerate_payment_gateway_customer,omitempty"`
	CreatedAt                          time.Time                             `json:"created_at,omitempty"`
	CustomerMetadata                   []CustomerMetadata
}

type CreatePricePlanArgs

type CreatePricePlanArgs struct {
	VendorId          int32                       `json:"vendor_id,omitempty"`
	Description       string                      `json:"description,omitempty"`
	Period            string                      `json:"period,omitempty"`
	BasePrice         int32                       `json:"base_price,omitempty"`
	AddOns            []AddOnInputArgs            `json:"add_ons,omitempty"`
	Tags              []string                    `json:"tags,omitempty"`
	Features          []FeatureInputArgs          `json:"features,omitempty"`
	Trial             *TrialInputArgs             `json:"trial,omitempty"`
	DisplayName       string                      `json:"display_name,omitempty"`
	Name              string                      `json:"name,omitempty"`
	Limits            []LimitInputArgs            `json:"limits,omitempty"`
	MeteredComponents []MeteredComponentInputArgs `json:"metered_components,omitempty"`
}

type CreateSubscriptionArgs

type CreateSubscriptionArgs struct {
	PricePlanName      string     `json:"price_plan_name,omitempty"`
	Discounts          []Discount `json:"discounts,omitempty"`
	CouponOverrideName string     `json:"coupon_override_name,omitempty"`
	EffectiveAt        time.Time  `json:"effective_at,omitempty"`
	CouponOverrideId   int32      `json:"coupon_override_id,omitempty"`
	CustomerId         int32      `json:"customer_id,omitempty"`
	PricePlanId        int32      `json:"price_plan_id,omitempty"`
	VendorId           int32      `json:"vendor_id,omitempty"`
	PricePlanTag       string     `json:"price_plan_tag,omitempty"`
}

type CreditGrant added in v0.4.7

type CreditGrant struct {
	// Number of credits granted
	Amount float64 `json:"amount,omitempty"`
	// The date at which this grant is effective
	EffectiveAt *time.Time `json:"effective_at,omitempty"`
	// A unique identifier for this grant
	Uuid string `json:"uuid,omitempty"`
	// The date at which this grant expires
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	// Name of the customer who received the grant
	CustomerName string `json:"customer_name,omitempty"`
	// The source of the grant.
	Source string `json:"source,omitempty"`
	// Optional description. This is only viewable internally
	Description string `json:"description,omitempty"`
	// Total price paid for the credits, in cents
	Price int32 `json:"price,omitempty"`
}

type Customer

type Customer swagger.Customer

type CustomerMeasurementMappingInputArgs

type CustomerMeasurementMappingInputArgs struct {
	Label      string `json:"label,omitempty"`
	ValueRegex string `json:"value_regex,omitempty"`
}

type CustomerMeasurmentMapping added in v0.3.0

type CustomerMeasurmentMapping swagger.CustomerMeasurementMapping

type CustomerMetadata added in v0.4.9

type CustomerMetadata struct {
	Property string `json:"property,omitempty"`
	Value    string `json:"value,omitempty"`
}

type CustomerPortalToken added in v0.4.3

type CustomerPortalToken swagger.CustomerPortalToken

type CustomerPortalTokenInputArgs added in v0.4.3

type CustomerPortalTokenInputArgs swagger.CustomerPortalTokenInputArgs

type CustomerUsage added in v0.3.0

type CustomerUsage swagger.CustomerUsage

type CustomersApiCustomersCustomerNameRevenueGetOpts added in v0.3.0

type CustomersApiCustomersCustomerNameRevenueGetOpts swagger.CustomersApiCustomersCustomerNameRevenueGetOpts

type CustomersApiCustomersCustomerNameUsageGetOpts added in v0.3.0

type CustomersApiCustomersCustomerNameUsageGetOpts swagger.CustomersApiCustomersCustomerNameUsageGetOpts

type DeleteSubscriptionArgs

type DeleteSubscriptionArgs swagger.DeleteSubscriptionArgs

type Discount added in v0.4.9

type Discount struct {
	Amount       float64 `json:"price_plan_name,omitempty"`
	DiscountType string  `json:"price_plan_name,omitempty"`
}

type FeatureInputArgs

type FeatureInputArgs struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	DisplayName string `json:"display_name,omitempty"`
}

type LimitInputArgs

type LimitInputArgs struct {
	Feature *FeatureInputArgs `json:"feature,omitempty"`
	Limit   float64           `json:"limit,omitempty"`
}

type LineItems added in v0.3.0

type LineItems swagger.LineItems

type Measurement

type Measurement swagger.Measurement

type Meter

type Meter swagger.Meter

type MeterInputArgs

type MeterInputArgs swagger.MeterInputArgs

type MeteredComponentInputArgs

type MeteredComponentInputArgs struct {
	MeterId     int32                 `json:"meter_id,omitempty"`
	PriceScheme *PriceSchemeInputArgs `json:"price_scheme,omitempty"`
	MeterName   string                `json:"meter_name,omitempty"`
}

type PaymentGatewayCredential

type PaymentGatewayCredential swagger.PaymentGatewayCredential

type PriceInputArgs

type PriceInputArgs struct {
	Cap   float64 `json:"cap,omitempty"`
	Price float64 `json:"price,omitempty"`
}

type PricePlan

type PricePlan swagger.PricePlan

type PriceSchemeInputArgs

type PriceSchemeInputArgs struct {
	TimeUnitName string           `json:"time_unit_name,omitempty"`
	UnitName     string           `json:"unit_name,omitempty"`
	SchemeType   string           `json:"scheme_type,omitempty"`
	Prices       []PriceInputArgs `json:"prices,omitempty"`
	PriceList    []interface{}    `json:"price_list,omitempty"`
}

type RevenueBreakdown added in v0.3.0

type RevenueBreakdown struct {
	TotalRevenue float64     `json:"total_revenue,omitempty"`
	LineItems    []LineItems `json:"line_items,omitempty"`
}

type RevenueResponse added in v0.3.0

type RevenueResponse swagger.RevenueResponse

type Subscription

type Subscription swagger.Subscription

type TrialInputArgs

type TrialInputArgs struct {
	TimeUnitName string  `json:"time_unit_name,omitempty"`
	TimeLength   float64 `json:"time_length,omitempty"`
	Credit       float64 `json:"credit,omitempty"`
}

type UpdateCustomerArgs

type UpdateCustomerArgs struct {
	VendorId            int32                                 `json:"vendor_id,omitempty"`
	Tags                []string                              `json:"tags,omitempty"`
	DisplayName         string                                `json:"display_name,omitempty"`
	ContactInfo         *ContactInfoInputArgs                 `json:"contact_info,omitempty"`
	Name                string                                `json:"name,omitempty"`
	MeasurementMappings []CustomerMeasurementMappingInputArgs `json:"measurement_mappings,omitempty"`
}

type UpdateMeterArgs

type UpdateMeterArgs swagger.UpdateMeterArgs

type UpdatePricePlanArgs

type UpdatePricePlanArgs struct {
	VendorId          int32                       `json:"vendor_id,omitempty"`
	Description       string                      `json:"description,omitempty"`
	Period            string                      `json:"period,omitempty"`
	BasePrice         int32                       `json:"base_price,omitempty"`
	AddOns            []AddOnInputArgs            `json:"add_ons,omitempty"`
	Tags              []string                    `json:"tags,omitempty"`
	Features          []FeatureInputArgs          `json:"features,omitempty"`
	Trial             *TrialInputArgs             `json:"trial,omitempty"`
	DisplayName       string                      `json:"display_name,omitempty"`
	Name              string                      `json:"name,omitempty"`
	Limits            []LimitInputArgs            `json:"limits,omitempty"`
	MeteredComponents []MeteredComponentInputArgs `json:"metered_components,omitempty"`
}

type UpdateSubscriptionArgs

type UpdateSubscriptionArgs swagger.UpdateSubscriptionArgs

Directories

Path Synopsis
examples
internal
swagger
* Octane API * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * * API version: 1.0.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
* Octane API * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * * API version: 1.0.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL