Browse Source

Add ListOptions to ListWatched

sona-tar 10 years ago
committed by Will Norris
parent
commit
c57bb02ff6
2 changed files with 15 additions and 3 deletions
  1. +6
    -1
      github/activity_watching.go
  2. +9
    -2
      github/activity_watching_test.go

+ 6
- 1
github/activity_watching.go View File

@ -50,13 +50,18 @@ func (s *ActivityService) ListWatchers(owner, repo string, opt *ListOptions) ([]
// the empty string will fetch watched repos for the authenticated user.
//
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
func (s *ActivityService) ListWatched(user string) ([]Repository, *Response, error) {
func (s *ActivityService) ListWatched(user string, opt *ListOptions) ([]Repository, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/subscriptions", user)
} else {
u = "user/subscriptions"
}
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err


+ 9
- 2
github/activity_watching_test.go View File

@ -43,10 +43,13 @@ func TestActivityService_ListWatched_authenticatedUser(t *testing.T) {
mux.HandleFunc("/user/subscriptions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"page": "2",
})
fmt.Fprint(w, `[{"id":1}]`)
})
watched, _, err := client.Activity.ListWatched("")
watched, _, err := client.Activity.ListWatched("", &ListOptions{Page: 2})
if err != nil {
t.Errorf("Activity.ListWatched returned error: %v", err)
}
@ -63,10 +66,14 @@ func TestActivityService_ListWatched_specifiedUser(t *testing.T) {
mux.HandleFunc("/users/u/subscriptions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"page": "2",
})
fmt.Fprint(w, `[{"id":1}]`)
})
watched, _, err := client.Activity.ListWatched("u")
watched, _, err := client.Activity.ListWatched("u", &ListOptions{Page: 2})
if err != nil {
t.Errorf("Activity.ListWatched returned error: %v", err)
}


Loading…
Cancel
Save