Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
fix initial array assignment in ids()
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevoo committed May 16, 2020
1 parent 9395793 commit b44055c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion twitter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type APIErrors struct {
Errors []APIError `json:"errors"`
}

// RoundTrip intercepts API responses and checks if throttling pauses is required
// RoundTrip intercepts API responses and checks if a throttling pause is required
func (t *NucollTransport) RoundTrip(req *http.Request) (res *http.Response, err error) {
if t.Config.AccessToken != "" {
req.Header.Add("Authorization", "Bearer "+t.Config.AccessToken)
Expand Down
11 changes: 9 additions & 2 deletions twitter/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ func (ns Twitter) ids(relation string, param string) ([]string, error) {
}
defer res.Body.Close()
json.NewDecoder(res.Body).Decode(&result)
ids = result.IDs
ids = append(ids, result.IDs...)
cursor := result.NextCursor
for cursor != 0 {
res, err = ns.Client.Get(fmt.Sprintf(endpoint+"&cursor=%d", relation, arg, cursor))
if err != nil {
return nil, err
}
defer res.Body.Close()
json.NewDecoder(res.Body).Decode(&result)
ids = append(ids, result.IDs...)
cursor = result.NextCursor
Expand All @@ -105,6 +106,7 @@ func (ns Twitter) ids(relation string, param string) ([]string, error) {
// members returns an array of hydrated nucoll user objects belonging to a list
func (ns Twitter) members(list string, param string) ([]UserObject, error) {
var result MembersResult
var users []UserObject
const endpoint = "https://api.twitter.com/1.1/lists/members.json?slug=%s&owner_screen_name=%s&count=5000&skip_status=true"

res, err := ns.Client.Get(fmt.Sprintf(endpoint, list, param))
Expand All @@ -117,13 +119,14 @@ func (ns Twitter) members(list string, param string) ([]UserObject, error) {
result.Users[i].Relation = list
result.Users[i].Subject = param
}
users := result.Users
users = append(users, result.Users...)
cursor := result.NextCursor
for cursor != 0 {
res, err = ns.Client.Get(fmt.Sprintf(endpoint+"&cursor=%d", list, param, cursor))
if err != nil {
return nil, err
}
defer res.Body.Close()
json.NewDecoder(res.Body).Decode(&result)
for i := range result.Users {
result.Users[i].Relation = list
Expand All @@ -149,6 +152,7 @@ func (ns Twitter) show(handle string) (UserObject, error) {
if err != nil {
return result, err
}
defer res.Body.Close()
json.NewDecoder(res.Body).Decode(&result)

return result, nil
Expand All @@ -175,6 +179,7 @@ func (ns Twitter) retweetersOf(handle string, maxCount int) ([]string, error) {
if err != nil {
return nil, err
}
defer res.Body.Close()
json.NewDecoder(res.Body).Decode(&result.Statuses)
if len(result.Statuses) == 0 {
break
Expand Down Expand Up @@ -267,6 +272,7 @@ func (ns Twitter) Init(followersFlag bool, maxPostCount int, queryFlag bool, nom
if err != nil {
log.Fatal("failed to use Twitter client: ", err)
}
defer res.Body.Close()
json.NewDecoder(res.Body).Decode(&result)
for i := range result {
if maxPostCount > 0 {
Expand Down Expand Up @@ -409,6 +415,7 @@ func (ns Twitter) Posts(queryFlag bool, list string, postID uint64, args []strin
if err != nil {
log.Fatal("failed to use Twitter client: ", err)
}
defer res.Body.Close()
if queryFlag || postID != 0 {
json.NewDecoder(res.Body).Decode(&result)
} else {
Expand Down

0 comments on commit b44055c

Please sign in to comment.