2016-11-24 13:18:40 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2016-12-11 13:50:01 +00:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2016-12-23 14:49:23 +00:00
|
|
|
|
|
|
|
"github.com/dannyvankooten/ana/count"
|
2016-11-24 13:18:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// URL: /api/screen-resolutions
|
|
|
|
var GetScreenResolutionsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2016-12-11 13:50:01 +00:00
|
|
|
before, after := getRequestedPeriods(r)
|
2016-11-24 13:18:40 +00:00
|
|
|
|
2016-12-11 13:50:01 +00:00
|
|
|
// get total
|
|
|
|
total := count.Visitors(before, after)
|
2016-11-24 13:18:40 +00:00
|
|
|
|
2016-12-11 13:50:01 +00:00
|
|
|
// get rows
|
2016-12-23 14:49:23 +00:00
|
|
|
results := count.Screens(before, after, getRequestedLimit(r), total)
|
2016-11-24 13:18:40 +00:00
|
|
|
|
2016-12-11 13:50:01 +00:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
json.NewEncoder(w).Encode(results)
|
2016-11-24 13:18:40 +00:00
|
|
|
})
|