godig

package
v0.0.0-...-f91b66c Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: Unlicense Imports: 11 Imported by: 7

Documentation

Index

Constants

View Source
const ClassicDateFormat = "Mon Jan 2 2006 15:04:05 GMT-0700 (MST)"

ClassicDateFormat is used to parse a Salsa timestamp coming from the database.

View Source
const DateFormat = "2006-01-02"

DateFormat is used to format a time so that Engage will recognize it.

View Source
const EngageDateFormat = "2006-01-02T15:04:05.000Z"

EngageDateFormat is used to format a date for Engage.

View Source
const TimestampFormat = "2006-01-02T15:04:05"

TimestampFormat is used to format a time so that Engage will recognize it.

Variables

This section is empty.

Functions

func ClassicTime

func ClassicTime(s string) (t time.Time, err error)

ClassicTime accepts a Classic timestamp and returns a time object.

func EngageDate

func EngageDate(s string) string

EngageDate parses converts a string containing a MySQL date to another string containing an Engage date.

func EngageTimestamp

func EngageTimestamp(s string) string

EngageTimestamp parses converts a string containing a MySQL date to another string containing an Engage date and time.

func FixCrit

func FixCrit(c string) string

FixCrit Replace spaces and percent signs in the criteria so that Saosa consumes them correctly.

func ShortDate

func ShortDate(s string) string

ShortDate accepts a time and outputs it as YYYY-mm-dd.

Types

type API

type API struct {
	Client   *http.Client
	Cookies  []*http.Cookie
	Host     string
	Verbose  bool
	CredData CredData
}

API hold the data that we need to do Salsa API calls. That includes the cookies from authentication.

func NewAPI

func NewAPI() *API

NewAPI initializes and returns an API object.

func YAMLAuth

func YAMLAuth(f string) (*API, error)

YAMLAuth accepts campaign manager credentials (email, password, host) from a YAML file and authenticates.

func (*API) Authenticate

func (a *API) Authenticate(c CredData) error

Authenticate and save the cookies for later.

func (*API) Chapter

func (a *API) Chapter() Table

Chapter is a shortcut for creating an organization Table object.

func (*API) Donation

func (a *API) Donation() Table

Donation is a shortcut for creating a donation Table object.

func (*API) EmailBlast

func (a *API) EmailBlast() Table

EmailBlast is a shortcut for creating an EmailBlast Table object.

func (*API) Get

func (a *API) Get(u string) (*http.Response, []byte, error)

Get reads the provided URL and returns the HTTP response, a body and an error. Get also adds the cookies that the API needs to prove authentication. Your application would probably be better off using One or Many.

func (*API) Groups

func (a *API) Groups() Table

Groups is a shorcut for creating a groups Table. Note that "groups" is the only table in the API that's plural.

func (*API) GroupsSupporters

func (a *API) GroupsSupporters() Table

GroupsSupporters is a shortcut to join groups to supporters via the supporter_groups table. Use LeftJoin to get data for this object.

func (*API) NewTable

func (a *API) NewTable(n string) Table

NewTable creates a table using a table/object name.

func (*API) Org

func (a *API) Org() Table

Org is a shortcut for creating an organization Table object.

func (*API) Publish

func (a *API) Publish() Table

Publish is a shortcut for creating a publish Table object.

func (*API) Supporter

func (a *API) Supporter() Table

Supporter is a shortcut for creating a supporter Table object.

func (*API) SupporterDonation

func (a *API) SupporterDonation() Table

SupporterDonation is a shortcut for creating a Table that holds supporter and donation records. Use LeftJoin to get data for this object.

func (*API) SupporterGroups

func (a *API) SupporterGroups() Table

SupporterGroups is a shortcut for creating a supporter_group Table object.

func (*API) Unsubscribe

func (a *API) Unsubscribe() Table

Unsubscribe is a shortcut for creating an unsubscribe Table object.

type AuthStatus

type AuthStatus struct {
	Status  string
	Message string
}

AuthStatus contains the information returned by Authentication.

type Chapter

type Chapter struct {
	ChapterKey         string `json:"chapter_KEY"`
	OrganizationKey    string `json:"organization_KEY"`
	ParentKey          string `json:"parent_KEY,omitempty"`
	ChapterTypeKey     string `json:"chapter_type_KEY"`
	LastModified       string `json:"Last_Modified"`
	DateCreated        string `json:"Date_Created"`
	Name               string `json:"Name"`
	READONLYShortName  string `json:"READONLY_Short_Name,omitempty"`
	Description        string `json:"Description,omitempty"`
	Official           bool   `json:"Official,omitempty"`
	Chartered          bool   `json:"Chartered,omitempty"`
	ChapterType        string `json:"Chapter_Type,omitempty"`
	HomepageURL        string `json:"Homepage_URL,omitempty"`
	Slogan             string `json:"Slogan,omitempty"`
	Municipality       string `json:"municipality,omitempty"`
	Region             string `json:"region,omitempty"`
	PostalCode         string `json:"postal_code,omitempty"`
	Country            string `json:"Country,omitempty"`
	Status             string `json:"Status,omitempty"`
	SiteID             string `json:"siteID,omitempty"`
	Latitude           string `json:"Latitude,omitempty"`
	Longitude          string `json:"Longitude,omitempty"`
	Privacy            string `json:"Privacy,omitempty"`
	BaseURL            string `json:"Base_URL,omitempty"`
	SecureURL          string `json:"Secure_URL,omitempty"`
	SyndicationOptions string `json:"Syndication_Options,omitempty"`
}

Chapter describes a chapter for an organization. Chapters may be rooted at the "national" (organization) level, or may be rooted in other chapters.

type CredData

type CredData struct {
	Host     string
	Email    string
	Password string
}

CredData contains the info that we need to get into the API.

func Credentials

func Credentials(p string) (CredData, error)

Credentials retrieves the login credentials from a YAML login file.

type DeleteStatus

type DeleteStatus struct {
	Object   string
	Key      string
	Result   string
	Messages []string
}

DeleteStatus contins the info returned by deleting a record.

type Field

type Field struct {
	Name         string `json:"name,omitempty"`
	Nullable     string `json:"nullable,omitempty"`
	Type         string `json:"type,omitempty"`
	DefaultValue string `json:"defaultValue,omitempty"`
	Label        string `json:"label,omitempty"`
	MaxLength    string `json:"maxlength,omitempty"`
	IsCustom     string `json:"isCustom,omitEmpty"`
	DisplayName  string `json:"displayName,omitEmpty"`
}

Field is used to describe table fields when calling Desfcribe.

type FieldList

type FieldList []Field

FieldList is a slice of Fields returned by Describe.

type MapList

type MapList []gjson.Result

MapList is a slice of FieldMaps.

type Organization

type Organization struct {
	OrganizationKey                            string `json:"organization_KEY"`
	RootKey                                    string `json:"root_Key,omitempty"`
	ParentKey                                  string `json:"parent_Key,omitempty"`
	PartnerKey                                 string `json:"partner_Key,omitempty"`
	LastModified                               string `json:"Last_Modified,omitempty"`
	DateCreated                                string `json:"Date_Created,omitempty"`
	PRIVATEDateCreated                         string `json:"PRIVATE_Date_Created,omitempty"`
	Name                                       string `json:"Name"`
	Type                                       string `json:"Type"`
	Status                                     string `json:"Status"`
	READONLYShortName                          string `json:"READONLY_Short_Name,omitempty"`
	Description                                string `json:"Description,omitempty"`
	OrganizationHomepage                       string `json:"Organization_Homepage,omitempty"`
	NewsletterOrListserveName                  string `json:"Newsletter_or_Listserve_Name,omitempty"`
	CustomHeaderHTML                           string `json:"Custom_Header_HTML,omitempty"`
	CustomFooterHTML                           string `json:"Custom_Footer_HTML,omitempty"`
	PrintHeader                                string `json:"Print_Header,omitempty"`
	PrintFooter                                string `json:"Print_Footer,omitempty"`
	BaseURL                                    string `json:"Base_URL"`
	SecureURL                                  string `json:"Secure_URL"`
	Street                                     string `json:"Street,omitempty"`
	Street2                                    string `json:"Street_2,omitempty"`
	City                                       string `json:"City,omitempty"`
	State                                      string `json:"State,omitempty"`
	Zip                                        string `json:"Zip,omitempty"`
	PRIVATEZipPlus4                            string `json:"PRIVATE_Zip_Plus_4,omitempty"`
	MailServer                                 string `json:"mail_server,omitempty"`
	MailUser                                   string `json:"mail_user,omitempty"`
	MailPass                                   string `json:"mail_pass,omitempty"`
	MailStatus                                 string `json:"Mail_Status,omitempty"`
	PromotionalCode                            string `json:"Promotional_Code,omitempty"`
	Interests                                  string `json:"Interests,omitempty"`
	Note                                       string `json:"Note,omitempty"`
	GlobalMailHTMLFooter                       string `json:"Global_Mail_HTML_Footer,omitempty"`
	GlobalMailTextFooter                       string `json:"Global_Mail_Text_Footer,omitempty"`
	LinkTrackURL                               string `json:"Link_Track_URL,omitempty"`
	OpenTrackURL                               string `json:"Open_Track_URL,omitempty"`
	SalsifiedBOOLVALUE                         string `json:"salsified_BOOLVALUE,omitempty"`
	Salsified                                  bool   `json:"salsified,omitempty"`
	StatusLastModified                         string `json:"Status_Last_Modified,omitempty"`
	DateTrialStarted                           string `json:"Date_Trial_Started,omitempty"`
	ContractDate                               string `json:"Contract_Date,omitempty"`
	ToolsInContract                            string `json:"Tools_In_Contract,omitempty"`
	ClosedDate                                 string `json:"Closed_Date,omitempty"`
	ClosedReason                               string `json:"Closed_Reason,omitempty"`
	DefaultEmailAddress                        string `json:"default_email_address,omitempty"`
	DefaultMerchantAccountKey                  string `json:"default_merchant_account_Key,omitempty"`
	MovedBOOLVALUE                             string `json:"moved_BOOLVALUE,omitempty"`
	Moved                                      bool   `json:"moved,omitempty"`
	BlastNotificationEmail                     string `json:"Blast_Notification_Email,omitempty"`
	Country                                    string `json:"Country,omitempty"`
	ListSize                                   string `json:"List_Size,omitempty"`
	Usages                                     string `json:"Usages,omitempty"`
	HearAboutUs                                string `json:"hear_about_us,omitempty"`
	Tier                                       string `json:"Tier,omitempty"`
	TaxStatus                                  string `json:"Tax_Status,omitempty"`
	StaffContact                               string `json:"Staff_Contact,omitempty"`
	LanguageCode                               string `json:"language_code,omitempty"`
	DisableTokenAuthenticationBOOLVALUE        string `json:"Disable_Token_Authentication_BOOLVALUE,omitempty"`
	DisableTokenAuthentication                 bool   `json:"Disable_Token_Authentication,omitempty"`
	EnforcePackagePermissions                  string `json:"Enforce_Package_Permissions,omitempty"`
	RecommendedMailServer                      string `json:"recommended_mail_server,omitempty"`
	OverrideMailServerBOOLVALUE                string `json:"override_mail_server_BOOLVALUE,omitempty"`
	OverrideMailServer                         bool   `json:"override_mail_server,omitempty"`
	EmailBlastBrandingOptOutBOOLVALUE          string `json:"Email_Blast_Branding_Opt_Out_BOOLVALUE,omitempty"`
	EmailBlastBrandingOptOut                   bool   `json:"Email_Blast_Branding_Opt_Out,omitempty"`
	ExternalClientID                           string `json:"external_client_id,omitempty"`
	RecommendEmailBlastBrandingOptOutBOOLVALUE string `json:"Recommend_Email_Blast_Branding_Opt_Out_BOOLVALUE,omitempty"`
	RecommendEmailBlastBrandingOptOut          bool   `json:"Recommend_Email_Blast_Branding_Opt_Out,omitempty"`
	OrganizationID                             string `json:"organization_id,omitempty"`
	WebsiteForcedBrandingRequiredBOOLVALUE     string `json:"Website_Forced_Branding_Required_BOOLVALUE,omitempty"`
	WebsiteForcedBrandingRequired              bool   `json:"Website_Forced_Branding_Required,omitempty"`
	AuthenticateEmailsBOOLVALUE                string `json:"Authenticate_Emails_BOOLVALUE,omitempty"`
	AuthenticateEmails                         bool   `json:"Authenticate_Emails,omitempty"`
	EnforceAutodedupeOnEmailSendBOOLVALUE      string `json:"enforce_autodedupe_on_email_send_BOOLVALUE,omitempty"`
	EnforceAutodedupeOnEmailSend               bool   `json:"enforce_autodedupe_on_email_send,omitempty"`
	EnforceHTTPSBOOLVALUE                      string `json:"enforce_https_BOOLVALUE,omitempty"`
	EnforceHTTPS                               bool   `json:"enforce_https,omitempty"`
}

Organization describes a record for an Salsa Classic client. Be aware that the bulk of the non-identity and non-status fields have been deprecated.

type Results

type Results struct {
	Object   string   `json:"object"`
	Key      string   `json:"key"`
	Result   string   `json:"result"`
	Messages []string `json:"messages"`
}

Results is returned by API calls.

type SalsaTimestamp

type SalsaTimestamp struct {
	time.Time
}

SalsaTimestamp provides a way to unmarshal Salsa's time into a time object. Salsa's time is "" when exported. The desired time should be ""/ Many thanks to OneOfOne https://stackoverflow.com/questions/25087960/json-unmarshal-time-that-isnt-in-rfc-3339-format

func (*SalsaTimestamp) IsSet

func (ct *SalsaTimestamp) IsSet() bool

IsSet returns true if the provided timestamp is not empty.

func (*SalsaTimestamp) MarshalDate

func (ct *SalsaTimestamp) MarshalDate() ([]byte, error)

MarshalJSON converts a Time into a Salsa timestamp string.

func (*SalsaTimestamp) MarshalJSON

func (ct *SalsaTimestamp) MarshalJSON() ([]byte, error)

MarshalJSON converts a Time into a Salsa timestamp string.

func (*SalsaTimestamp) UnmarshalJSON

func (ct *SalsaTimestamp) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON parses a byte slice in Salsa format and stores a time object.

type Table

type Table struct {
	*API
	Name string
}

Table links an API to a Salsa database table.

func (*Table) Count

func (t *Table) Count(c string) (string, error)

Count returns the number of records in the table that match the criteria. You're responsible for providing valid criteria for the selected table. To just count records, pass an empty string in the criteria.

func (*Table) Delete

func (t *Table) Delete(key string, target interface{}) error

Delete does a Salsa API /delete. The caller provides a key. We whack that record.

func (*Table) Describe

func (t *Table) Describe() (f FieldList, err error)

Describe returns the table structure as an array of field descriptors.

func (*Table) LeftJoin

func (t *Table) LeftJoin(offset int32, count int, crit string, target interface{}) error

LeftJoin reads two or more tables from the database. The tables are joined on the primary key of the left table. For example, to find supporters and their donations would require a table join statement like 'supporter(supporter_KEY)donation'. The field supporter_KEY is the primary key in supporter and a foreign key in donation.

LeftJoin reads staring at offset. It will retrieve either count or 500 records, whichever is smaller. If crit is defined, then that is added to the URL as a condition to limit the number of supporters.

The target is a slice of schemas. The schemas contain the fields that you'd like to see. Be sure to use the form "table.fieldName" in the JSON extensions to assure that the data is retrieved correctly.

func (*Table) LeftJoinMap

func (t *Table) LeftJoinMap(offset int32, count int, crit string) ([]map[string]string, error)

LeftJoinMap reads from Salsa and returns an array of maps. The results are unmarshalled using gjson. Each map containsa single record.

func (*Table) LeftJoinRaw

func (t *Table) LeftJoinRaw(offset int32, count int, crit string) ([]byte, error)

LeftJoinRaw does a left join using Salsa's API and returns a buffer of bytes.

func (*Table) Many

func (t *Table) Many(offset int32, count int, crit string, target interface{}) error

Many reads many records from a table. Reading starts at offset and retrieves count records. Salsa will never return more than 500 records, however. The target is a slice of records that match the table schema. Many automatically unmarshals from JSON into the target. An empty target indicates end of data.

func (*Table) ManyMap

func (t *Table) ManyMap(offset int32, count int, crit string) ([]map[string]string, error)

ManyMap returns an array of records. Each record is a map of field names and values. An empty array indicates end of data.

func (*Table) ManyMapTagged

func (t *Table) ManyMapTagged(offset int32, count int, crit string, tag string) ([]map[string]string, error)

ManyMapTagged returns an array of records that have a common tag. Each record is a map of field names and values. An empty array indicates end of data.

func (*Table) ManyRaw

func (t *Table) ManyRaw(offset int32, count int, crit string) ([]byte, error)

ManyRaw reads many records from a table. Reading starts at offset and retrieves count records. Salsa will never return more than 500 records, however. The results are unmarshalled data in JSON format.

func (*Table) ManyRawTagged

func (t *Table) ManyRawTagged(offset int32, count int, crit string, tag string) ([]byte, error)

ManyRawTagged reads many records from a table. Records share a common tag. Reading starts at offset and retrieves count records. Salsa will never return more than 500 records, however.

func (*Table) ManyTagged

func (t *Table) ManyTagged(offset int32, count int, crit string, tag string, target interface{}) error

ManyTagged reads many records from a table. Records share a common tag. Reading starts at offset and retrieves count records. Salsa will never return more than 500 records, however.

The target is a slice of records that match the table schema. Many automatically unmarshals from JSON into the target. An empty target indicates end of data.

func (*Table) One

func (t *Table) One(key string, target interface{}) error

One retrieves a single record using the provided primary key. The target is the address of a record schema, which defines which fields will be returned. Note that there is not currently a way to retrieve all fields into a schema. Use ManyMap to do that.

func (*Table) OneMap

func (t *Table) OneMap(key string) (map[string]string, error)

OneMap retrieves a single record using the provided primary key. The returned record is a map of names and values. Everything is a string.

func (*Table) OneRaw

func (t *Table) OneRaw(key string) ([]byte, error)

OneRaw retrieves a single record using the provided primary key. Returns the buffer retrieved from the URL.

func (*Table) Save

func (t *Table) Save(key string, s string) ([]byte, error)

Save does a Salsa API /save. The caller provides a buffer of fields to changed in the form "fieldname=value".

The buffer can be inordinately long. Salsa may not process a truly long buffer. YMWV.

func (*Table) SaveBulk

func (t *Table) SaveBulk(s string) ([]byte, error)

SaveBulk does a Salsa API /save. The caller provides the contents of the body for a POST. In general, the contents can be characterized as "&object=" followed by the table name, "&key=" followed by zero or the primary key and multiple instances of "&FieldName=Value" SaveBulk returns the body of the response and an error

Jump to

Keyboard shortcuts

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