store

package
v0.0.0-...-2f160bf Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// FollowedEventType when user followes
	FollowedEventType = "followed"

	// UnfollowedEventType when user unfollows
	UnfollowedEventType = "unfollowed"
)
View Source
const (

	// ISODateFormat is the YYYY-MM-DD format
	ISODateFormat = "2006-01-02"
)

Variables

View Source
var (

	// ErrDataNotFound is thrown when query does not find the requested data
	ErrDataNotFound = errors.New("data not found")
)

Functions

func Contains

func Contains(list []int64, val int64) bool

Contains checks for val in list

func DeleteAuthSession

func DeleteAuthSession(ctx context.Context, id string) error

DeleteAuthSession deletes session once it has been used

func DeleteSearchCriterion

func DeleteSearchCriterion(ctx context.Context, id string) error

DeleteSearchCriterion deletes single search criterion

func GetTokenSecret

func GetTokenSecret(ctx context.Context) (token string, err error)

GetTokenSecret returns the secret manager token value

func GetTwitterAPISecrets

func GetTwitterAPISecrets(ctx context.Context) (key, secret string, err error)

GetTwitterAPISecrets returns the secret manager twitter apu values

func IsDataNotFoundError

func IsDataNotFoundError(err error) bool

IsDataNotFoundError checks boolions on whether the error is result of data not found

func NewID

func NewID() string

NewID generates new ID using UUID v4

func NormalizeString

func NormalizeString(val string) string

NormalizeString makes val comparable regardless of case or whitespace

func PrettyDurationSince

func PrettyDurationSince(a time.Time) string

PrettyDurationSince prints pretty duration since date

func SaveAuthSession

func SaveAuthSession(ctx context.Context, s *AuthSession) error

SaveAuthSession persists authenticated user session config

func SaveAuthUser

func SaveAuthUser(ctx context.Context, u *AuthedUser) error

SaveAuthUser saves multiple users

func SaveDailyFollowerState

func SaveDailyFollowerState(ctx context.Context, data *DailyFollowerState) error

SaveDailyFollowerState saves daily follower state

func SaveSearchCriteria

func SaveSearchCriteria(ctx context.Context, c *SearchCriteria) error

SaveSearchCriteria saves search criteria

func ToID

func ToID(val string) string

ToID hashes the passed string into a valid ID

Types

type AuthSession

type AuthSession struct {
	ID     string    `firestore:"id" json:"id"`
	Config string    `firestore:"config" json:"config"`
	On     time.Time `firestore:"on" json:"on"`
}

AuthSession represents the authenticated user session

func GetAuthSession

func GetAuthSession(ctx context.Context, id string) (content *AuthSession, err error)

GetAuthSession retreaves previous saved session config

type AuthedUser

type AuthedUser struct {
	Username          string      `firestore:"username" json:"username"`
	Profile           *SimpleUser `firestore:"profile" json:"profile"`
	AccessTokenKey    string      `firestore:"access_token_key" json:"access_token_key"`
	AccessTokenSecret string      `firestore:"access_token_secret" json:"access_token_secret"`
	UpdatedAt         time.Time   `firestore:"updated_at" json:"updated_at"`
}

AuthedUser represents authenticated user

func GetAllAuthedUsers

func GetAllAuthedUsers(ctx context.Context) (users []*AuthedUser, err error)

GetAllAuthedUsers retreaves all authenticated users

func GetAuthedUser

func GetAuthedUser(ctx context.Context, username string) (user *AuthedUser, err error)

GetAuthedUser check if the authed username is in UI users and creates UI event

type DailyFollowerState

type DailyFollowerState struct {
	Username         string  `firestore:"username" json:"username"`
	StateOn          string  `firestore:"date" json:"date"`
	Followers        []int64 `firestore:"followers" json:"followers"`
	FollowerCount    int     `firestore:"follower_count" json:"follower_count"`
	Friends          []int64 `firestore:"friends" json:"friends"`
	FriendsCount     int     `firestore:"friend_count" json:"friend_count"`
	NewFollowers     []int64 `firestore:"new_followers" json:"new_followers"`
	NewFollowerCount int     `firestore:"new_follower_count" json:"new_follower_count"`
	Unfollowers      []int64 `firestore:"unfollowers" json:"unfollowers"`
	UnfollowerCount  int     `firestore:"unfollower_count" json:"unfollower_count"`
}

DailyFollowerState represents daily follower state

func GetDailyFollowerState

func GetDailyFollowerState(ctx context.Context, username string, day time.Time) (data *DailyFollowerState, err error)

GetDailyFollowerState retreaves follower data for specific date

func GetDailyFollowerStatesSince

func GetDailyFollowerStatesSince(ctx context.Context, username string, since time.Time) (data []*DailyFollowerState, err error)

GetDailyFollowerStatesSince retrieves map of dates and follower count since the specified date HACK: workaround for lack of support for compounded queries. You can only perform range comparisons (<, <=, >, >=) on a single field

func NewDailyFollowerState

func NewDailyFollowerState(username string, date time.Time) *DailyFollowerState

NewDailyFollowerState creates a new instance of the DailyFollowerState

type DailyFollowerStateByDate

type DailyFollowerStateByDate []*DailyFollowerState

DailyFollowerStateByDate is a custom data structure for array of DailyFollowerState

func (DailyFollowerStateByDate) Len

func (s DailyFollowerStateByDate) Len() int

func (DailyFollowerStateByDate) Less

func (s DailyFollowerStateByDate) Less(i, j int) bool

func (DailyFollowerStateByDate) Swap

func (s DailyFollowerStateByDate) Swap(i, j int)

type SearchCriteria

type SearchCriteria struct {
	ID   string `firestore:"id" json:"id" form:"id"`
	User string `firestore:"user" json:"user" form:"user"`

	Name  string `firestore:"name" json:"name" form:"name"`
	Value string `firestore:"value" json:"value" form:"value"`
	Lang  string `firestore:"lang" json:"lang" form:"lang"`

	SinceID int64 `firestore:"since_id" json:"since_id" form:"since_id"`

	Latest    bool `firestore:"latest" json:"latest" form:"latest"`
	HasLink   bool `firestore:"has_link" json:"has_link" form:"has_link"`
	IncludeRT bool `firestore:"include_rt" json:"include_rt" form:"include_rt"`

	PostCountMin int `firestore:"post_count_min" json:"post_count_min" form:"post_count_min"`
	PostCountMax int `firestore:"post_count_max" json:"post_count_max" form:"post_count_max"`

	FaveCountMin int `firestore:"fave_count_min" json:"fave_count_min" form:"fave_count_min"`
	FaveCountMax int `firestore:"fave_count_max" json:"fave_count_max" form:"fave_count_max"`

	FriendCountMin int `firestore:"friend_count_min" json:"friend_count_min" form:"friend_count_min"`
	FriendCountMax int `firestore:"friend_count_max" json:"friend_count_max" form:"friend_count_max"`

	FollowerCountMin int `firestore:"follower_count_min" json:"follower_count_min" form:"follower_count_min"`
	FollowerCountMax int `firestore:"follower_count_max" json:"follower_count_max" form:"follower_count_max"`

	FollowerRatioMin float32 `firestore:"follower_ratio_min" json:"follower_ratio_min" form:"follower_ratio_min"`
	FollowerRatioMax float32 `firestore:"follower_ratio_max" json:"follower_ratio_max" form:"follower_ratio_max"`

	ExecutedOn time.Time `firestore:"updated_on" json:"executed_on" form:"executed_on"`
}

SearchCriteria is the flat version of search criteria for simplicity of form binding

func GetSearchCriteria

func GetSearchCriteria(ctx context.Context, username string) (data []*SearchCriteria, err error)

GetSearchCriteria retreaves all search criteria for specific user

func GetSearchCriterion

func GetSearchCriterion(ctx context.Context, id string) (data *SearchCriteria, err error)

GetSearchCriterion selects single criterion by id

func (*SearchCriteria) FormatedExecutedOn

func (s *SearchCriteria) FormatedExecutedOn() string

FormatedExecutedOn returns RFC822 formated ExecutedOn

type SearchCriteriaByName

type SearchCriteriaByName []*SearchCriteria

SearchCriteriaByName is a custom data structure for array of SearchCriteria

func (SearchCriteriaByName) Len

func (s SearchCriteriaByName) Len() int

func (SearchCriteriaByName) Less

func (s SearchCriteriaByName) Less(i, j int) bool

func (SearchCriteriaByName) Swap

func (s SearchCriteriaByName) Swap(i, j int)

type SimpleTweet

type SimpleTweet struct {
	ID               string      `firestore:"id_str" json:"id_str"`
	CriteriaID       string      `firestore:"criteria_id" json:"criteria_id"`
	ExecutedOn       string      `firestore:"executed_on" json:"executed_on"`
	CreatedAt        time.Time   `firestore:"created_at" json:"created_at"`
	FavoriteCount    int         `firestore:"favorite_count" json:"favorite_count"`
	ReplyCount       int         `firestore:"reply_count" json:"reply_count"`
	RetweetCount     int         `firestore:"retweet_count" json:"retweet_count"`
	IsRT             bool        `firestore:"is_rt" json:"is_rt"`
	Text             string      `firestore:"text" json:"text"`
	Author           *SimpleUser `firestore:"author" json:"author"`
	AuthorIsFriend   bool        `firestore:"author_is_friend" json:"author_is_friend"`
	AuthorIsFollower bool        `firestore:"author_is_follower" json:"author_is_follower"`
}

SimpleTweet is the short version of twitter search result

func (*SimpleTweet) FormatedCreatedAt

func (s *SimpleTweet) FormatedCreatedAt() string

FormatedCreatedAt returns RFC822 formated CreatedAt

type SimpleUser

type SimpleUser struct {

	// User details
	ID           int64     `firestore:"id" json:"id"`
	Username     string    `firestore:"username" json:"username"`
	Name         string    `firestore:"name" json:"name"`
	Description  string    `firestore:"description" json:"description"`
	ProfileImage string    `firestore:"profile_image" json:"profile_image"`
	CreatedAt    time.Time `firestore:"created_at" json:"created_at"`
	UpdatedAt    time.Time `firestore:"updated_at" json:"updated_at"`

	// geo
	Lang     string `firestore:"lang" json:"lang"`
	Location string `firestore:"location" json:"location"`
	Timezone string `firestore:"time_zone" json:"time_zone"`

	// counts
	PostCount     int `firestore:"post_count" json:"post_count"`
	FaveCount     int `firestore:"fave_count" json:"fave_count"`
	FriendCount   int `firestore:"friend_count" json:"friend_count"`
	FollowerCount int `firestore:"followers_count" json:"followers_count"`
	ListedCount   int `firestore:"listed_count" json:"listed_count"`
}

SimpleUser represents simplified Twitter user

func (*SimpleUser) FormatedCreatedAt

func (s *SimpleUser) FormatedCreatedAt() string

FormatedCreatedAt returns RFC822 formated CreatedAt

func (*SimpleUser) UserSince

func (s *SimpleUser) UserSince() string

UserSince displays the length of time since the user joined Twitter s

type SimpleUserEvent

type SimpleUserEvent struct {
	SimpleUser
	EventDate string `firestore:"event_at" json:"event_at"`
	EventType string `firestore:"event_type" json:"event_type"`
	EventUser string `firestore:"event_user" json:"event_user"`
	IsFriend  bool   `firestore:"is_friend" json:"is_friend"`
}

SimpleUserEvent wraps simple twitter user as an time event

type UserEventByDate

type UserEventByDate []*SimpleUserEvent

UserEventByDate is a custom data structure for array of SimpleUserEvent

func (UserEventByDate) Len

func (s UserEventByDate) Len() int

func (UserEventByDate) Less

func (s UserEventByDate) Less(i, j int) bool

func (UserEventByDate) Swap

func (s UserEventByDate) Swap(i, j int)

Jump to

Keyboard shortcuts

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