Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement /lists/members.json with pagination resolving #221

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions list.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package anaconda

type NextPrevCursor struct {
PreviousCursor int `json:"previous_cursor"`
NextCursor int `json:"next_cursor"`
}

type ListResponse struct {
PreviousCursor int `json:"previous_cursor"`
NextCursor int `json:"next_cursor"`
Lists []List `json:"lists"`
NextPrevCursor
Lists []List `json:"lists"`
}

type ListMembershipResponse struct {
NextPrevCursor
Users []User `json:"users"`
}

type AddUserToListResponse struct {
Expand Down
28 changes: 28 additions & 0 deletions lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ func (a TwitterApi) AddMultipleUsersToList(screenNames []string, listID int64, v
return list, r.err
}

func (a TwitterApi) GetListMembers(listID int64, v url.Values) ([]User, error) {
v = cleanValues(v)
v.Set("list_id", strconv.FormatInt(listID, 10))
v.Set("cursor", "-1")

var all []User
var lmResp ListMembershipResponse
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/members.json", v, &lmResp, _GET, response_ch}
if err := (<-response_ch).err; err != nil {
return nil, err
}
all = lmResp.Users
for lmResp.NextCursor != 0 {
//log.Printf("additonal list(%d) members req. %d %d.", listID, lmResp.NextCursor, len(all))

v.Set("cursor", strconv.FormatInt(int64(lmResp.NextCursor), 10))

response_ch = make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/members.json", v, &lmResp, _GET, response_ch}
if err := (<-response_ch).err; err != nil {
return nil, err
}
all = append(all, lmResp.Users...)
}
return all, nil
}

// GetListsOwnedBy implements /lists/ownerships.json
// screen_name, count, and cursor are all optional values
func (a TwitterApi) GetListsOwnedBy(userID int64, v url.Values) (lists []List, err error) {
Expand Down