Skip to content

Commit ba3668f

Browse files
muesliChimeraCoder
authored andcommitted
Use cleanValues more consistently (#204)
1 parent 2d44918 commit ba3668f

File tree

7 files changed

+10
-44
lines changed

7 files changed

+10
-44
lines changed

Diff for: account.go

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ func (a TwitterApi) VerifyCredentials() (ok bool, err error) {
1616

1717
// Get the user object for the authenticated user. Requests /account/verify_credentials
1818
func (a TwitterApi) GetSelf(v url.Values) (u User, err error) {
19-
v = cleanValues(v)
2019
response_ch := make(chan response)
2120
a.queryQueue <- query{a.baseUrl + "/account/verify_credentials.json", v, &u, _GET, response_ch}
2221
return u, (<-response_ch).err

Diff for: friends_followers.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ func (a TwitterApi) GetFollowersIds(v url.Values) (c Cursor, err error) {
7777
// Like GetFollowersIds, but returns a channel instead of a cursor and pre-fetches the remaining results
7878
// This channel is closed once all values have been fetched
7979
func (a TwitterApi) GetFollowersIdsAll(v url.Values) (result chan FollowersIdsPage) {
80-
8180
result = make(chan FollowersIdsPage)
8281

83-
if v == nil {
84-
v = url.Values{}
85-
}
82+
v = cleanValues(v)
8683
go func(a TwitterApi, v url.Values, result chan FollowersIdsPage) {
8784
// Cursor defaults to the first page ("-1")
8885
next_cursor := "-1"
@@ -144,12 +141,9 @@ func (a TwitterApi) GetFriendsList(v url.Values) (c UserCursor, err error) {
144141
// Like GetFriendsList, but returns a channel instead of a cursor and pre-fetches the remaining results
145142
// This channel is closed once all values have been fetched
146143
func (a TwitterApi) GetFriendsListAll(v url.Values) (result chan FriendsPage) {
147-
148144
result = make(chan FriendsPage)
149145

150-
if v == nil {
151-
v = url.Values{}
152-
}
146+
v = cleanValues(v)
153147
go func(a TwitterApi, v url.Values, result chan FriendsPage) {
154148
// Cursor defaults to the first page ("-1")
155149
next_cursor := "-1"
@@ -175,12 +169,9 @@ func (a TwitterApi) GetFriendsListAll(v url.Values) (result chan FriendsPage) {
175169
// Like GetFollowersList, but returns a channel instead of a cursor and pre-fetches the remaining results
176170
// This channel is closed once all values have been fetched
177171
func (a TwitterApi) GetFollowersListAll(v url.Values) (result chan FollowersPage) {
178-
179172
result = make(chan FollowersPage)
180173

181-
if v == nil {
182-
v = url.Values{}
183-
}
174+
v = cleanValues(v)
184175
go func(a TwitterApi, v url.Values, result chan FollowersPage) {
185176
// Cursor defaults to the first page ("-1")
186177
next_cursor := "-1"
@@ -214,12 +205,9 @@ func (a TwitterApi) GetFollowersUser(id int64, v url.Values) (c Cursor, err erro
214205
// Like GetFriendsIds, but returns a channel instead of a cursor and pre-fetches the remaining results
215206
// This channel is closed once all values have been fetched
216207
func (a TwitterApi) GetFriendsIdsAll(v url.Values) (result chan FriendsIdsPage) {
217-
218208
result = make(chan FriendsIdsPage)
219209

220-
if v == nil {
221-
v = url.Values{}
222-
}
210+
v = cleanValues(v)
223211
go func(a TwitterApi, v url.Values, result chan FriendsIdsPage) {
224212
// Cursor defaults to the first page ("-1")
225213
next_cursor := "-1"

Diff for: lists.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import (
77

88
// CreateList implements /lists/create.json
99
func (a TwitterApi) CreateList(name, description string, v url.Values) (list List, err error) {
10-
if v == nil {
11-
v = url.Values{}
12-
}
10+
v = cleanValues(v)
1311
v.Set("name", name)
1412
v.Set("description", description)
1513

@@ -20,9 +18,7 @@ func (a TwitterApi) CreateList(name, description string, v url.Values) (list Lis
2018

2119
// AddUserToList implements /lists/members/create.json
2220
func (a TwitterApi) AddUserToList(screenName string, listID int64, v url.Values) (users []User, err error) {
23-
if v == nil {
24-
v = url.Values{}
25-
}
21+
v = cleanValues(v)
2622
v.Set("list_id", strconv.FormatInt(listID, 10))
2723
v.Set("screen_name", screenName)
2824

@@ -36,9 +32,7 @@ func (a TwitterApi) AddUserToList(screenName string, listID int64, v url.Values)
3632
// GetListsOwnedBy implements /lists/ownerships.json
3733
// screen_name, count, and cursor are all optional values
3834
func (a TwitterApi) GetListsOwnedBy(userID int64, v url.Values) (lists []List, err error) {
39-
if v == nil {
40-
v = url.Values{}
41-
}
35+
v = cleanValues(v)
4236
v.Set("user_id", strconv.FormatInt(userID, 10))
4337

4438
var listResponse ListResponse
@@ -49,9 +43,7 @@ func (a TwitterApi) GetListsOwnedBy(userID int64, v url.Values) (lists []List, e
4943
}
5044

5145
func (a TwitterApi) GetListTweets(listID int64, includeRTs bool, v url.Values) (tweets []Tweet, err error) {
52-
if v == nil {
53-
v = url.Values{}
54-
}
46+
v = cleanValues(v)
5547
v.Set("list_id", strconv.FormatInt(listID, 10))
5648
v.Set("include_rts", strconv.FormatBool(includeRTs))
5749

Diff for: oembed.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ func (a TwitterApi) GetOEmbed(v url.Values) (o OEmbed, err error) {
3434

3535
// Calls GetOEmbed with the corresponding id. Convenience wrapper for GetOEmbed()
3636
func (a TwitterApi) GetOEmbedId(id int64, v url.Values) (o OEmbed, err error) {
37-
if v == nil {
38-
v = url.Values{}
39-
}
37+
v = cleanValues(v)
4038
v.Set("id", strconv.FormatInt(id, 10))
4139
resp, err := http.Get(a.baseUrlV1() + "/statuses/oembed.json?" + v.Encode())
4240
if err != nil {

Diff for: timeline.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import (
99
// https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
1010
// By default, include_entities is set to "true"
1111
func (a TwitterApi) GetHomeTimeline(v url.Values) (timeline []Tweet, err error) {
12-
if v == nil {
13-
v = url.Values{}
14-
}
15-
12+
v = cleanValues(v)
1613
if val := v.Get("include_entities"); val == "" {
1714
v.Set("include_entities", "true")
1815
}

Diff for: trends.go

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func (a TwitterApi) GetTrendsByPlace(id int64, v url.Values) (trendResp TrendRes
4949
// https://dev.twitter.com/rest/reference/get/trends/available
5050
func (a TwitterApi) GetTrendsAvailableLocations(v url.Values) (locations []TrendLocation, err error) {
5151
response_ch := make(chan response)
52-
v = cleanValues(v)
5352
a.queryQueue <- query{a.baseUrl + "/trends/available.json", v, &locations, _GET, response_ch}
5453
return locations, (<-response_ch).err
5554
}

Diff for: webhook.go

-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
//only one webhook URL can be registered to an application.
1010
//https://dev.twitter.com/webhooks/reference/get/account_activity/webhooks
1111
func (a TwitterApi) GetActivityWebhooks(v url.Values) (u []WebHookResp, err error) {
12-
v = cleanValues(v)
1312
responseCh := make(chan response)
1413
a.queryQueue <- query{a.baseUrl + "/account_activity/webhooks.json", v, &u, _GET, responseCh}
1514
return u, (<-responseCh).err
@@ -30,7 +29,6 @@ type WebHookResp struct {
3029
//Only one webhook URL can be registered to an application.
3130
//https://api.twitter.com/1.1/account_activity/webhooks.json
3231
func (a TwitterApi) SetActivityWebhooks(v url.Values) (u []WebHookResp, err error) {
33-
v = cleanValues(v)
3432
responseCh := make(chan response)
3533
a.queryQueue <- query{a.baseUrl + "/account_activity/webhooks.json", v, &u, _POST, responseCh}
3634
return u, (<-responseCh).err
@@ -39,7 +37,6 @@ func (a TwitterApi) SetActivityWebhooks(v url.Values) (u []WebHookResp, err erro
3937
//DeleteActivityWebhooks Removes the webhook from the provided application’s configuration.
4038
//https://dev.twitter.com/webhooks/reference/del/account_activity/webhooks
4139
func (a TwitterApi) DeleteActivityWebhooks(v url.Values, webhookID string) (u interface{}, err error) {
42-
v = cleanValues(v)
4340
responseCh := make(chan response)
4441
a.queryQueue <- query{a.baseUrl + "/account_activity/webhooks/" + webhookID + ".json", v, &u, _DELETE, responseCh}
4542
return u, (<-responseCh).err
@@ -48,7 +45,6 @@ func (a TwitterApi) DeleteActivityWebhooks(v url.Values, webhookID string) (u in
4845
//PutActivityWebhooks update webhook which reenables the webhook by setting its status to valid.
4946
//https://dev.twitter.com/webhooks/reference/put/account_activity/webhooks
5047
func (a TwitterApi) PutActivityWebhooks(v url.Values, webhookID string) (u interface{}, err error) {
51-
v = cleanValues(v)
5248
responseCh := make(chan response)
5349
a.queryQueue <- query{a.baseUrl + "/account_activity/webhooks/" + webhookID + ".json", v, &u, _PUT, responseCh}
5450
return u, (<-responseCh).err
@@ -58,7 +54,6 @@ func (a TwitterApi) PutActivityWebhooks(v url.Values, webhookID string) (u inter
5854
//When subscribed, all DM events for the provided user will be sent to the app’s webhook via POST request.
5955
//https://dev.twitter.com/webhooks/reference/post/account_activity/webhooks/subscriptions
6056
func (a TwitterApi) SetWHSubscription(v url.Values, webhookID string) (u interface{}, err error) {
61-
v = cleanValues(v)
6257
responseCh := make(chan response)
6358
a.queryQueue <- query{a.baseUrl + "/account_activity/webhooks/" + webhookID + "/subscriptions.json", v, &u, _POST, responseCh}
6459
return u, (<-responseCh).err
@@ -68,7 +63,6 @@ func (a TwitterApi) SetWHSubscription(v url.Values, webhookID string) (u interfa
6863
//subscribed to the provided user’s Direct Messages.
6964
//https://dev.twitter.com/webhooks/reference/get/account_activity/webhooks/subscriptions
7065
func (a TwitterApi) GetWHSubscription(v url.Values, webhookID string) (u interface{}, err error) {
71-
v = cleanValues(v)
7266
responseCh := make(chan response)
7367
a.queryQueue <- query{a.baseUrl + "/account_activity/webhooks/" + webhookID + "/subscriptions.json", v, &u, _GET, responseCh}
7468
return u, (<-responseCh).err
@@ -78,7 +72,6 @@ func (a TwitterApi) GetWHSubscription(v url.Values, webhookID string) (u interfa
7872
//all DM events for the requesting user will no longer be sent to the webhook URL..
7973
//https://dev.twitter.com/webhooks/reference/del/account_activity/webhooks
8074
func (a TwitterApi) DeleteWHSubscription(v url.Values, webhookID string) (u interface{}, err error) {
81-
v = cleanValues(v)
8275
responseCh := make(chan response)
8376
a.queryQueue <- query{a.baseUrl + "/account_activity/webhooks/" + webhookID + "/subscriptions.json", v, &u, _DELETE, responseCh}
8477
return u, (<-responseCh).err

0 commit comments

Comments
 (0)