hubspot

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 3 Imported by: 0

README

This is a HubSpot Go client generated using openapi-generator. It includes packages for every OpenAPI spec listed in HubSpot's API directory.

Installing

go get github.com/clarkmcc/go-hubspot

Re-generating Clients

This package includes a client generator that runs the openapi-generator binary (must be located in your PATH) and re-generates the Go clients using the most up-to-date API specs. Any changes to the specs should be committed to this repository through a PR. I'll do my best to keep this up to date with the most recent changes. Assuming that you have openapi-generator installed, just run the following to re-generate the clients.

go generate

Using the clients

The clients are broken out into their own packages by name and categorized by API version.

import "github.com/clarkmcc/go-hubspot/generated/v3/contacts"

client := contacts.NewAPIClient(contacts.NewConfiguration())

input := contacts.SimplePublicObjectInput{
  Properties: map[string]string{
    "firstname": "Adrian", 
    "lastname": "Mott",
  },
}

client.BasicApi.
    Create(context.Background()).
    SimplePublicObjectInput(input).
    Execute()

Authorization

Authorization is done by passing context values in with each request. In order to facilitate this, I've created a simple Authorizer interface and a private app token implementation (more implementations to come). An API key implementation is also available but the HubSpot API has deprecated API tokens.

authorizer := hubspot.NewTokenAuthorizer("<PRIVATE APP TOKEN>")
ctx := hubspot.WithAuthorizer(context.Background(), authorizer)
// Pass this context to your hubspot API requests

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextKey = "hubspot.authorizer"

Functions

func WithAuthorizer

func WithAuthorizer(ctx context.Context, authorizer Authorizer) context.Context

WithAuthorizer appends the given authorizer to the context

Types

type APIKeyAuthorizer

type APIKeyAuthorizer struct {
	Key string
}

func NewAPIKeyAuthorizer

func NewAPIKeyAuthorizer(key string) *APIKeyAuthorizer

func (*APIKeyAuthorizer) Apply

func (a *APIKeyAuthorizer) Apply(request AuthorizationRequest)

type AuthorizationRequest

type AuthorizationRequest struct {
	QueryParams url.Values
	FormParams  url.Values
	Headers     map[string]string
}

AuthorizationRequest represents a request that could be authorized but is not yet authorized. It only contains the fields that an authorizer may need to modify.

type Authorizer

type Authorizer interface {
	Apply(request AuthorizationRequest)
}

Authorizer knows how to authorize API requests to the HubSpot API by modifying the request context

type TokenAuthorizer

type TokenAuthorizer struct {
	Token string
}

func NewTokenAuthorizer

func NewTokenAuthorizer(token string) *TokenAuthorizer

func (*TokenAuthorizer) Apply

func (a *TokenAuthorizer) Apply(request AuthorizationRequest)

Jump to

Keyboard shortcuts

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