Documentation ¶
Index ¶
- func AddArrival(barcodeID string, config *Config, mbAccessToken string) error
- func GetFieldValue(fieldID int, customFields []CustomField) (string, error)
- func IsValidHexID(barcodeID string) bool
- func IsValidID(facilityCode int, barcodeID string) bool
- type Access
- type AccessCredential
- type Auth
- type Brivo
- type BrivoToken
- type BrivoUser
- func (user *BrivoUser) AssignUserCredential(credID int, brivoAPIKey string, brivoAccessToken string) error
- func (user *BrivoUser) AssignUserGroup(groupID int, brivoAPIKey string, brivoAccessToken string) error
- func (user *BrivoUser) BuildUser(mbUser MindBodyUser, config Config)
- func (user *BrivoUser) CreateUser(brivoAPIKey string, brivoAccessToken string) error
- func (user *BrivoUser) DeleteUser(brivoAPIKey string, brivoAccessToken string) error
- func (user *BrivoUser) UpdateCustomField(fieldID int, fieldValue string, brivoAPIKey string, brivoAccessToken string) error
- type Config
- type Credential
- type CredentialFormat
- type CredentialList
- type CustomField
- type CustomFields
- type Event
- type EventUserData
- type FieldValue
- type MindBody
- type MindBodyUser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddArrival ¶
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 ¶
IsValidHexID checks for a valid 8 digit hex value @deprecated
func IsValidID ¶
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
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 ¶
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
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 ¶
CreateUser creates a new Brivo user
func (*BrivoUser) DeleteUser ¶
DeleteUser will delete a Brivo user by ID
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
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 ¶
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 ¶
CreateOrUpdateUser is a webhook event handler for client.updated and client.created
func (*Event) DeactivateUser ¶
DeactivateUser is a webhook event handler for client.deactivated
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 ¶
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
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