internal

package
v0.0.0-...-028b85c Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrNotConfigured is used when SlackOverflow is not configured
	ErrNotConfigured = "You must execute 'slackoverflow reconfigure' or correct errors in ~/.slackoverflow/slackoverflow.yaml"
)

Variables

View Source
var (
	// Name of the application
	Name = "slackoverflow"
	// Version number
	Version = "17.11.10"
	// ShortDesc of the app
	ShortDesc = "Slackoverflow enables you to post tagged Stack Overflow questions to Slack, updated using reaction emojis."
	// BuildDate of the application
	BuildDate = "2017-11-10T01:18:26+02:00"
	// Contributors of the application
	Contributors = []string{
		"Marko Kungla <marko.kungla@gmail.com>",
	}
	// CLIheader template
	CLIheader = `` /* 347-byte string literal not displayed */

	// CLIfooter template
	CLIfooter = `` /* 191-byte string literal not displayed */

)

Functions

func HTTPGet

func HTTPGet(host string, path string, qp map[string]string, collection interface{}) error

HTTPGet make Get request

func HTTPGetByURL

func HTTPGetByURL(url string, collection interface{}) error

HTTPGetByURL make Get request

Types

type BadgeCountsObj

type BadgeCountsObj struct {
	Bronze int `json:"bronze"`
	Silver int `json:"silver"`
	Gold   int `json:"gold"`
}

BadgeCountsObj of Stack Exchange User

type Config

type Config struct {
	Slack         SlackConfig         `yaml:"slack"`
	StackExchange StackExchangeConfig `yaml:"stackexchange"`
	// contains filtered or unexported fields
}

Config of SlackOverflow

func (*Config) IsLoaded

func (c *Config) IsLoaded() bool

IsLoaded returns true if configuration has been loaded

func (*Config) Save

func (c *Config) Save() error

Save the configuration file

type Database

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

Database for SlackOverflow

func (*Database) Close

func (d *Database) Close() error

Close the database

func (*Database) FindSlackQuestion

func (d *Database) FindSlackQuestion(QID int) SlackQuestion

FindSlackQuestion link

func (*Database) FindStackExchangeQuestion

func (d *Database) FindStackExchangeQuestion(QID int) StackExchangeQuestion

FindStackExchangeQuestion by ID

func (*Database) FindStackExchangeUser

func (d *Database) FindStackExchangeUser(UID int) StackExchangeUser

FindStackExchangeUser by ID

func (*Database) LatestStackExchangeQuestion

func (d *Database) LatestStackExchangeQuestion() (StackExchangeQuestion, error)

LatestStackExchangeQuestion return latest locl question if any

func (*Database) SetPath

func (d *Database) SetPath(file path.Obj)

SetPath to sqllite database file

func (*Database) SlackQuestionCreate

func (d *Database) SlackQuestionCreate(slq SlackQuestion) (msg string, err error)

SlackQuestionCreate new Question

func (*Database) SlackQuestionDelete

func (d *Database) SlackQuestionDelete(slq SlackQuestion) error

SlackQuestionDelete by ID

func (*Database) SlackQuestionGetAll

func (d *Database) SlackQuestionGetAll() (links []SlackQuestion, count int)

SlackQuestionGetAll linked questions

func (*Database) StackExchangeQuestionCreate

func (d *Database) StackExchangeQuestionCreate(seq StackExchangeQuestion) (msg string, err error)

StackExchangeQuestionCreate stores new Question

func (*Database) StackExchangeQuestionDelete

func (d *Database) StackExchangeQuestionDelete(seq StackExchangeQuestion) error

StackExchangeQuestionDelete by ID

func (*Database) StackExchangeQuestionTrackedIds

func (d *Database) StackExchangeQuestionTrackedIds(qToWatch int) (ids string, count int)

StackExchangeQuestionTrackedIds return tracked question ids

func (*Database) StackExchangeQuestionUpdate

func (d *Database) StackExchangeQuestionUpdate(seq StackExchangeQuestion) (msg string, err error)

StackExchangeQuestionUpdate updates existsing question

func (*Database) StackExchangeQuestionsTracked

func (d *Database) StackExchangeQuestionsTracked(qToWatch int) (questions []StackExchangeQuestion, count int)

StackExchangeQuestionsTracked returns tracked questions

func (*Database) StackExchangeUserCreate

func (d *Database) StackExchangeUserCreate(seu StackExchangeUser) (msg string, err error)

StackExchangeUserCreate creates new User

func (*Database) StackExchangeUserUpdate

func (d *Database) StackExchangeUserUpdate(seu StackExchangeUser) (msg string, err error)

StackExchangeUserUpdate existsing User

func (*Database) SyncStackExchangeQuestion

func (d *Database) SyncStackExchangeQuestion(q QuestionObj, site string) (msg string, err error)

SyncStackExchangeQuestion create or update question received from defined site

func (*Database) SyncStackExchangeUserShallowUser

func (d *Database) SyncStackExchangeUserShallowUser(user ShallowUserObj) (msg string, err error)

SyncStackExchangeUserShallowUser Create or update Stack Exchange User

func (*Database) VerifyTables

func (d *Database) VerifyTables(w *cli.Worker) (err error)

VerifyTables of SlackOverflow database

type Paging

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

Paging - https://api.stackexchange.com/docs/paging

func (*Paging) FirstPage

func (p *Paging) FirstPage()

FirstPage sets current page to 1

func (*Paging) GetCurrentPageNr

func (p *Paging) GetCurrentPageNr() int

GetCurrentPageNr return current page number

func (*Paging) HasMore

func (p *Paging) HasMore() bool

HasMore either there are more results

func (*Paging) NextPage

func (p *Paging) NextPage()

NextPage increases page number

func (*Paging) PreviousPage

func (p *Paging) PreviousPage()

PreviousPage decreases page number

func (*Paging) SetPage

func (p *Paging) SetPage(page int)

SetPage sets current page

func (*Paging) SetPageSize

func (p *Paging) SetPageSize(pageSize int)

SetPageSize sets current page

type Parameter

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

Parameter Stack Exchange parameter

func (*Parameter) Decription

func (p *Parameter) Decription() string

Decription of this parameter

func (*Parameter) String

func (p *Parameter) String() string

String value of the parameter

type Parameters

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

Parameters Stack Exchange query parameters

func (*Parameters) Allow

func (p *Parameters) Allow(param string, value interface{}, desc string)

Allow parameter to be set

func (*Parameters) ApplyDefaults

func (p *Parameters) ApplyDefaults()

ApplyDefaults apply default parameters

func (*Parameters) Delete

func (p *Parameters) Delete(param string)

Delete the given parameter

func (*Parameters) GetAllowed

func (p *Parameters) GetAllowed() map[string]Parameter

GetAllowed returns parameters accepted by this endpoint

func (*Parameters) GetApplied

func (p *Parameters) GetApplied() map[string]Parameter

GetApplied returns parameters which have been set

func (*Parameters) IsAllowed

func (p *Parameters) IsAllowed(param string) bool

IsAllowed return true is parameter is allowed by this endpoint

func (*Parameters) IsSet

func (p *Parameters) IsSet(param string) bool

IsSet return true is parameter is set

func (*Parameters) Set

func (p *Parameters) Set(param string, value interface{})

Set adds or moifies a parameter given by the key and value

func (*Parameters) ValueOf

func (p *Parameters) ValueOf(param string) string

ValueOf returns value of given parameter if it is set

type QuestionObj

type QuestionObj struct {
	QID              int            `json:"question_id"`
	Title            string         `json:"title"`
	CreationDate     int64          `json:"creation_date"`
	LastActivityDate int64          `json:"last_activity_date"`
	Owner            ShallowUserObj `json:"owner"`
	IsAnswered       bool           `json:"is_answered"`
	ShareLink        string         `json:"share_link"`
	ClosedReason     string         `json:"closed_reason"`
	Tags             []string       `json:"tags"`
	Score            int            `json:"score"`
	ViewCount        int            `json:"view_count"`
	AnswerCount      int            `json:"answer_count"`
	CommentCount     int            `json:"comment_count"`
	UpVoteCount      int            `json:"up_vote_count"`
	DownVoteCount    int            `json:"down_vote_count"`
	DeleteVoteCount  int            `json:"delete_vote_count"`
	FavoriteCount    int            `json:"favorite_count"`
	ReOpenVoteCount  int            `json:"reopen_vote_count"`
}

QuestionObj is question item returned by StackExchange API

type Questions

type Questions struct {
	Client     *StackExchangeClient
	Parameters Parameters
	Paging
	Result *QuestionsWrapperObj
}

Questions - https://api.stackexchange.com/docs/questions-by-ids

func (*Questions) DrawQuery

func (q *Questions) DrawQuery(w *cli.Worker, ids string)

DrawQuery output table of questions query

func (*Questions) Get

func (q *Questions) Get(ids string) (bool, error)

Get request

func (*Questions) GetURL

func (q *Questions) GetURL(ids string) (string, error)

GetURL composed from current parameters

func (*Questions) Init

func (q *Questions) Init()

Init initializes Questions module

type QuestionsWrapperObj

type QuestionsWrapperObj struct {
	Backoff        int           `json:"backoff"`
	ErrorID        int           `json:"error_id"`
	ErrorName      string        `json:"error_name"`
	ErrorMessage   string        `json:"error_message"`
	HasMore        bool          `json:"has_more"`
	Page           int           `json:"page"`
	QuotaMax       int           `json:"quota_max"`
	QuotaRemaining int           `json:"quota_remaining"`
	Items          []QuestionObj `json:"items"`
}

QuestionsWrapperObj is a API response type

type SearchAdvanced

type SearchAdvanced struct {
	Client     *StackExchangeClient
	Parameters Parameters
	Paging
	Result *QuestionsWrapperObj
}

SearchAdvanced - https://api.stackexchange.com/docs/advanced-search

func (*SearchAdvanced) DrawQuery

func (sa *SearchAdvanced) DrawQuery(w *cli.Worker)

DrawQuery output table of search query

func (*SearchAdvanced) Get

func (sa *SearchAdvanced) Get() (bool, error)

Get request

func (*SearchAdvanced) GetURL

func (sa *SearchAdvanced) GetURL() (string, error)

GetURL composed from current parameters

func (*SearchAdvanced) Init

func (sa *SearchAdvanced) Init()

Init initializes Search Advanced module

type ShallowUserObj

type ShallowUserObj struct {
	UID          int            `json:"user_id"`
	Reputation   int            `json:"reputation"`
	ProfileImage string         `json:"profile_image"`
	DisplayName  string         `json:"display_name"`
	Link         string         `json:"link"`
	AcceptRate   int            `json:"accept_rate"`
	BadgeCounts  BadgeCountsObj `json:"badge_counts"`
}

ShallowUserObj returned by Stack Exchange API

type SlackConfig

type SlackConfig struct {
	Enabled     bool           `yaml:"enabled"`
	TeamURL     bool           `yaml:"team-url"`
	Channel     string         `yaml:"channel"`
	ChannelName string         `yaml:"channel-name"`
	Token       string         `yaml:"token"`
	APIHost     string         `yaml:"api-host"`
	TeamInfo    slack.TeamInfo `yaml:"team-info"`
}

SlackConfig for Slack Overflow

func (*SlackConfig) Disable

func (s *SlackConfig) Disable()

Disable posting and updating to Slack

func (*SlackConfig) Enable

func (s *SlackConfig) Enable()

Enable posting and updating to Slack

func (*SlackConfig) SetAPIhost

func (s *SlackConfig) SetAPIhost(h string)

SetAPIhost for Slack API

func (*SlackConfig) SetChannel

func (s *SlackConfig) SetChannel(ch string)

SetChannel sets the slack channel where questions will be posted

func (*SlackConfig) SetChannelName

func (s *SlackConfig) SetChannelName(n string)

SetChannelName sets the name of the slack channel where questions will be posted

func (*SlackConfig) SetTeamInfo

func (s *SlackConfig) SetTeamInfo(t *slack.TeamInfo)

SetTeamInfo for current Slack configuration

func (*SlackConfig) SetToken

func (s *SlackConfig) SetToken(t string)

SetToken sets Slack API token

type SlackOverflow

type SlackOverflow struct {
	// Path retursn SlackOverflow config path
	Path             path.Obj
	ConfigFilePath   path.Obj
	DatabaseFilePath path.Obj
	Config           Config
	DB               Database
	StackExchange    StackExchangeClient
}

SlackOverflow application instance

func NewSlackOverflow

func NewSlackOverflow() *SlackOverflow

NewSlackOverflow instance

func (*SlackOverflow) IsConfigured

func (so *SlackOverflow) IsConfigured() (bool, error)

IsConfigured returns false with error if SlackOverflow is not configured

func (*SlackOverflow) Load

func (so *SlackOverflow) Load(w *cli.Worker) (err error)

Load SlackOverflow and try to load configuration from given path

func (*SlackOverflow) Session

func (so *SlackOverflow) Session(w *cli.Worker) error

Session loads everything for SlackOverfloe

func (*SlackOverflow) SyncQuestion

func (so *SlackOverflow) SyncQuestion(w *cli.Worker, q QuestionObj)

SyncQuestion questions

type SlackQuestion

type SlackQuestion struct {
	// Id of StackExchangeQuestion question
	QID     int
	Channel string
	TS      string
}

SlackQuestion table Records in this table keep track of qustions between Stack Exchange and Slack

type StackExchangeClient

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

StackExchangeClient to call Stack Exchange API

func (*StackExchangeClient) GetEndpont

func (s *StackExchangeClient) GetEndpont(path string) (*url.URL, error)

GetEndpont returns base endpoint

func (*StackExchangeClient) GetQuotaMax

func (s *StackExchangeClient) GetQuotaMax() int

GetQuotaMax return maximum allowed quota

func (*StackExchangeClient) GetQuotaRemaining

func (s *StackExchangeClient) GetQuotaRemaining() int

GetQuotaRemaining return remaining quota for today

func (*StackExchangeClient) Questions

func (s *StackExchangeClient) Questions() *Questions

Questions https://api.stackexchange.com/docs/questions-by-ids

func (*StackExchangeClient) SearchAdvanced

func (s *StackExchangeClient) SearchAdvanced() *SearchAdvanced

SearchAdvanced https://api.stackexchange.com/docs/advanced-search

func (*StackExchangeClient) SetAPIVersion

func (s *StackExchangeClient) SetAPIVersion(varsion string)

SetAPIVersion set Stack Exchange API version

func (*StackExchangeClient) SetHost

func (s *StackExchangeClient) SetHost(host string)

SetHost set Stack Exchange API host

func (*StackExchangeClient) SetKey

func (s *StackExchangeClient) SetKey(apiKey string)

SetKey Set Stack Exchange API to receive a higher request quota if exists

func (*StackExchangeClient) SetQuotaMax

func (s *StackExchangeClient) SetQuotaMax(quotaMax int)

SetQuotaMax set maximum allowed quota

func (*StackExchangeClient) SetQuotaRemaining

func (s *StackExchangeClient) SetQuotaRemaining(quotaRemaining int)

SetQuotaRemaining set remaining quota for today

type StackExchangeConfig

type StackExchangeConfig struct {
	Enabled          bool              `yaml:"enabled"`
	Key              string            `yaml:"key"`
	APIVersion       string            `yaml:"api-version"`
	APIHost          string            `yaml:"api-host"`
	Site             string            `yaml:"site"`
	QuestionsToWatch int               `yaml:"questions-to-watch"`
	SearchAdvanced   map[string]string `yaml:"search-advanced"`
	Questions        map[string]string `yaml:"questions"`
}

StackExchangeConfig for Slack Overflow

func (*StackExchangeConfig) Disable

func (s *StackExchangeConfig) Disable()

Disable Stack Exchange

func (*StackExchangeConfig) Enable

func (s *StackExchangeConfig) Enable()

Enable Stack Exchange

func (*StackExchangeConfig) SetAPIVersion

func (s *StackExchangeConfig) SetAPIVersion(v string)

SetAPIVersion for Stack Exchange API

func (*StackExchangeConfig) SetAPIhost

func (s *StackExchangeConfig) SetAPIhost(h string)

SetAPIhost for Stack Exchange API

type StackExchangeQuestion

type StackExchangeQuestion struct {
	QID              int
	UID              int
	Title            string
	CreationDate     time.Time
	LastActivityDate time.Time
	ShareLink        string
	ClosedReason     string
	Tags             string
	Site             string
	IsAnswered       bool
	Score            int
	ViewCount        int
	AnswerCount      int
	CommentCount     int
	UpVoteCount      int
	DownVoteCount    int
	DeleteVoteCount  int
	FavoriteCount    int
	ReOpenVoteCount  int
}

StackExchangeQuestion table

type StackExchangeUser

type StackExchangeUser struct {
	UID          int
	DisplayName  string
	ProfileImage string
	Link         string
	Reputation   int
	AcceptRate   int
	BadgeBronze  int
	BadgeSilver  int
	BadgeGold    int
}

StackExchangeUser table

type Table

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

Table struct when generating table view in console

func NewTable

func NewTable(h ...string) *Table

NewTable creates new table

func (*Table) AddRow

func (t *Table) AddRow(a ...interface{})

AddRow to the table

func (*Table) Print

func (t *Table) Print()

Print the table

type TableCol

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

TableCol is struct for column in table

Jump to

Keyboard shortcuts

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