models

package
v0.0.0-...-b429ff8 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddArrival

func AddArrival(barcodeID string, config *Config, mbAccessToken string) error

AddArrival logs a client arrival to a location in MINDBODY. This is used by Brivo event subscriptions when a user enters the facility through an access point

func GetFieldValue

func GetFieldValue(fieldID int, customFields []CustomField) (string, error)

GetFieldValue searches through []CustomField by ID and returns Value

func IsValidHexID

func IsValidHexID(barcodeID string) bool

IsValidHexID checks for a valid 8 digit hex value @deprecated

func IsValidID

func IsValidID(facilityCode int, barcodeID string) bool

IsValidID checks to make sure MindBodyUser.ID and EventUserData.ClientID follow the correct ID format of XX-XXXXX, where the first two digits are the Brivo facility code. If the ID value does not validate, that means the user has not been assigned a MINDBODY security bracelet and should not be added to Brivo.

Types

type Access

type Access struct {
	Occurred time.Time `json:"occurred"`
	Actor    struct {
		ID   int    `json:"id"`   // The user's Brivo ID
		Name string `json:"name"` // The user's name (for debugging)
	} `json:"actor"`
	EventData struct {
		ActionAllowed bool               `json:"actionAllowed"` // Was the action allowed? (May not be used)
		ObjectName    string             `json:"objectName"`    // Access point name
		Credentials   []AccessCredential `json:"credentials"`
	} `json:"eventData"`
}

Access stores Brivo user data when a site access event happens

func (*Access) ProcessRequest

func (access *Access) ProcessRequest(config *Config, auth *Auth, pool *redis.Pool)

ProcessRequest takes a Brivo access requests and logs a client arrival in Mindbody

type AccessCredential

type AccessCredential struct {
	ID       int  `json:"id"` // Brivo credential ID
	Disabled bool `json:"disabled"`
}

AccessCredential holds the user credential associate with the access event

type Auth

type Auth struct {
	BrivoToken    BrivoToken
	MindBodyToken mbToken
}

Auth stores authentication tokens for Brivo and MINDBODY

func (*Auth) Authenticate

func (auth *Auth) Authenticate(config *Config) error

Authenticate fetches access tokens for MINDBODY and Brivo

type Brivo

type Brivo struct {
	Data     []BrivoUser `json:"data"`
	Offset   int         `json:"offset"`
	PageSize int         `json:"pageSize"`
	Count    int         `json:"count"`
}

Brivo stores Brivo API response data

func (*Brivo) ListUsers

func (brivo *Brivo) ListUsers(brivoAPIKey string, brivoAccessToken string) error

ListUsers builds the Brivo data model with user data

func (*Brivo) ListUsersWithinGroup

func (brivo *Brivo) ListUsersWithinGroup(groupID int, brivoAPIKey string, brivoAccessToken string) error

ListUsersWithinGroup builds the Brivo data model with user data for a specific GroupID

type BrivoToken

type BrivoToken struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	Scope        string `json:"scope"`
	JTI          string `json:"jti"`
	ExpireTime   time.Time
}

BrivoToken stores Brivo API Tokens. Valid until `ExpiresIn` and then must be refreshed with `RefreshToken`

func (*BrivoToken) GetBrivoToken

func (token *BrivoToken) GetBrivoToken(config *Config) error

GetBrivoToken retrieves a Brivo Access Token using password grant type. It accepts `config` as a reference for updating via BuildClientCredentials().

func (*BrivoToken) RefreshBrivoToken

func (token *BrivoToken) RefreshBrivoToken(config Config) error

RefreshBrivoToken fetches a Brivo refresh token after the original access token expires

type BrivoUser

type BrivoUser struct {
	ID           int           `json:"id,omitempty"`
	ExternalID   string        `json:"externalId"` // MINDBODY's ClientUniqueID (will not change)
	FirstName    string        `json:"firstName"`
	MiddleName   string        `json:"middleName"`
	LastName     string        `json:"lastName"`
	Suspended    bool          `json:"suspended"`
	CustomFields []CustomField `json:"customFields"`
	Emails       []email       `json:"emails"`
	PhoneNumbers []phoneNumber `json:"phoneNumbers"`
}

BrivoUser stores Brivo user data

func (*BrivoUser) AssignUserCredential

func (user *BrivoUser) AssignUserCredential(credID int, brivoAPIKey string, brivoAccessToken string) error

AssignUserCredential assigns the credentialID to a user

func (*BrivoUser) AssignUserGroup

func (user *BrivoUser) AssignUserGroup(groupID int, brivoAPIKey string, brivoAccessToken string) error

AssignUserGroup assigns the user to groupID

func (*BrivoUser) BuildUser

func (user *BrivoUser) BuildUser(mbUser MindBodyUser, config Config)

BuildUser will build a Brivo user from MINDBODY user data

func (*BrivoUser) CreateUser

func (user *BrivoUser) CreateUser(brivoAPIKey string, brivoAccessToken string) error

CreateUser creates a new Brivo user

func (*BrivoUser) DeleteUser

func (user *BrivoUser) DeleteUser(brivoAPIKey string, brivoAccessToken string) error

DeleteUser will delete a Brivo user by ID

func (*BrivoUser) UpdateCustomField

func (user *BrivoUser) UpdateCustomField(fieldID int, fieldValue string, brivoAPIKey string, brivoAccessToken string) error

UpdateCustomField updates the fieldValue for a particular Custom Field by fieldID

type Config

type Config struct {
	BrivoUsername          string
	BrivoPassword          string
	BrivoClientID          string
	BrivoClientSecret      string
	BrivoAPIKey            string
	BrivoFacilityCode      int
	BrivoSiteID            int
	BrivoMemberGroupID     int
	BrivoBarcodeFieldID    int
	BrivoUserTypeFieldID   int
	BrivoRateLimit         int
	BrivoClientCredentials string

	MindbodyAPIKey              string
	MindbodyUsername            string
	MindbodyPassword            string
	MindbodySite                string
	MindbodyLocationID          int
	MindbodyMessageSignatureKey string

	RedisURL string

	Debug bool
	Proxy bool
	Port  string
	Env   string
}

Config stores environment settings imported from .env

func (*Config) GetConfig

func (config *Config) GetConfig()

GetConfig loads the environment variables into Config. Uses Config Vars on Heroku or .env file locally

type Credential

type Credential struct {
	ID                int              `json:"id,omitempty"`
	CredentialFormat  CredentialFormat `json:"credentialFormat"`
	ReferenceID       string           `json:"referenceId"` // Barcode ID (MindBodyUser.ID | BrivoUser.CustomField BarcodeID)
	EncodedCredential string           `json:"encodedCredential,omitempty"`
	FieldValues       []FieldValue     `json:"fieldValues,omitempty"`
}

Credential stores the Brivo access credential

func GenerateStandardCredential

func GenerateStandardCredential(barcodeID string, facilityCode int) *Credential

GenerateStandardCredential creates a Standard 26 Bit credential that uses the MINDBODY barcode ID and Brivo facility code as Field Values

func GenerateUnknownCredential

func GenerateUnknownCredential(barcodeID string) *Credential

GenerateUnknownCredential creates an encoded credential using format 110 Unknown @deprecated

func GetCredentialByID

func GetCredentialByID(credentialID int, brivoAPIKey string, brivoAccessToken string) (Credential, error)

GetCredentialByID returns a user credential based on the Brivo credential ID

func (*Credential) CreateCredential

func (cred *Credential) CreateCredential(brivoAPIKey string, brivoAccessToken string) (int, error)

CreateCredential will create new Brivo access credential. If the credential already exists, return the ID

func (*Credential) DeleteCredential

func (cred *Credential) DeleteCredential(brivoAPIKey string, brivoAccessToken string) error

DeleteCredential will delete a Brivo user by ID

type CredentialFormat

type CredentialFormat struct {
	ID int `json:"id"`
}

CredentialFormat stores the Brivo credential format

type CredentialList

type CredentialList struct {
	Offset   int          `json:"offset"`
	PageSize int          `json:"pageSize"`
	Data     []Credential `json:"data"`
	Count    int          `json:"count"`
}

CredentialList is the data format returned when querying credentials from Brivo

func (*CredentialList) GetCredentials

func (creds *CredentialList) GetCredentials(brivoAPIKey string, brivoAccessToken string) error

GetCredentials fetches all existing credentials from Brivo

type CustomField

type CustomField struct {
	ID    int    `json:"id,omitempty"`
	Value string `json:"value"`
}

CustomField stores data for a single custom field

func GenerateCustomField

func GenerateCustomField(customFieldID int, customFieldValue string) *CustomField

GenerateCustomField will create a CustomField{} based on an ID and Value

type CustomFields

type CustomFields struct {
	Data  []CustomField `json:"data"`
	Count int           `json:"count"`
}

CustomFields stores data about custom fields attached to a Brivo user

func (*CustomFields) GetCustomFieldsForUser

func (customFields *CustomFields) GetCustomFieldsForUser(userID int, brivoAPIKey string, brivoAccessToken string) error

GetCustomFieldsForUser retrieves any Brivo custom fields attached to userID

type Event

type Event struct {
	MessageID                        string        `json:"messageId"`
	EventID                          string        `json:"eventId"`
	EventSchemaVersion               float64       `json:"eventSchemaVersion"`
	EventInstanceOriginationDateTime time.Time     `json:"eventInstanceOriginationDateTime"`
	EventData                        EventUserData `json:"eventData"`
}

Event stores MINDBODY webhook event data

func (*Event) CreateOrUpdateUser

func (event *Event) CreateOrUpdateUser(config Config, auth Auth) error

CreateOrUpdateUser is a webhook event handler for client.updated and client.created

func (*Event) DeactivateUser

func (event *Event) DeactivateUser(config Config, auth Auth) error

DeactivateUser is a webhook event handler for client.deactivated

func (*Event) ProcessEvent

func (event *Event) ProcessEvent(errChan chan *Event, isRefreshing bool, config *Config, auth *Auth)

ProcessEvent handles cases for each webhook EventID

type EventUserData

type EventUserData struct {
	SiteID           int       `json:"siteId"`
	ClientID         string    `json:"clientId"`       // The client’s public ID (MindBodyUser.ID) used for barcode credential
	ClientUniqueID   int       `json:"clientUniqueId"` // The client’s guaranteed unique ID (MindBodyUser.UniqueID)
	CreationDateTime time.Time `json:"creationDateTime"`
	FirstName        string    `json:"firstName"`
	MiddleName       string    `json:"middleName"` // Currently not supported
	LastName         string    `json:"lastName"`
	Email            string    `json:"email"`
	MobilePhone      string    `json:"mobilePhone"`
	HomePhone        string    `json:"homePhone"`
	WorkPhone        string    `json:"workPhone"`
	Status           string    `json:"status"` // Declined,Non-Member,Active,Expired,Suspended,Terminated
}

EventUserData stores MINDBODY user data sent by webhook events

type FieldValue

type FieldValue struct {
	ID    int    `json:"id"`
	Value string `json:"value"`
}

FieldValue contains relevant Credential fields for `card_number` and `facility_code`

type MindBody

type MindBody struct {
	PaginationResponse struct {
		RequestedLimit  int `json:"RequestedLimit"`
		RequestedOffset int `json:"RequestedOffset"`
		PageSize        int `json:"PageSize"`
		TotalResults    int `json:"TotalResults"`
	} `json:"PaginationResponse"`
	Clients []MindBodyUser `json:"Clients"`
}

MindBody Client Data

func (*MindBody) GetClients

func (mb *MindBody) GetClients(config Config, mbAccessToken string) error

GetClients builds the MINDBODY data model with client data

type MindBodyUser

type MindBodyUser struct {
	ID          string `json:"Id"`       // Client’s public barcode ID used for client-related API calls (this is changeable)
	UniqueID    int    `json:"UniqueId"` // Client’s unique system-generated ID (does not change)
	FirstName   string `json:"FirstName"`
	MiddleName  string `json:"MiddleName"`
	LastName    string `json:"LastName"`
	Email       string `json:"Email"`
	MobilePhone string `json:"MobilePhone"`
	HomePhone   string `json:"HomePhone"`
	WorkPhone   string `json:"WorkPhone"`
	Active      bool   `json:"Active"`
	Status      string `json:"Status"` // Declined,Non-Member,Active,Expired,Suspended,Terminated
}

MindBodyUser stores MINDBODY user data

Jump to

Keyboard shortcuts

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