telegraph/get_views.go

33 lines
848 B
Go
Raw Normal View History

2017-09-04 21:09:59 +00:00
package telegraph
import (
2018-07-27 11:51:14 +00:00
gopath "path"
2017-09-04 21:09:59 +00:00
"strconv"
2018-07-27 11:51:14 +00:00
"time"
2017-09-04 21:09:59 +00:00
json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp"
)
// GetViews get the number of views for a Telegraph article. By default, the total number of page
// views will be returned. Returns a PageViews object on success.
2018-07-27 11:51:14 +00:00
func GetViews(path string, date time.Time) (r *PageViews, err error) {
args := http.AcquireArgs()
2018-07-27 11:51:14 +00:00
defer http.ReleaseArgs(args)
args.Add("path", path) // required
args.Add("year", strconv.Itoa(date.Year()))
args.Add("month", strconv.Itoa(int(date.Month())))
args.Add("day", strconv.Itoa(date.Day()))
args.Add("hour", strconv.Itoa(date.Hour()))
dst := new(Response)
dst, err = makeRequest(gopath.Join("getViews", path), args)
2017-09-04 21:09:59 +00:00
if err != nil {
return nil, err
}
2018-07-27 11:51:14 +00:00
r = new(PageViews)
err = json.Unmarshal(*dst.Result, r)
return
2017-09-04 21:09:59 +00:00
}