pip compatible server to serve Python packages out of GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

108 lines
2.7 KiB

// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"fmt"
"net/url"
"strconv"
"time"
)
// UsersService handles communication with the user related
// methods of the GitHub API.
//
// GitHub API docs: http://developer.github.com/v3/users/
type UsersService struct {
client *Client
}
// User represents a GitHub user.
type User struct {
Login string `json:"login,omitempty"`
ID int `json:"id,omitempty"`
URL string `json:"url,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
GravatarID string `json:"gravatar_id,omitempty"`
Name string `json:"name,omitempty"`
Company string `json:"company,omitempty"`
Blog string `json:"blog,omitempty"`
Location string `json:"location,omitempty"`
Email string `json:"email,omitempty"`
Hireable bool `json:"hireable,omitempty"`
PublicRepos int `json:"public_repos,omitempty"`
Followers int `json:"followers,omitempty"`
Following int `json:"following,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
}
// UserEmail represents user's email address
type UserEmail string
// Get fetches a user. Passing the empty string will fetch the authenticated
// user.
//
// GitHub API docs: http://developer.github.com/v3/users/#get-a-single-user
func (s *UsersService) Get(user string) (*User, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v", user)
} else {
u = "user"
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
uResp := new(User)
_, err = s.client.Do(req, uResp)
return uResp, err
}
// Edit the authenticated user.
//
// GitHub API docs: http://developer.github.com/v3/users/#update-the-authenticated-user
func (s *UsersService) Edit(user *User) (*User, error) {
u := "user"
req, err := s.client.NewRequest("PATCH", u, user)
if err != nil {
return nil, err
}
uResp := new(User)
_, err = s.client.Do(req, uResp)
return uResp, err
}
// UserListOptions specifies optional parameters to the UsersService.List
// method.
type UserListOptions struct {
// ID of the last user seen
Since int
}
// ListAll lists all GitHub users.
//
// GitHub API docs: http://developer.github.com/v3/users/#get-all-users
func (s *UsersService) ListAll(opt *UserListOptions) ([]User, error) {
u := "users"
if opt != nil {
params := url.Values{
"since": []string{strconv.Itoa(opt.Since)},
}
u += "?" + params.Encode()
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
users := new([]User)
_, err = s.client.Do(req, users)
return *users, err
}