Browse Source

Switches to the new traffic API format (#462)

Fixes #458
Fabrice Vaillant 9 years ago
committed by Will Norris
parent
commit
f7fcf6f52f
2 changed files with 8 additions and 31 deletions
  1. +4
    -27
      github/repos_traffic.go
  2. +4
    -4
      github/repos_traffic_test.go

+ 4
- 27
github/repos_traffic.go View File

@ -5,11 +5,7 @@
package github package github
import (
"fmt"
"strconv"
"time"
)
import "fmt"
// TrafficReferrer represent information about traffic from a referrer . // TrafficReferrer represent information about traffic from a referrer .
type TrafficReferrer struct { type TrafficReferrer struct {
@ -26,30 +22,11 @@ type TrafficPath struct {
Uniques *int `json:"uniques,omitempty"` Uniques *int `json:"uniques,omitempty"`
} }
// TimestampMS represents a timestamp as used in datapoint.
//
// It's only used to parse the result given by the API which are unix timestamp in milliseonds.
type TimestampMS struct {
time.Time
}
// UnmarshalJSON parse unix timestamp.
func (t *TimestampMS) UnmarshalJSON(b []byte) error {
s := string(b)
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
// We can drop the reaminder as returned values are days and it will always be 0
*t = TimestampMS{time.Unix(i/1000, 0)}
return nil
}
// TrafficData represent information about a specific timestamp in views or clones list. // TrafficData represent information about a specific timestamp in views or clones list.
type TrafficData struct { type TrafficData struct {
Timestamp *TimestampMS `json:"timestamp,omitempty"`
Count *int `json:"count,omitempty"`
Uniques *int `json:"uniques,omitempty"`
Timestamp *Timestamp `json:"timestamp,omitempty"`
Count *int `json:"count,omitempty"`
Uniques *int `json:"uniques,omitempty"`
} }
// TrafficViews represent information about the number of views in the last 14 days. // TrafficViews represent information about the number of views in the last 14 days.


+ 4
- 4
github/repos_traffic_test.go View File

@ -83,7 +83,7 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) {
fmt.Fprintf(w, `{"count": 7, fmt.Fprintf(w, `{"count": 7,
"uniques": 6, "uniques": 6,
"views": [{ "views": [{
"timestamp": 1464710400000,
"timestamp": "2016-05-31T16:00:00.000Z",
"count": 7, "count": 7,
"uniques": 6 "uniques": 6
}]}`) }]}`)
@ -96,7 +96,7 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) {
want := &TrafficViews{ want := &TrafficViews{
Views: []*TrafficData{{ Views: []*TrafficData{{
Timestamp: &TimestampMS{time.Unix(1464710400, 0)},
Timestamp: &Timestamp{time.Date(2016, time.May, 31, 16, 0, 0, 0, time.UTC)},
Count: Int(7), Count: Int(7),
Uniques: Int(6), Uniques: Int(6),
}}, }},
@ -120,7 +120,7 @@ func TestRepositoriesService_ListTrafficClones(t *testing.T) {
fmt.Fprintf(w, `{"count": 7, fmt.Fprintf(w, `{"count": 7,
"uniques": 6, "uniques": 6,
"clones": [{ "clones": [{
"timestamp": 1464710400000,
"timestamp": "2016-05-31T16:00:00.00Z",
"count": 7, "count": 7,
"uniques": 6 "uniques": 6
}]}`) }]}`)
@ -133,7 +133,7 @@ func TestRepositoriesService_ListTrafficClones(t *testing.T) {
want := &TrafficClones{ want := &TrafficClones{
Clones: []*TrafficData{{ Clones: []*TrafficData{{
Timestamp: &TimestampMS{time.Unix(1464710400, 0)},
Timestamp: &Timestamp{time.Date(2016, time.May, 31, 16, 0, 0, 0, time.UTC)},
Count: Int(7), Count: Int(7),
Uniques: Int(6), Uniques: Int(6),
}}, }},


Loading…
Cancel
Save