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

Added retweeters ids method #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions tweets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"strconv"
)

type RetweetersIdsPage struct {
Ids []int64
Error error
}

func (a TwitterApi) GetTweet(id int64, v url.Values) (tweet Tweet, err error) {
v = cleanValues(v)
v.Set("id", strconv.FormatInt(id, 10))
Expand Down Expand Up @@ -36,6 +41,40 @@ func (a TwitterApi) GetRetweets(id int64, v url.Values) (tweets []Tweet, err err
return tweets, (<-response_ch).err
}

// Like GetRetweetersIdsList, but returns a channel instead of a cursor and pre-fetches the remaining results
// This channel is closed once all values have been fetched
func (a TwitterApi) GetRetweetersIdsListAll(v url.Values) (result chan RetweetersIdsPage) {
result = make(chan RetweetersIdsPage)

v = cleanValues(v)
go func(a TwitterApi, v url.Values, result chan RetweetersIdsPage) {
// Cursor defaults to the first page ("-1")
next_cursor := "-1"
for {
v.Set("cursor", next_cursor)
c, err := a.GetRetweetersIdsList(v)

// throttledQuery() handles all rate-limiting errors
// if GetFollowersList() returns an error, it must be a different kind of error

result <- RetweetersIdsPage{c.Ids, err}

next_cursor = c.Next_cursor_str
if err != nil || next_cursor == "0" {
close(result)
break
}
}
}(a, v, result)
return result
}

func (a TwitterApi) GetRetweetersIdsList(v url.Values) (c Cursor, err error) {
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/statuses/retweeters/ids.json", v, &c, _GET, response_ch}
return c, (<-response_ch).err
}

//PostTweet will create a tweet with the specified status message
func (a TwitterApi) PostTweet(status string, v url.Values) (tweet Tweet, err error) {
v = cleanValues(v)
Expand Down