planhat

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 11 Imported by: 0

README

Go Planhat - A simple Planhat Go Library

Status GitHub tag (latest SemVer) GitHub GoDoc Go Report Card

This repository is intended as a simple to use library for the Go language to interact with the Planhat API.

In order to use this library you will need a planhat subscription.

Installing

You can install the library in the usual way as follows:

$ go get github.com/darrenparkinson/planhat

Usage

In your code, import the library:

import "github.com/darrenparkinson/planhat"

You can then construct a new Planhat client, and use the various services on the client to access different parts of the API. For example:

ph, _ := planhat.NewClient(apikey, cluster, nil)
companies, err := ph.CompanyService.List(context.Background())

Some API methods have optional parameters that can be passed, for example:

ph, _ := planhat.NewClient(apikey, cluster, nil)
opts := &planhat.CompanyListOptions{Limit: planhat.Int(10), Offset: planhat.Int(0)}
companies, err := ph.CompanyService.List(context.Background(), opts)

The services of a client divide the API into logical areas and correspond to the structure of the Planhat API documentation at https://docs.planhat.com/

NOTE: Using the context package, one can easily pass cancelation signals and deadlines to various services of the client for handling a request. In case there is no context available, then context.Background() can be used as a starting point.

Authentication

Authentication is provided by an API Key as outlined in the documentation. You are able to provide the API Key as part of initialisation using NewClient.

You can obtain an API key by navigating to "Service Accounts" and adding a new service account user that has the permissions you require, followed by clicking the "Generate New Token" button.

If you receive a planhat: unauthorized request message, you may be using an incorrect region.

Region

Planhat supports various regions and cluster as outlined in the documentation. You must provide the cluster you are using to NewClient on initialisation. Ask your planhat representative or check the docs to see which one you need to use. If there is no specified cluster, you may pass an empty string.

Examples:

  • "" becomes api,
  • eu becomes api-eu,
  • eu2 becomes api-eu2,
  • eu3 becomes api-eu3,
  • us2 becomes api-us2

Helper Functions

Most structs for resources use pointer values. This allows distinguishing between unset fields and those set to a zero value. Some helper functions have been provided to easily create these pointers for string, bool and int values as you saw above and here, for example:

opts := &planhat.CompanyListOptions{
	Limit:  planhat.Int(10),
	Offset: planhat.Int(0),
	Sort:   planhat.String("name"),
}

This can cause challenges when receiving results since you may encounter a panic if you access a nil pointer, e.g:

company, _ := ph.CompanyService.GetCompany(ctx, "123123123abcabcabc")
log.Println(*company.ExternalID)

In this case, if the external id has no value, you would receive a panic: runtime error: invalid memory address or nil pointer dereference error. Clearly this isn't a very nice user experience, so where appropriate, "getter" accessor functions are generated automatically for structs with pointer fields to enable you to safely retrieve values:

company, _ := ph.CompanyService.GetCompany(ctx, "123123123abcabcabc")
log.Println(company.GetExternalID())

Pagination

Where pagination is provided, Planhat provides the Offset and Limit query parameters as part of the request parameters for a given endpoint. These can be passed via options to the command:

companies, err := c.CompanyService.List(ctx, &planhat.CompanyListOptions{Limit: planhat.Int(10), Offset: planhat.Int(0)})

By way of an example, you might use the following to work through multiple pages:

var allCompanies []*planhat.Company
limit, offset := 10, 0
for {
    companies, _ := ph.CompanyService.List(ctx, &planhat.CompanyListOptions{Limit: planhat.Int(limit), Offset: planhat.Int(offset)})
    log.Println("Retrieved", len(companies), "companies")
    offset += limit
    if len(companies) == 0 {
	    break
    }
    allCompanies = append(allCompanies, companies...)
}
log.Println("Found total", len(allCompanies), "companies.")

As you can see, planhat doesn't provide a mechanism to check if there are more values, so we keep going until there are no results.

Sorting

Where sorting is provided, Planhat provides the Sort query parameter as part of the request parameters for a given endpoint. This can also be passed via the options to the command and is used in conjuntion with pagination:

companies, err := c.CompanyService.List(ctx, &planhat.CompanyListOptions{Limit: planhat.Int(10), Offset: planhat.Int(0), Sort: planhat.String("name")})

Note that the sort string appears to be case sensitive and must currently use the Planhat object name.

Errors

In the documentation, Planhat identifies the following returned errors. These are provided as constants so that you may check against them:

Code Error Constant
400 Bad Request ErrBadRequest
401 Unauthorized Request ErrUnauthorized
403 Forbidden ErrForbidden
500 Internal Error ErrInternalError

All other errors are returned as ErrUnknown

As an example:

companies, err := ph.CompanyService.List(ctx)
if errors.Is(err, planhat.ErrUnauthorized) {
	log.Fatal("Sorry, you're not allowed to do that.")
}

Services

The following outlines the planhat models and their implementation status:

Model Service Implementation Status
Asset AssetService Complete
Churn ChurnService Not Implemented
Company CompanyService Complete
Conversation ConversationService Not Implemented
Custom Field CustomFieldService Not Implemented
Enduser EnduserService Not Implemented
Invoice InvoiceService Not Implemented
Issue IssueService Not Implemented
License LicenseService Not Implemented
Note NoteService Not Implemented
NPS NPSService Not Implemented
Opportunity OpportunityService Not Implemented
Project ProjectService Not Implemented
Sale SaleService Not Implemented
Task TaskService Not Implemented
Ticket TicketService Not Implemented
User UserService Partial

In addition to the Planhat Models, there are some additional endpoints in the documentation as outlined below:

Section Service Implementation Status
User Activities UserActivityService Not Implemented
Metrics MetricsService Complete

Contributing

Since all endpoints would ideally be covered, contributions are always welcome. Adding new methods should be relatively straightforward.

Versioning

In general this planhat library follows semver for tagging releases of the package. As yet, it is still in development and has not had a tag added, but will in due course. Since it is still in development, you may expect some changes.

License

This library is distributed under the MIT license found in the LICENSE file.

Documentation

Overview

Package planhat provides a client for using the Planhat API.

Usage:

import "github.com/darrenparkinson/planhat"

Construct a new Planhat client, then use the various services on the client to access different parts of the Planhat API. For example:

client := planhat.NewClient(apikey, cluster, nil)

// List companies
companies, err := ph.CompanyService.List(ctx)

Some API methods have optional parameters that can be passed. For example:

ph, _ := planhat.NewClient(apikey, cluster, nil)
opts := &planhat.CompanyListOptions{Limit: planhat.Int(10), Offset: planhat.Int(0)}
companies, err := ph.CompanyService.List(ctx, opts)

The services of a client divide the API into logical areas and correspond to the structure of the Planhat API documentation at https://docs.planhat.com/

NOTE: Using the context package, one can easily pass cancelation signals and deadlines to various services of the client for handling a request. In case there is no context available, then context.Background() can be used as a starting point.

Authentication

Authentication is provided by an API Key as outlined in the documentation at https://docs.planhat.com/#authentication. You are able to provide the API Key as part of initialisation using `NewClient`.

You can obtain an API key by navigating to "Service Accounts" and adding a new service account user that has the permissions you require, followed by clicking the "Generate New Token" button.

If you receive a `planhat: unauthorized request` message, you may be using an incorrect region.

Region

Planhat supports various regions and cluster as outlined in the documentation at https://docs.planhat.com/#base-url). You must provide the cluster you are using to `NewClient` on initialisation. Ask your planhat representative or [check the docs](https://docs.planhat.com/#introduction) to see which one you need to use. If there is no specified cluster, you may pass an empty string.

Examples:

* "" becomes `api`, * `eu` becomes `api-eu`, * `eu2` becomes `api-eu2`, * `eu3` becomes `api-eu3`, * `us2` becomes `api-us2`

Pagination

Where pagination is provided, Planhat provides the Offset and Limit query parameters as part of the request parameters for a given endpoint. These can be passed via options to the command:

companies, err := c.CompanyService.List(ctx, &planhat.CompanyListOptions{Limit: planhat.Int(10), Offset: planhat.Int(0)})

By way of an example, you might use the following to work through multiple pages:

var allCompanies []*planhat.Company
limit, offset := 10, 0
for {
	companies, _ := ph.CompanyService.List(ctx, &planhat.CompanyListOptions{Limit: planhat.Int(limit), Offset: planhat.Int(offset)})
	log.Println("Retrieved", len(companies), "companies")
	offset += limit
	if len(companies) == 0 {
		break
	}
	allCompanies = append(allCompanies, companies...)
}
log.Println("Found total", len(allCompanies), "companies.")

As you can see, planhat doesn't provide a mechanism to check if there are more values, so we keep going until there are no results.

Sorting

Where sorting is provided, Planhat provides the Sort query parameter as part of the request parameters for a given endpoint. This can also be passed via the options to the command and is used in conjuntion with pagination:

companies, err := c.CompanyService.List(ctx, &planhat.CompanyListOptions{Limit: planhat.Int(10), Offset: planhat.Int(0), Sort: planhat.String("name")})

Note that the sort string appears to be case sensitive and must currently use the Planhat object name.

Copyright 2021 The go-planhat AUTHORS. All rights reserved.

Use of this source code is governed by an MIT-style license that can be found in the LICENSE file. Code generated by gen-accessors; DO NOT EDIT.

Index

Constants

View Source
const (
	ErrBadRequest        = Err("planhat: bad request")
	ErrUnauthorized      = Err("planhat: unauthorized request")
	ErrForbidden         = Err("planhat: forbidden")
	ErrInternalError     = Err("planhat: internal error")
	ErrUnknown           = Err("planhat: unexpected error occurred")
	ErrMissingTenantUUID = Err("planhat: missing required tenant uuid for this request")
)

Error Constants Cisco documents these as the only error responses they will emit.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func Float64

func Float64(v float64) *float64

Float64 is a helper routine that allocates a new Float64 value to store v and returns a pointer to it.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type Asset

type Asset struct {
	ID         *string                `json:"_id,omitempty"`
	Name       *string                `json:"name,omitempty"`
	CompanyID  *string                `json:"companyId,omitempty"`
	ExternalID *string                `json:"externalId,omitempty"`
	SourceID   *string                `json:"sourceId,omitempty"`
	Custom     map[string]interface{} `json:"custom,omitempty"`
}

Asset represents a planhat asset.

func (*Asset) GetCompanyID

func (a *Asset) GetCompanyID() string

GetCompanyID returns the CompanyID field if it's non-nil, zero value otherwise.

func (*Asset) GetExternalID

func (a *Asset) GetExternalID() string

GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise.

func (*Asset) GetID

func (a *Asset) GetID() string

GetID returns the ID field if it's non-nil, zero value otherwise.

func (*Asset) GetName

func (a *Asset) GetName() string

GetName returns the Name field if it's non-nil, zero value otherwise.

func (*Asset) GetSourceID

func (a *Asset) GetSourceID() string

GetSourceID returns the SourceID field if it's non-nil, zero value otherwise.

type AssetListOptions

type AssetListOptions struct {
	// Limit the list length.
	Limit *int `url:"limit,omitempty"`

	// Start the list on a specific integer index.
	Offset *int `url:"offset,omitempty"`

	// Sort based on a specific property. Prefix the property "-" to change the sort order.
	Sort *string `url:"sort,omitempty"`

	// Select specific properties. This is case sensitive and currently needs to be the planhat names as
	// a comma separated string, e.g. "companyid,name".
	Select *string `url:"select,omitempty"`

	// Filter using company id. Multiple ids can be used separating them by commas.
	CompanyID *string `url:"companyId,omitempty"`
}

AssetListOptions represents query parameters for listing assets. They are pointer values in order to distinguish between unset fields and those with set to a zero value. Use the helper function planhat.Int() or planhat.String() to set the values.

func (*AssetListOptions) GetLimit

func (a *AssetListOptions) GetLimit() int

GetLimit returns the Limit field if it's non-nil, zero value otherwise.

func (*AssetListOptions) GetOffset

func (a *AssetListOptions) GetOffset() int

GetOffset returns the Offset field if it's non-nil, zero value otherwise.

func (*AssetListOptions) GetSelect

func (a *AssetListOptions) GetSelect() string

GetSelect returns the Select field if it's non-nil, zero value otherwise.

func (*AssetListOptions) GetSort

func (a *AssetListOptions) GetSort() string

GetSort returns the Sort field if it's non-nil, zero value otherwise.

type AssetService

type AssetService struct {
	// contains filtered or unexported fields
}

AssetService represents the Assets group

func (*AssetService) BulkUpsert

func (s *AssetService) BulkUpsert(ctx context.Context, assets []Asset) (*UpsertResponse, error)

BulkUpsert will update or insert assets. To create an asset it's required define a name and a valid companyId. To update an asset it is required to specify in the payload one of the following keyables:

_id, sourceId and/or externalId.

Since this is a bulk upsert operation it's possible create and/or update multiple assets with the same payload. Note there is an upper limit of 50,000 items per request. For more information, see the [planhat docs](https://docs.planhat.com/#bulk_upsert)

func (*AssetService) Create

func (s *AssetService) Create(ctx context.Context, asset Asset) (*Asset, error)

Create creates a new asset record

func (*AssetService) Delete

func (s *AssetService) Delete(ctx context.Context, id string) (*DeleteResponse, error)

Delete is used delete an asset. It is required to pass the _id (ID).

func (*AssetService) Get

func (s *AssetService) Get(ctx context.Context, id string) (*Asset, error)

Get returns a single asset given it's planhat ID Alternately it's possible to get an asset using its externalId and/or sourceId adding a prefix and passing one of these keyables as identifiers. e.g. extid-{{externalId}} or srcid-{{sourceId}}. Helper functions have also been provided for this.

func (*AssetService) GetByExternalID

func (s *AssetService) GetByExternalID(ctx context.Context, externalID string) (*Asset, error)

GetByExternalID retrieves an asset using it's external ID

func (*AssetService) GetBySourceID

func (s *AssetService) GetBySourceID(ctx context.Context, sourceID string) (*Asset, error)

GetBySourceID retrieves an asset using it's source ID

func (*AssetService) List

func (s *AssetService) List(ctx context.Context, options ...*AssetListOptions) ([]*Asset, error)

List will list assets based on the AssetListOptions provided

func (*AssetService) Update

func (s *AssetService) Update(ctx context.Context, id string, asset Asset) (*Asset, error)

Update will update a planhat asset. To update an asset it is required to pass the asset _id in the request. Alternately it is possible to update using the asset externalId and/or sourceId adding a prefix and passing one of these keyables as identifiers. e.g. extid-{{externalId}} or srcid-{{sourceId}}

type Client

type Client struct {
	// BaseURL for Planhat API.  Set to https://api-eu3.planhat.com using `planhat.New()`, or set directly.
	BaseURL string

	// MetricsURL for Planhat API.  Set to https://analytics.planhat.com/dimensiondata as per the planhat docs.
	MetricsURL string

	//HTTP Client to use for making requests, allowing the user to supply their own if required.
	HTTPClient *http.Client

	//API Key for Planhat.
	APIKey string

	//TenantUUID for posting to the metrics endpoint.  Only required if you're sending in metrics.
	TenantUUID string

	MetricsService *MetricsService
	AssetService   *AssetService
	CompanyService *CompanyService
	EndUserService *EndUserService
	UserService    *UserService
	// contains filtered or unexported fields
}

Client is the main planhat client for interacting with the library. It can be created using NewClient

func NewClient

func NewClient(apikey string, cluster string, client *http.Client) (*Client, error)

NewClient is a helper function that returns an new planhat client given a region and an API Key. Optionally you can provide your own http client or use nil to use the default. This is done to ensure you're aware of the decision you're making to not provide your own http client.

type Company

type Company struct {
	// CoOwner of the company.  Empty interface due to GetCompany returning an ID string and GetCompanies returning an ID and Nickname
	CoOwner       *interface{}           `json:"coOwner,omitempty"`
	CSMScore      *int                   `json:"csmScore,omitempty"`
	Custom        map[string]interface{} `json:"custom,omitempty"`
	CustomerFrom  *time.Time             `json:"customerFrom,omitempty"`
	CustomerTo    *time.Time             `json:"customerTo,omitempty"`
	ExternalID    *string                `json:"externalId,omitempty"`
	H             *int                   `json:"h,omitempty"`
	ID            *string                `json:"_id,omitempty"`
	LastRenewal   *time.Time             `json:"lastRenewal,omitempty"`
	LastTouch     *interface{}           `json:"lastTouch,omitempty"`
	LastTouchType *interface{}           `json:"lastTouchType,omitempty"`
	Licenses      *[]License             `json:"licenses,omitempty"`
	MR            *float64               `json:"mr,omitempty"`
	MRR           *float64               `json:"mrr,omitempty"`
	MRRTotal      *float64               `json:"mrrTotal,omitempty"`
	MRTotal       *float64               `json:"mrTotal,omitempty"`
	Name          *string                `json:"name,omitempty"`
	NRR30         *int                   `json:"nrr30,omitempty"`
	NRRTotal      *int                   `json:"nrrTotal,omitempty"`
	// Owner of the company.  Empty interface due to GetCompany returning an ID string and GetCompanies returning an ID and Nickname
	Owner              *interface{} `json:"owner,omitempty"`
	Phase              *string      `json:"phase,omitempty"`
	PhaseSince         *time.Time   `json:"phaseSince,omitempty"`
	Products           *[]string    `json:"products,omitempty"`
	RenewalDate        *time.Time   `json:"renewalDate,omitempty"`
	RenewalDaysFromNow *int         `json:"renewalDaysFromNow,omitempty"`
	Status             *string      `json:"status,omitempty"`
}

Company represents a planhat company.

func (*Company) GetCSMScore

func (c *Company) GetCSMScore() int

GetCSMScore returns the CSMScore field if it's non-nil, zero value otherwise.

func (*Company) GetCustomerFrom

func (c *Company) GetCustomerFrom() time.Time

GetCustomerFrom returns the CustomerFrom field if it's non-nil, zero value otherwise.

func (*Company) GetCustomerTo

func (c *Company) GetCustomerTo() time.Time

GetCustomerTo returns the CustomerTo field if it's non-nil, zero value otherwise.

func (*Company) GetExternalID

func (c *Company) GetExternalID() string

GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise.

func (*Company) GetH

func (c *Company) GetH() int

GetH returns the H field if it's non-nil, zero value otherwise.

func (*Company) GetID

func (c *Company) GetID() string

GetID returns the ID field if it's non-nil, zero value otherwise.

func (*Company) GetLastRenewal

func (c *Company) GetLastRenewal() time.Time

GetLastRenewal returns the LastRenewal field if it's non-nil, zero value otherwise.

func (*Company) GetLicenses

func (c *Company) GetLicenses() []License

GetLicenses returns the Licenses field if it's non-nil, zero value otherwise.

func (*Company) GetMR

func (c *Company) GetMR() *float64

GetMR returns the MR field.

func (*Company) GetMRR

func (c *Company) GetMRR() *float64

GetMRR returns the MRR field.

func (*Company) GetMRRTotal

func (c *Company) GetMRRTotal() *float64

GetMRRTotal returns the MRRTotal field.

func (*Company) GetMRTotal

func (c *Company) GetMRTotal() *float64

GetMRTotal returns the MRTotal field.

func (*Company) GetNRR30

func (c *Company) GetNRR30() int

GetNRR30 returns the NRR30 field if it's non-nil, zero value otherwise.

func (*Company) GetNRRTotal

func (c *Company) GetNRRTotal() int

GetNRRTotal returns the NRRTotal field if it's non-nil, zero value otherwise.

func (*Company) GetName

func (c *Company) GetName() string

GetName returns the Name field if it's non-nil, zero value otherwise.

func (*Company) GetPhase

func (c *Company) GetPhase() string

GetPhase returns the Phase field if it's non-nil, zero value otherwise.

func (*Company) GetPhaseSince

func (c *Company) GetPhaseSince() time.Time

GetPhaseSince returns the PhaseSince field if it's non-nil, zero value otherwise.

func (*Company) GetProducts

func (c *Company) GetProducts() []string

GetProducts returns the Products field if it's non-nil, zero value otherwise.

func (*Company) GetRenewalDate

func (c *Company) GetRenewalDate() time.Time

GetRenewalDate returns the RenewalDate field if it's non-nil, zero value otherwise.

func (*Company) GetRenewalDaysFromNow

func (c *Company) GetRenewalDaysFromNow() int

GetRenewalDaysFromNow returns the RenewalDaysFromNow field if it's non-nil, zero value otherwise.

func (*Company) GetStatus

func (c *Company) GetStatus() string

GetStatus returns the Status field if it's non-nil, zero value otherwise.

type CompanyListOptions

type CompanyListOptions struct {
	// Limit the list length.
	Limit *int `url:"limit,omitempty"`

	// Start the list on a specific integer index.
	Offset *int `url:"offset,omitempty"`

	// Sort based on a specific property. Prefix the property "-" to change the sort order.
	Sort *string `url:"sort,omitempty"`
}

CompanyListOptions represents query parameters for listing companies. They are pointer values in order to distinguish between unset fields and those with set to a zero value. Use the helper function planhat.Int() or planhat.String() to set the values.

func (*CompanyListOptions) GetLimit

func (c *CompanyListOptions) GetLimit() int

GetLimit returns the Limit field if it's non-nil, zero value otherwise.

func (*CompanyListOptions) GetOffset

func (c *CompanyListOptions) GetOffset() int

GetOffset returns the Offset field if it's non-nil, zero value otherwise.

func (*CompanyListOptions) GetSort

func (c *CompanyListOptions) GetSort() string

GetSort returns the Sort field if it's non-nil, zero value otherwise.

type CompanyService

type CompanyService struct {
	// contains filtered or unexported fields
}

CompanyService represents the Company group

func (*CompanyService) BulkUpsert

func (s *CompanyService) BulkUpsert(ctx context.Context, companies []Company) (*UpsertResponse, error)

BulkUpsert will update or insert companies. Note there is an upper limit of 50,000 items per request. For more information, see the [planhat docs](https://docs.planhat.com/#bulk_upsert)

func (*CompanyService) Create

func (s *CompanyService) Create(ctx context.Context, company Company) (*Company, error)

Create creates a new company record

func (*CompanyService) Delete

func (s *CompanyService) Delete(ctx context.Context, id string) (*DeleteResponse, error)

Delete is used delete a company. It is required to pass the _id (ID).

func (*CompanyService) Get

func (s *CompanyService) Get(ctx context.Context, id string) (*Company, error)

Get returns a single company given it's planhat ID

func (*CompanyService) GetByExternalID

func (s *CompanyService) GetByExternalID(ctx context.Context, externalID string) (*Company, error)

GetByExternalID retrieves a company using it's external ID

func (*CompanyService) GetBySourceID

func (s *CompanyService) GetBySourceID(ctx context.Context, sourceID string) (*Company, error)

GetBySourceID retrieves a company using it's source ID

func (*CompanyService) LeanList

func (s *CompanyService) LeanList(ctx context.Context, options ...*LeanCompanyListOptions) ([]*LeanCompany, error)

LeanList returns a lightweight list of all companies in Planhat to match against your own ids etc.

func (*CompanyService) List

func (s *CompanyService) List(ctx context.Context, options ...*CompanyListOptions) ([]*Company, error)

List will list companies based on the CompanyListOptions provided

func (*CompanyService) Update

func (s *CompanyService) Update(ctx context.Context, id string, company Company) (*Company, error)

Update will update a planhat company. To update a company it is required to pass the company _id in the request. Alternately it is possible to update using the company externalId and/or sourceId adding a prefix and passing one of these keyables as identifiers. e.g. extid-{{externalId}} or srcid-{{sourceId}} Note you may get a Bad Request error if you include the ID in the company record

type Custom

type Custom map[string]interface{}

Custom represents planhat custom fields

type DeleteResponse

type DeleteResponse struct {
	N            int `json:"n"`
	OK           int `json:"ok"`
	DeletedCount int `json:"deletedCount"`
}

DeleteResponse is returned by planhat when deleting an object

type DimensionData

type DimensionData struct {
	ID          string    `json:"_id"`
	DimensionID string    `json:"dimensionId"`
	Time        time.Time `json:"time"`
	Value       float64   `json:"value"`
	Model       string    `json:"model"`
	ParentID    string    `json:"parentId"`
	CompanyID   string    `json:"companyId"`
	CompanyName string    `json:"companyName"`
}

DimensionData represents metrics data from planhat for the list operation.

type EndUserService

type EndUserService struct {
	// contains filtered or unexported fields
}

EndUserService represents the End Users group

type Err

type Err string

Err implements the error interface so we can have constant errors.

func (Err) Error

func (e Err) Error() string

type LeanCompany

type LeanCompany struct {
	ID         string `json:"_id"`
	Name       string `json:"name"`
	ExternalID string `json:"externalId"`
	SourceID   string `json:"sourceId"`
	Slug       string `json:"slug"`
}

LeanCompany is the result of the Get lean list endpoint

type LeanCompanyListOptions

type LeanCompanyListOptions struct {
	ExternalID *string `url:"externalId,omitempty"`
	SourceID   *string `url:"sourceId,omitempty"`
	Status     *string `url:"status,omitempty"`
}

LeanCompanyListOptions represents query parameters for listing companies. They are pointer values in order to distinguish between unset fields and those with set to a zero value. Use the helper function planhat.String() to set the value.

func (*LeanCompanyListOptions) GetExternalID

func (l *LeanCompanyListOptions) GetExternalID() string

GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise.

func (*LeanCompanyListOptions) GetSourceID

func (l *LeanCompanyListOptions) GetSourceID() string

GetSourceID returns the SourceID field if it's non-nil, zero value otherwise.

func (*LeanCompanyListOptions) GetStatus

func (l *LeanCompanyListOptions) GetStatus() string

GetStatus returns the Status field if it's non-nil, zero value otherwise.

type License

type License struct {
	ID         string  `json:"_id"`
	ExternalID string  `json:"externalId"`
	Value      float64 `json:"value"`
	Currency   struct {
		ID        string `json:"_id"`
		Symbol    string `json:"symbol"`
		Rate      int    `json:"rate"`
		IsBase    bool   `json:"isBase"`
		Overrides struct {
		} `json:"overrides"`
	} `json:"_currency"`
	FromDate           time.Time `json:"fromDate"`
	ToDate             time.Time `json:"toDate"`
	Product            string    `json:"product"`
	CompanyID          string    `json:"companyId"`
	Custom             Custom    `json:"custom"`
	CompanyName        string    `json:"companyName"`
	Status             string    `json:"status"`
	RenewalStatus      string    `json:"renewalStatus"`
	FixedPeriod        bool      `json:"fixedPeriod"`
	ToDateIncluded     bool      `json:"toDateIncluded"`
	Length             float64   `json:"length"`
	Mrr                float64   `json:"mrr"`
	RenewalPeriod      float64   `json:"renewalPeriod"`
	RenewalUnit        string    `json:"renewalUnit"`
	RenewalDate        time.Time `json:"renewalDate"`
	RenewalDaysFromNow int       `json:"renewalDaysFromNow"`
	NoticePeriod       float64   `json:"noticePeriod"`
	NoticeUnit         string    `json:"noticeUnit"`
	IsOverdue          bool      `json:"isOverdue"`
}

License represents a planhat license

type Metric

type Metric struct {
	// Any string without spaces or special characters. If you're sending "Share of Active Users" a good dimensionId
	// might be "activeusershare". It's not displayed in Planhat but will be used when building Health Metrics in
	// Planhat. Required.
	DimensionID *string `json:"dimensionId,omitempty"`
	// The raw (number) value you would like to set. Required.
	Value *float64 `json:"value,omitempty"`
	// This is the model (company by default) external id in your systems. For this to work the objects in Planhat
	// will need to have this externalId set. Required.
	ExternalID *string `json:"externalId,omitempty"`
	// Company (default), EndUser, Asset and Project models are supported
	Model *string `json:"model,omitempty"`
	// Pass a valid ISO format date string to specify the date of the event. In none is provided we will use the time the request was received.
	Date *string `json:"date,omitempty"`
}

Metric represents an item that can be pushed to planhat.

func (*Metric) GetDate

func (m *Metric) GetDate() string

GetDate returns the Date field if it's non-nil, zero value otherwise.

func (*Metric) GetDimensionID

func (m *Metric) GetDimensionID() string

GetDimensionID returns the DimensionID field if it's non-nil, zero value otherwise.

func (*Metric) GetExternalID

func (m *Metric) GetExternalID() string

GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise.

func (*Metric) GetModel

func (m *Metric) GetModel() string

GetModel returns the Model field if it's non-nil, zero value otherwise.

func (*Metric) GetValue

func (m *Metric) GetValue() *float64

GetValue returns the Value field.

type MetricsListOptions

type MetricsListOptions struct {
	// Id of company.
	CID *string `url:"cid,omitempty"`

	// Id of the dimension data.
	DimID *string `url:"dimid,omitempty"`

	// Days format integer representing the start day period (Days since January 1, 1970, Unix epoch).
	From *int `url:"from,omitempty"`

	// Days format integer representing the end day period (Days since January 1, 1970, Unix epoch).
	To *int `url:"to,omitempty"`

	// Limit the list length.
	Limit *int `url:"limit,omitempty"`

	// Start the list on a specific integer index.
	Offset *int `url:"offset,omitempty"`
}

MetricsListOptions represents query parameters for listing metrics. They are pointer values in order to distinguish between unset fields and those with set to a zero value. Use the helper function planhat.Int() or planhat.String() to set the values.

func (*MetricsListOptions) GetCID

func (m *MetricsListOptions) GetCID() string

GetCID returns the CID field if it's non-nil, zero value otherwise.

func (*MetricsListOptions) GetDimID

func (m *MetricsListOptions) GetDimID() string

GetDimID returns the DimID field if it's non-nil, zero value otherwise.

func (*MetricsListOptions) GetFrom

func (m *MetricsListOptions) GetFrom() int

GetFrom returns the From field if it's non-nil, zero value otherwise.

func (*MetricsListOptions) GetLimit

func (m *MetricsListOptions) GetLimit() int

GetLimit returns the Limit field if it's non-nil, zero value otherwise.

func (*MetricsListOptions) GetOffset

func (m *MetricsListOptions) GetOffset() int

GetOffset returns the Offset field if it's non-nil, zero value otherwise.

func (*MetricsListOptions) GetTo

func (m *MetricsListOptions) GetTo() int

GetTo returns the To field if it's non-nil, zero value otherwise.

type MetricsService

type MetricsService struct {
	// contains filtered or unexported fields
}

MetricsService represents the Metrics methods

func (*MetricsService) BulkUpsert

func (s *MetricsService) BulkUpsert(ctx context.Context, metrics []Metric) (*UpsertMetricsResponse, error)

BulkUpsert will update metrics. To push dimension data into Planhat it is required to specify the Tenant Token (tenantUUID) in the request URL. This token is a simple uui identifier for your tenant and it can be found in the Developer module under the Tokens section. Set the TenantUUID on the planhat Client. For more information, see the [planhat docs](https://docs.planhat.com/#bulkupsert_metrics)

func (*MetricsService) List

func (s *MetricsService) List(ctx context.Context, options ...*MetricsListOptions) ([]*DimensionData, error)

List returns a list of DimensionData items as per the documentation https://docs.planhat.com/#get_metrics

type UpsertMetricsResponse

type UpsertMetricsResponse struct {
	Processed int           `json:"processed"`
	Errors    []interface{} `json:"errors"`
}

UpsertMetricsResponse is the result of a bulk upsert operation as documented in the [planhat docs](https://docs.planhat.com/#bulkupsert_metrics). Note the use of slices of empty interfaces due to the lack of documentation on what an error object is.

type UpsertResponse

type UpsertResponse struct {
	Created          int           `json:"created"`
	CreatedErrors    []interface{} `json:"createdErrors"`
	InsertsKeys      []interface{} `json:"insertsKeys"`
	Updated          int           `json:"updated"`
	UpdatedErrors    []interface{} `json:"updatedErrors"`
	UpdatesKeys      []interface{} `json:"updatesKeys"`
	NonUpdates       int           `json:"nonupdates"`
	Modified         []string      `json:"modified"`
	UpsertedIDs      []string      `json:"upsertedIds"`
	PermissionErrors []interface{} `json:"permissionErrors"`
}

UpsertResponse is the result of a bulk upsert operation as documented in the [planhat docs](https://docs.planhat.com/#bulk_upsert). Note the use of slices of empty interfaces due to the lack of documentation on what an error object etc. are

type User

type User struct {
	ID                         *string `json:"_id,omitempty"`
	SkippedGettingStartedSteps struct {
		Email     *bool `json:"email,omitempty"`
		Linkedin  *bool `json:"linkedin,omitempty"`
		Avatar    *bool `json:"avatar,omitempty"`
		All       *bool `json:"all,omitempty"`
		Team      *bool `json:"team,omitempty"`
		Customers *bool `json:"customers,omitempty"`
	} `json:"skippedGettingStartedSteps,omitempty"`
	Image struct {
		Path *string `json:"path,omitempty"`
	} `json:"image,omitempty"`
	FirstName            *string  `json:"firstName,omitempty"`
	LastName             *string  `json:"lastName,omitempty"`
	IsHidden             *bool    `json:"isHidden,omitempty"`
	Removed              *bool    `json:"removed,omitempty"`
	Inactive             *bool    `json:"inactive,omitempty"`
	CompressedView       *bool    `json:"compressedView,omitempty"`
	CompanyFilter        *string  `json:"companyFilter,omitempty"`
	TaskFilter           *string  `json:"taskFilter,omitempty"`
	WorkflowFilter       *string  `json:"workflowFilter,omitempty"`
	PlayLogDisabled      *bool    `json:"playLogDisabled,omitempty"`
	RadarOneLine         *bool    `json:"radarOneLine,omitempty"`
	CollapsedFolders     []string `json:"collapsedFolders,omitempty"`
	RevReportPeriodType  *string  `json:"revReportPeriodType,omitempty"`
	SplitLayoutDisabled  *bool    `json:"splitLayoutDisabled,omitempty"`
	DailyDigest          *bool    `json:"dailyDigest,omitempty"`
	FollowerUpdate       *bool    `json:"followerUpdate,omitempty"`
	InAppNotifications   *bool    `json:"inAppNotifications,omitempty"`
	LastVisitedCompanies []string `json:"lastVisitedCompanies,omitempty"`
	LastVisitedEndusers  []string `json:"lastVisitedEndusers,omitempty"`
	Roles                []struct {
		ID          *string `json:"_id,omitempty"`
		Name        *string `json:"name,omitempty"`
		Description *string `json:"description,omitempty"`
		V           *int    `json:"__v,omitempty"`
	} `json:"roles,omitempty"`
	IsExposedAsSenderOption *bool      `json:"isExposedAsSenderOption,omitempty"`
	DefaultMeetingLength    *int       `json:"defaultMeetingLength,omitempty"`
	NickName                *string    `json:"nickName,omitempty"`
	Email                   *string    `json:"email,omitempty"`
	CreateDate              *time.Time `json:"createDate,omitempty"`
	V                       *int       `json:"__v,omitempty"`
	RecentOpenTabs          *struct {
		Customers           *string `json:"customers,omitempty"`
		Bi                  *string `json:"bi,omitempty"`
		BiSystem            *string `json:"bi-system,omitempty"`
		BiAnalytics         *string `json:"bi-analytics,omitempty"`
		People              *string `json:"people,omitempty"`
		Tasks               *string `json:"tasks,omitempty"`
		Conversations       *string `json:"conversations,omitempty"`
		ConversationsOutbox *string `json:"conversations-outbox,omitempty"`
		Engage              *string `json:"engage,omitempty"`
		Nps                 *string `json:"nps,omitempty"`
		Revenue             *string `json:"revenue,omitempty"`
		Settings            *string `json:"settings,omitempty"`
		Team                *string `json:"team,omitempty"`
	} `json:"recentOpenTabs,omitempty"`
	RecentOpenPage      *string `json:"recentOpenPage,omitempty"`
	Segment             *string `json:"segment,omitempty"`
	BubbleChartSettings struct {
		XParam *string `json:"xParam,omitempty"`
		YParam *string `json:"yParam,omitempty"`
	} `json:"bubbleChartSettings,omitempty"`
	RecentTabSearches struct {
		BaseTasksAssigned *string `json:"base-tasks-assigned,omitempty"`
	} `json:"recentTabSearches,omitempty"`
	GoogleAPI struct {
		AccessEnabled *bool         `json:"accessEnabled,omitempty"`
		SyncEnabled   *bool         `json:"syncEnabled,omitempty"`
		SyncInitial   *bool         `json:"syncInitial,omitempty"`
		SyncedLabels  []interface{} `json:"syncedLabels,omitempty"`
	} `json:"googleApi,omitempty"`
	MsAPI struct {
		AccessEnabled *bool         `json:"accessEnabled,omitempty"`
		SyncEnabled   *bool         `json:"syncEnabled,omitempty"`
		SyncInitial   *bool         `json:"syncInitial,omitempty"`
		SyncedLabels  []interface{} `json:"syncedLabels,omitempty"`
	} `json:"msApi,omitempty"`
	GoogleCalendarAPI struct {
		AccessEnabled   *bool         `json:"accessEnabled,omitempty"`
		SyncEnabled     *bool         `json:"syncEnabled,omitempty"`
		SyncInitial     *bool         `json:"syncInitial,omitempty"`
		SyncedCalendars []interface{} `json:"syncedCalendars,omitempty"`
		CalendarToSave  struct {
		} `json:"calendarToSave,omitempty"`
	} `json:"googleCalendarApi,omitempty"`
}

User represents a planhat user

func (*User) GetCompanyFilter

func (u *User) GetCompanyFilter() string

GetCompanyFilter returns the CompanyFilter field if it's non-nil, zero value otherwise.

func (*User) GetCompressedView

func (u *User) GetCompressedView() bool

GetCompressedView returns the CompressedView field if it's non-nil, zero value otherwise.

func (*User) GetCreateDate

func (u *User) GetCreateDate() time.Time

GetCreateDate returns the CreateDate field if it's non-nil, zero value otherwise.

func (*User) GetDailyDigest

func (u *User) GetDailyDigest() bool

GetDailyDigest returns the DailyDigest field if it's non-nil, zero value otherwise.

func (*User) GetDefaultMeetingLength

func (u *User) GetDefaultMeetingLength() int

GetDefaultMeetingLength returns the DefaultMeetingLength field if it's non-nil, zero value otherwise.

func (*User) GetEmail

func (u *User) GetEmail() string

GetEmail returns the Email field if it's non-nil, zero value otherwise.

func (*User) GetFirstName

func (u *User) GetFirstName() string

GetFirstName returns the FirstName field if it's non-nil, zero value otherwise.

func (*User) GetFollowerUpdate

func (u *User) GetFollowerUpdate() bool

GetFollowerUpdate returns the FollowerUpdate field if it's non-nil, zero value otherwise.

func (*User) GetID

func (u *User) GetID() string

GetID returns the ID field if it's non-nil, zero value otherwise.

func (*User) GetInAppNotifications

func (u *User) GetInAppNotifications() bool

GetInAppNotifications returns the InAppNotifications field if it's non-nil, zero value otherwise.

func (*User) GetInactive

func (u *User) GetInactive() bool

GetInactive returns the Inactive field if it's non-nil, zero value otherwise.

func (*User) GetIsExposedAsSenderOption

func (u *User) GetIsExposedAsSenderOption() bool

GetIsExposedAsSenderOption returns the IsExposedAsSenderOption field if it's non-nil, zero value otherwise.

func (*User) GetIsHidden

func (u *User) GetIsHidden() bool

GetIsHidden returns the IsHidden field if it's non-nil, zero value otherwise.

func (*User) GetLastName

func (u *User) GetLastName() string

GetLastName returns the LastName field if it's non-nil, zero value otherwise.

func (*User) GetNickName

func (u *User) GetNickName() string

GetNickName returns the NickName field if it's non-nil, zero value otherwise.

func (*User) GetPlayLogDisabled

func (u *User) GetPlayLogDisabled() bool

GetPlayLogDisabled returns the PlayLogDisabled field if it's non-nil, zero value otherwise.

func (*User) GetRadarOneLine

func (u *User) GetRadarOneLine() bool

GetRadarOneLine returns the RadarOneLine field if it's non-nil, zero value otherwise.

func (*User) GetRecentOpenPage

func (u *User) GetRecentOpenPage() string

GetRecentOpenPage returns the RecentOpenPage field if it's non-nil, zero value otherwise.

func (*User) GetRemoved

func (u *User) GetRemoved() bool

GetRemoved returns the Removed field if it's non-nil, zero value otherwise.

func (*User) GetRevReportPeriodType

func (u *User) GetRevReportPeriodType() string

GetRevReportPeriodType returns the RevReportPeriodType field if it's non-nil, zero value otherwise.

func (*User) GetSegment

func (u *User) GetSegment() string

GetSegment returns the Segment field if it's non-nil, zero value otherwise.

func (*User) GetSplitLayoutDisabled

func (u *User) GetSplitLayoutDisabled() bool

GetSplitLayoutDisabled returns the SplitLayoutDisabled field if it's non-nil, zero value otherwise.

func (*User) GetTaskFilter

func (u *User) GetTaskFilter() string

GetTaskFilter returns the TaskFilter field if it's non-nil, zero value otherwise.

func (*User) GetV

func (u *User) GetV() int

GetV returns the V field if it's non-nil, zero value otherwise.

func (*User) GetWorkflowFilter

func (u *User) GetWorkflowFilter() string

GetWorkflowFilter returns the WorkflowFilter field if it's non-nil, zero value otherwise.

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

UserService represents the Users group

func (*UserService) List

func (s *UserService) List(ctx context.Context) ([]*User, error)

List returns a list of planhat users

Jump to

Keyboard shortcuts

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