1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type TrafficReferrer struct {
15 Referrer *string `json:"referrer,omitempty"`
16 Count *int `json:"count,omitempty"`
17 Uniques *int `json:"uniques,omitempty"`
18 }
19
20
21 type TrafficPath struct {
22 Path *string `json:"path,omitempty"`
23 Title *string `json:"title,omitempty"`
24 Count *int `json:"count,omitempty"`
25 Uniques *int `json:"uniques,omitempty"`
26 }
27
28
29 type TrafficData struct {
30 Timestamp *Timestamp `json:"timestamp,omitempty"`
31 Count *int `json:"count,omitempty"`
32 Uniques *int `json:"uniques,omitempty"`
33 }
34
35
36 type TrafficViews struct {
37 Views []*TrafficData `json:"views,omitempty"`
38 Count *int `json:"count,omitempty"`
39 Uniques *int `json:"uniques,omitempty"`
40 }
41
42
43 type TrafficClones struct {
44 Clones []*TrafficData `json:"clones,omitempty"`
45 Count *int `json:"count,omitempty"`
46 Uniques *int `json:"uniques,omitempty"`
47 }
48
49
50
51 type TrafficBreakdownOptions struct {
52 Per string `url:"per,omitempty"`
53 }
54
55
56
57
58 func (s *RepositoriesService) ListTrafficReferrers(ctx context.Context, owner, repo string) ([]*TrafficReferrer, *Response, error) {
59 u := fmt.Sprintf("repos/%v/%v/traffic/popular/referrers", owner, repo)
60
61 req, err := s.client.NewRequest("GET", u, nil)
62 if err != nil {
63 return nil, nil, err
64 }
65
66 var trafficReferrers []*TrafficReferrer
67 resp, err := s.client.Do(ctx, req, &trafficReferrers)
68 if err != nil {
69 return nil, resp, err
70 }
71
72 return trafficReferrers, resp, nil
73 }
74
75
76
77
78 func (s *RepositoriesService) ListTrafficPaths(ctx context.Context, owner, repo string) ([]*TrafficPath, *Response, error) {
79 u := fmt.Sprintf("repos/%v/%v/traffic/popular/paths", owner, repo)
80
81 req, err := s.client.NewRequest("GET", u, nil)
82 if err != nil {
83 return nil, nil, err
84 }
85
86 var paths []*TrafficPath
87 resp, err := s.client.Do(ctx, req, &paths)
88 if err != nil {
89 return nil, resp, err
90 }
91
92 return paths, resp, nil
93 }
94
95
96
97
98 func (s *RepositoriesService) ListTrafficViews(ctx context.Context, owner, repo string, opts *TrafficBreakdownOptions) (*TrafficViews, *Response, error) {
99 u := fmt.Sprintf("repos/%v/%v/traffic/views", owner, repo)
100 u, err := addOptions(u, opts)
101 if err != nil {
102 return nil, nil, err
103 }
104
105 req, err := s.client.NewRequest("GET", u, nil)
106 if err != nil {
107 return nil, nil, err
108 }
109
110 trafficViews := new(TrafficViews)
111 resp, err := s.client.Do(ctx, req, &trafficViews)
112 if err != nil {
113 return nil, resp, err
114 }
115
116 return trafficViews, resp, nil
117 }
118
119
120
121
122 func (s *RepositoriesService) ListTrafficClones(ctx context.Context, owner, repo string, opts *TrafficBreakdownOptions) (*TrafficClones, *Response, error) {
123 u := fmt.Sprintf("repos/%v/%v/traffic/clones", owner, repo)
124 u, err := addOptions(u, opts)
125 if err != nil {
126 return nil, nil, err
127 }
128
129 req, err := s.client.NewRequest("GET", u, nil)
130 if err != nil {
131 return nil, nil, err
132 }
133
134 trafficClones := new(TrafficClones)
135 resp, err := s.client.Do(ctx, req, &trafficClones)
136 if err != nil {
137 return nil, resp, err
138 }
139
140 return trafficClones, resp, nil
141 }
142
View as plain text