@@ -8,8 +8,6 @@ package github
88import (
99 "encoding/json"
1010 "fmt"
11- "net/url"
12- "strconv"
1311 "time"
1412)
1513
@@ -74,12 +72,9 @@ func (p PushEventCommit) String() string {
7472//
7573// GitHub API docs: http://developer.github.com/v3/activity/events/#list-public-events
7674func (s * ActivityService ) ListEvents (opt * ListOptions ) ([]Event , * Response , error ) {
77- u := "events"
78- if opt != nil {
79- params := url.Values {
80- "page" : []string {strconv .Itoa (opt .Page )},
81- }
82- u += "?" + params .Encode ()
75+ u , err := addOptions ("events" , opt )
76+ if err != nil {
77+ return nil , nil , err
8378 }
8479
8580 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -101,11 +96,9 @@ func (s *ActivityService) ListEvents(opt *ListOptions) ([]Event, *Response, erro
10196// GitHub API docs: http://developer.github.com/v3/activity/events/#list-repository-events
10297func (s * ActivityService ) ListRepositoryEvents (owner , repo string , opt * ListOptions ) ([]Event , * Response , error ) {
10398 u := fmt .Sprintf ("repos/%v/%v/events" , owner , repo )
104- if opt != nil {
105- params := url.Values {
106- "page" : []string {strconv .Itoa (opt .Page )},
107- }
108- u += "?" + params .Encode ()
99+ u , err := addOptions (u , opt )
100+ if err != nil {
101+ return nil , nil , err
109102 }
110103
111104 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -127,11 +120,9 @@ func (s *ActivityService) ListRepositoryEvents(owner, repo string, opt *ListOpti
127120// GitHub API docs: http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
128121func (s * ActivityService ) ListIssueEventsForRepository (owner , repo string , opt * ListOptions ) ([]Event , * Response , error ) {
129122 u := fmt .Sprintf ("repos/%v/%v/issues/events" , owner , repo )
130- if opt != nil {
131- params := url.Values {
132- "page" : []string {strconv .Itoa (opt .Page )},
133- }
134- u += "?" + params .Encode ()
123+ u , err := addOptions (u , opt )
124+ if err != nil {
125+ return nil , nil , err
135126 }
136127
137128 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -153,11 +144,9 @@ func (s *ActivityService) ListIssueEventsForRepository(owner, repo string, opt *
153144// GitHub API docs: http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories
154145func (s * ActivityService ) ListEventsForRepoNetwork (owner , repo string , opt * ListOptions ) ([]Event , * Response , error ) {
155146 u := fmt .Sprintf ("networks/%v/%v/events" , owner , repo )
156- if opt != nil {
157- params := url.Values {
158- "page" : []string {strconv .Itoa (opt .Page )},
159- }
160- u += "?" + params .Encode ()
147+ u , err := addOptions (u , opt )
148+ if err != nil {
149+ return nil , nil , err
161150 }
162151
163152 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -179,11 +168,9 @@ func (s *ActivityService) ListEventsForRepoNetwork(owner, repo string, opt *List
179168// GitHub API docs: http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization
180169func (s * ActivityService ) ListEventsForOrganization (org string , opt * ListOptions ) ([]Event , * Response , error ) {
181170 u := fmt .Sprintf ("orgs/%v/events" , org )
182- if opt != nil {
183- params := url.Values {
184- "page" : []string {strconv .Itoa (opt .Page )},
185- }
186- u += "?" + params .Encode ()
171+ u , err := addOptions (u , opt )
172+ if err != nil {
173+ return nil , nil , err
187174 }
188175
189176 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -211,12 +198,9 @@ func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool
211198 } else {
212199 u = fmt .Sprintf ("users/%v/events" , user )
213200 }
214-
215- if opt != nil {
216- params := url.Values {
217- "page" : []string {strconv .Itoa (opt .Page )},
218- }
219- u += "?" + params .Encode ()
201+ u , err := addOptions (u , opt )
202+ if err != nil {
203+ return nil , nil , err
220204 }
221205
222206 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -244,12 +228,9 @@ func (s *ActivityService) ListEventsRecievedByUser(user string, publicOnly bool,
244228 } else {
245229 u = fmt .Sprintf ("users/%v/received_events" , user )
246230 }
247-
248- if opt != nil {
249- params := url.Values {
250- "page" : []string {strconv .Itoa (opt .Page )},
251- }
252- u += "?" + params .Encode ()
231+ u , err := addOptions (u , opt )
232+ if err != nil {
233+ return nil , nil , err
253234 }
254235
255236 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -272,12 +253,11 @@ func (s *ActivityService) ListEventsRecievedByUser(user string, publicOnly bool,
272253// GitHub API docs: http://developer.github.com/v3/activity/events/#list-events-for-an-organization
273254func (s * ActivityService ) ListUserEventsForOrganization (org , user string , opt * ListOptions ) ([]Event , * Response , error ) {
274255 u := fmt .Sprintf ("users/%v/events/orgs/%v" , user , org )
275- if opt != nil {
276- params := url.Values {
277- "page" : []string {strconv .Itoa (opt .Page )},
278- }
279- u += "?" + params .Encode ()
256+ u , err := addOptions (u , opt )
257+ if err != nil {
258+ return nil , nil , err
280259 }
260+
281261 req , err := s .client .NewRequest ("GET" , u , nil )
282262 if err != nil {
283263 return nil , nil , err
0 commit comments