Browse Source

Add UsersService.GetByID method.

Note: GetByID uses the undocumented GitHub API endpoint /user/:id.

Resolves #329 (assuming #332 is also merged).
Closes #333
Quinn Slack 12 years ago
committed by Will Norris
parent
commit
1acbd99794
2 changed files with 39 additions and 0 deletions
  1. +19
    -0
      github/users.go
  2. +20
    -0
      github/users_test.go

+ 19
- 0
github/users.go View File

@ -95,6 +95,25 @@ func (s *UsersService) Get(user string) (*User, *Response, error) {
return uResp, resp, err
}
// GetByID fetches a user.
//
// Note: GetByID uses the undocumented GitHub API endpoint /user/:id.
func (s *UsersService) GetByID(id int) (*User, *Response, error) {
u := fmt.Sprintf("user/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
user := new(User)
resp, err := s.client.Do(req, user)
if err != nil {
return nil, resp, err
}
return user, resp, err
}
// Edit the authenticated user.
//
// GitHub API docs: http://developer.github.com/v3/users/#update-the-authenticated-user


+ 20
- 0
github/users_test.go View File

@ -100,6 +100,26 @@ func TestUsersService_Get_invalidUser(t *testing.T) {
testURLParseError(t, err)
}
func TestUsersService_GetByID(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/user/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
user, _, err := client.Users.GetByID(1)
if err != nil {
t.Errorf("Users.GetByID returned error: %v", err)
}
want := &User{ID: Int(1)}
if !reflect.DeepEqual(user, want) {
t.Errorf("Users.GetByID returned %+v, want %+v", user, want)
}
}
func TestUsersService_Edit(t *testing.T) {
setup()
defer teardown()


Loading…
Cancel
Save