fetch

package
v0.0.0-...-8f4005c Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2016 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var QuickStatsApi = ChartbeatApi{
	ChartbeatUrl{"live/quickstats/v4", "all_platforms=1&loyalty=1"},
	"quickstats",
	Quickstats{},
}
View Source
var RecentApi = ChartbeatApi{
	ChartbeatUrl{"live/recent/v3", ""},
	"recent",
	Recent{},
}
View Source
var ReferrersApi = ChartbeatApi{
	ChartbeatUrl{"live/referrers/v3", ""},
	"referrers",
	Referrers{},
}
View Source
var TopGeoApi = ChartbeatApi{
	ChartbeatUrl{"live/top_geo/v1", ""},
	"topgeo",
	TopGeo{},
}
View Source
var TopPagesApi = ChartbeatApi{
	ChartbeatUrl{"live/toppages/v3", "all_platforms=1&loyalty=1"},
	"popular",
	TopPages{},
}

TODO add back visits calculations

View Source
var TrafficSeriesApi = ChartbeatApi{
	ChartbeatUrl{"historical/traffic/series", ""},
	"traffic-series",
	TrafficSeries{},
}

* The beats

Functions

func AddUrlParams

func AddUrlParams(urls []string, queryString string) []string

Add query string to the end of the each url in an array of urls. Expects that some url params are already added

AddUrlParam(["http://google.com?test=123", "http://yahoo.com?test=abc"], "test2=added")

Result:

["http://google.com?test=123&test2=added", "http://yahoo.com?test=abc&test2=added"]

func CalculateTimeInterval

func CalculateTimeInterval(articles []*mc.TopArticle, session *mgo.Session)

func FormatChartbeatUrls

func FormatChartbeatUrls(endPoint string, sites []string, apiKey string) ([]string, error)

Format chartbeat URLs based on a chartbeat API endpoint

Format: http://api.chartbeat.com/<endPoint>/?apikey=<key>&host=<site[i]>&

Example endPoint (NOTE no starting or ending slashes): live/toppages/v3

func GetHostFromParams

func GetHostFromParams(inputUrl string) (string, error)

Chartbeat queries have a GET parameter "host", which represents the host we're getting data on. Pull the host from the url and return it. Return host (e.g. freep.com) Return "" if we don't find one

func GetQuickStats

func GetQuickStats(url string) (*m.QuickStats, error)

func GetRecents

func GetRecents(url string) (*m.RecentResp, error)

func GetTopGeo

func GetTopGeo(url string) (*m.TopGeo, error)

func GetTopPages

func GetTopPages(url string) (*mc.TopPages, error)

Given a URL for the api.chartbeat.com/live/toppages/v3 API, get the data and read the response

func SortQuickStats

func SortQuickStats(quickStats []*m.QuickStats) []*m.QuickStats

func SortTopArticles

func SortTopArticles(articles []*mc.TopArticle) []*mc.TopArticle

Types

type Beat

type Beat interface {
	Run(*mgo.Session, string, string, []string)
}

Types Beat type to be called from command package

type ByVisits

type ByVisits []*mc.TopArticle

* Sorting stuff

func (ByVisits) Len

func (a ByVisits) Len() int

func (ByVisits) Less

func (a ByVisits) Less(i, j int) bool

func (ByVisits) Swap

func (a ByVisits) Swap(i, j int)

type ChartbeatApi

type ChartbeatApi struct {
	Url           ChartbeatUrl
	MapiEndpoints string         // comma-separated list of mapi endpoints to hit e.g. "quickstats,toppages,traffic-series"
	Fetch         ChartbeatFetch // Interface in fetch/chartbeat/ that will fetch the chartbeat info
}

ChartbeatApi to be used in the chartbeat package

func (ChartbeatApi) Run

func (c ChartbeatApi) Run(session *mgo.Session, apiKey, gnapiDomain string, sites []string)

type ChartbeatFetch

type ChartbeatFetch interface {
	Fetch([]string, *mgo.Session) m.Snapshot
}

type ChartbeatUrl

type ChartbeatUrl struct {
	ChartbeatEndpoint string // https://api.chartbeat.com API endpoint
	ChartbeatParams   string // Urls params for chartbeat url, "" to specify none
}

func (ChartbeatUrl) Urls

func (u ChartbeatUrl) Urls(apiKey string, sites []string) []string

type QuickStatsSort

type QuickStatsSort []*m.QuickStats

func (QuickStatsSort) Len

func (q QuickStatsSort) Len() int

func (QuickStatsSort) Less

func (q QuickStatsSort) Less(i, j int) bool

func (QuickStatsSort) Swap

func (q QuickStatsSort) Swap(i, j int)

type Quickstats

type Quickstats struct{}

func (Quickstats) Fetch

func (q Quickstats) Fetch(urls []string, session *mgo.Session) m.Snapshot

type Recent

type Recent struct{}

func (Recent) Fetch

func (r Recent) Fetch(urls []string, session *mgo.Session) m.Snapshot

type Referrers

type Referrers struct{}

func (Referrers) Fetch

func (r Referrers) Fetch(urls []string, session *mgo.Session) m.Snapshot

type TopGeo

type TopGeo struct{}

func (TopGeo) Fetch

func (t TopGeo) Fetch(urls []string, session *mgo.Session) m.Snapshot

type TopPages

type TopPages struct{}

func (TopPages) Fetch

func (t TopPages) Fetch(urls []string, session *mgo.Session) mc.Snapshot

Fetch the top pages data for each url in the urls parameter. Url expected to be http://api.chartbeat.com/live/toppages/v3

type TrafficSeries

type TrafficSeries struct {
	Data struct {
		Start int `json:"start"`
		End   int `json:"end"`
		// frequency is the data sample interval in minutes
		Frequency int `json:"frequency"`

		// Michigan.com
		Freep       *m.TrafficSeriesIn `json:"freep.com"`
		DetroitNews *m.TrafficSeriesIn `json:"detroitnews.com"`
		BattleCreek *m.TrafficSeriesIn `json:"battlecreekenquirer.com"`
		Hometown    *m.TrafficSeriesIn `json:"hometownlife.com"`
		Lansing     *m.TrafficSeriesIn `json:"lansingstatejournal.com"`
		Livingston  *m.TrafficSeriesIn `json:"livingstondaily.com"`
		Herald      *m.TrafficSeriesIn `json:"thetimesherald.com"`

		// Usat
		UsaToday *m.TrafficSeriesIn `json:"usatoday.com"`

		// Tennessean
		Tennessean *m.TrafficSeriesIn `json:"tennessean.com"`

		// Central Ohio omg why are there so many sites help
		Mansfield        *m.TrafficSeriesIn `json:"mansfieldnewsjournal.com"`
		Newark           *m.TrafficSeriesIn `json:"newarkadvocate.com"`
		Zanesville       *m.TrafficSeriesIn `json:"zanesvilletimesrecorder.com"`
		Chillicothe      *m.TrafficSeriesIn `json:"chillicothegazette.com"`
		Lancaster        *m.TrafficSeriesIn `json:"lancastereaglegazette.com"`
		Marion           *m.TrafficSeriesIn `json:"marionstar.com"`
		TheNewsMessenger *m.TrafficSeriesIn `json:"thenews-messenger.com"`
		Coshocton        *m.TrafficSeriesIn `json:"coshoctontribune.com"`
		Bucyrus          *m.TrafficSeriesIn `json:"bucyrustelegraphforum.com"`
		PortClinton      *m.TrafficSeriesIn `json:"portclintonnewsherald.com"`

		// Central Ohio omg why are there so many sites help
		DesMoines    *m.TrafficSeriesIn `json:"desmoinesregister.com"`
		PressCitizen *m.TrafficSeriesIn `json:"press-citizen.com"`
		Juice        *m.TrafficSeriesIn `json:"dmjuice.com"`
		HawkCentral  *m.TrafficSeriesIn `json:"hawkcentral.com"`
	} `json:"data"`
}

func (TrafficSeries) Fetch

func (h TrafficSeries) Fetch(urls []string, session *mgo.Session) m.Snapshot

func (*TrafficSeries) GetSeries

func (h *TrafficSeries) GetSeries() *m.TrafficSeriesIn

func (*TrafficSeries) SignalMapi

func (h *TrafficSeries) SignalMapi()

func (*TrafficSeries) String

func (h *TrafficSeries) String() string

Jump to

Keyboard shortcuts

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