59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package anilist
|
|
|
|
func (api *Api) GetUserByName(name string) (*User, error) {
|
|
query := `query ($name: String) {
|
|
User (name: $name) ` + subSelectionUser + `
|
|
}`
|
|
|
|
vars := map[string]interface{}{
|
|
"name": name,
|
|
}
|
|
|
|
resp := responseObj[struct {
|
|
User *User
|
|
}]{}
|
|
|
|
err := request(api, query, vars, &resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp.Data.User, nil
|
|
}
|
|
|
|
func (api *Api) GetUserByID(id int) (*User, error) {
|
|
query := `query ($id: Int) {
|
|
User (id: $id) ` + subSelectionUser + `
|
|
}`
|
|
|
|
vars := map[string]interface{}{
|
|
"id": id,
|
|
}
|
|
|
|
resp := responseObj[struct {
|
|
User *User
|
|
}]{}
|
|
|
|
err := request(api, query, vars, &resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp.Data.User, nil
|
|
}
|
|
|
|
func (api *Api) SearchUsers(search string, onError func(error)) <-chan *User {
|
|
vars := map[string]interface{}{"search": search}
|
|
resp := responseObj[*page[User]]{}
|
|
return requestPaged(api, searchUsersQuery, vars, &resp, onError)
|
|
}
|
|
|
|
const (
|
|
searchUsersQuery = `query ($search: String, $page: Int) {
|
|
Page (page: $page) {
|
|
pageInfo ` + subSelectionPageInfo + `
|
|
users (search: $search) ` + subSelectionUser + `
|
|
}
|
|
}`
|
|
)
|