Skip to content

Commit

Permalink
Update include entities -> exclude entities
Browse files Browse the repository at this point in the history
This is done for consistency with other endpoints. The default value
of exclude entities is false, so only if it is explicitly set to true
is "include_entities" set to "false".
  • Loading branch information
ryanfowler committed Jan 4, 2017
1 parent afc18fe commit 094feb9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 57 deletions.
32 changes: 16 additions & 16 deletions favorites.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
//ListFavoritesParams represents the query parameters for a
// /favorites/list.json request
type ListFavoritesParams struct {
UserID string `json:"user_id"`
ScreenName string `json:"screen_name"`
Count int `json:"count"`
SinceID string `json:"since_id"`
MaxID string `json:"max_id"`
IncludeEntities bool `json:"include_entities"`
UserID string
ScreenName string
Count int
SinceID string
MaxID string
ExcludeEntities bool
}

// ListFavorites calls the Twitter /favorites/list.json endpoint
Expand All @@ -41,17 +41,17 @@ func listFavoritesToQuery(params ListFavoritesParams) url.Values {
if params.MaxID != "" {
values.Set("max_id", params.MaxID)
}
if params.IncludeEntities {
values.Set("include_entities", "true")
if params.ExcludeEntities {
values.Set("include_entities", "false")
}
return values
}

//CreateFavoriteParameters represents query parameters for a
// /favorites/create.json request
type CreateFavoriteParameters struct {
ID string `json:"id"`
IncludeEntities bool `json:"include_entities"`
ID string
ExcludeEntities bool
}

// CreateFavorite calls the Twitter /favorites/create.json endpoint
Expand All @@ -64,17 +64,17 @@ func (c *Client) CreateFavorite(ctx context.Context, params CreateFavoriteParame
func createFavoriteToQuery(params CreateFavoriteParameters) url.Values {
values := url.Values{}
values.Set("id", params.ID)
if params.IncludeEntities {
values.Set("include_entities", "true")
if params.ExcludeEntities {
values.Set("include_entities", "false")
}
return values
}

//DestroyFavoriteParameters represents query parameters for a
// /favorites/create.json request
type DestroyFavoriteParameters struct {
ID string `json:"id"`
IncludeEntities bool `json:"include_entities"`
ID string
ExcludeEntities bool
}

// DestroyFavorite calls the Twitter /favorites/create.json endpoint
Expand All @@ -87,8 +87,8 @@ func (c *Client) DestroyFavorite(ctx context.Context, params DestroyFavoritePara
func destroyFavoriteToQuery(params DestroyFavoriteParameters) url.Values {
values := url.Values{}
values.Set("id", params.ID)
if params.IncludeEntities {
values.Set("include_entities", "true")
if params.ExcludeEntities {
values.Set("include_entities", "false")
}
return values
}
22 changes: 10 additions & 12 deletions favorites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package twitter

import (
"context"
"net/http"

"io/ioutil"
"net/http"
"strings"

"github.com/garyburd/go-oauth/oauth"
Expand Down Expand Up @@ -77,12 +76,11 @@ var _ = Describe("Favorites", func() {
ctx := context.Background()

_, err := client.ListFavorites(ctx, ListFavoritesParams{
UserID: "sumid",
ScreenName: "sumscreenname",
Count: 3,
SinceID: "12345",
MaxID: "12346",
IncludeEntities: true,
UserID: "sumid",
ScreenName: "sumscreenname",
Count: 3,
SinceID: "12345",
MaxID: "12346",
})

Ω(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -130,7 +128,7 @@ var _ = Describe("Favorites", func() {
}

Ω(req.FormValue("id")).Should(Equal("12345"))
Ω(req.FormValue("include_entities")).Should(Equal("true"))
Ω(req.FormValue("include_entities")).Should(Equal("false"))

return r, nil
},
Expand All @@ -154,7 +152,7 @@ var _ = Describe("Favorites", func() {

_, err := client.CreateFavorite(ctx, CreateFavoriteParameters{
ID: "12345",
IncludeEntities: true,
ExcludeEntities: true,
})

Ω(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -202,7 +200,7 @@ var _ = Describe("Favorites", func() {
}

Ω(req.FormValue("id")).Should(Equal("12345"))
Ω(req.FormValue("include_entities")).Should(Equal("true"))
Ω(req.FormValue("include_entities")).Should(Equal("false"))

return r, nil
},
Expand All @@ -226,7 +224,7 @@ var _ = Describe("Favorites", func() {

_, err := client.DestroyFavorite(ctx, DestroyFavoriteParameters{
ID: "12345",
IncludeEntities: true,
ExcludeEntities: true,
})

Ω(err).ShouldNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion friendships.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func showFriendshipToQuery(params ShowFriendshipsParameters) url.Values {
return values
}

// LookupFriendsParams represents parameters for /friendships/lookup.json Twitter endpoint
// LookupFriendshipsParams represents parameters for /friendships/lookup.json Twitter endpoint
type LookupFriendshipsParams struct {
ScreenName []string
UserID []string
Expand Down
3 changes: 1 addition & 2 deletions friendships_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package twitter

import (
"context"
"io/ioutil"
"net/http"
"strings"

"io/ioutil"

"github.com/garyburd/go-oauth/oauth"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
5 changes: 1 addition & 4 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,11 @@ func mediaUploadToQuery(params MediaUploadParameters) (mediaUploadQueryResponse,
}

if len(params.Media) > 0 {
media := bytes.NewReader(params.Media)

part, err := bodyWriter.CreateFormFile("media", "")
if err != nil {
return queryResponse, err
}

_, err = io.Copy(part, media)
_, err = part.Write(params.Media)
if err != nil {
return queryResponse, err
}
Expand Down
3 changes: 1 addition & 2 deletions media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package twitter
import (
"context"
"errors"
"net/http"

"io/ioutil"
"net/http"
"strings"

"github.com/garyburd/go-oauth/oauth"
Expand Down
18 changes: 9 additions & 9 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type SearchUsersParams struct {
Q string
Page int
Count int
IncludeEntities bool
ExcludeEntities bool
}

// SearchUsers calls Twitter endpoint /users/search.json
Expand All @@ -31,8 +31,8 @@ func searchUsersToQuery(params SearchUsersParams) url.Values {
if params.Count != 0 {
values.Set("count", strconv.Itoa(params.Count))
}
if params.IncludeEntities {
values.Set("include_entities", "true")
if params.ExcludeEntities {
values.Set("include_entities", "false")
}
return values
}
Expand All @@ -41,7 +41,7 @@ func searchUsersToQuery(params SearchUsersParams) url.Values {
type ShowUserParams struct {
UserID string
ScreenName string
IncludeEntities bool
ExcludeEntities bool
}

// ShowUser calls Twitter endpoint /users/show.json
Expand All @@ -56,8 +56,8 @@ func showUserToQuery(params ShowUserParams) url.Values {

values.Set("user_id", params.UserID)
values.Set("screen_name", params.ScreenName)
if params.IncludeEntities {
values.Set("include_entities", "true")
if params.ExcludeEntities {
values.Set("include_entities", "false")
}

return values
Expand All @@ -67,7 +67,7 @@ func showUserToQuery(params ShowUserParams) url.Values {
type LookupUsersParams struct {
ScreenName []string
UserID []string
IncludeEntities bool
ExcludeEntities bool
}

// LookupUsers calls Twitter endpoint /users/lookup.json
Expand All @@ -85,8 +85,8 @@ func lookupUsersToQuery(params LookupUsersParams) url.Values {
if len(params.UserID) > 0 {
values.Set("user_id", strings.Join(params.UserID, ","))
}
if params.IncludeEntities {
values.Set("include_entities", "true")
if params.ExcludeEntities {
values.Set("include_entities", "false")
}

return values
Expand Down
20 changes: 9 additions & 11 deletions users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ = Describe("Users", func() {
Ω(req.FormValue("q")).Should(Equal("#crazy"))
Ω(req.FormValue("page")).Should(Equal("1"))
Ω(req.FormValue("count")).Should(Equal("10"))
Ω(req.FormValue("include_entities")).Should(Equal("true"))
Ω(req.FormValue("include_entities")).Should(Equal(""))

return r, nil
},
Expand All @@ -78,10 +78,9 @@ var _ = Describe("Users", func() {
ctx := context.Background()

_, err := client.SearchUsers(ctx, SearchUsersParams{
Q: "#crazy",
Page: 1,
Count: 10,
IncludeEntities: true,
Q: "#crazy",
Page: 1,
Count: 10,
})

Ω(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -130,7 +129,7 @@ var _ = Describe("Users", func() {

Ω(req.FormValue("user_id")).Should(Equal("12345"))
Ω(req.FormValue("screen_name")).Should(Equal("sumname"))
Ω(req.FormValue("include_entities")).Should(Equal("true"))
Ω(req.FormValue("include_entities")).Should(Equal("false"))

return r, nil
},
Expand All @@ -155,7 +154,7 @@ var _ = Describe("Users", func() {
_, err := client.ShowUser(ctx, ShowUserParams{
UserID: "12345",
ScreenName: "sumname",
IncludeEntities: true,
ExcludeEntities: true,
})

Ω(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -205,7 +204,7 @@ var _ = Describe("Users", func() {

Ω(req.FormValue("user_id")).Should(Equal("12345"))
Ω(req.FormValue("screen_name")).Should(Equal("sumname"))
Ω(req.FormValue("include_entities")).Should(Equal("true"))
Ω(req.FormValue("include_entities")).Should(Equal(""))

return r, nil
},
Expand All @@ -228,9 +227,8 @@ var _ = Describe("Users", func() {
ctx := context.Background()

_, err := client.LookupUsers(ctx, LookupUsersParams{
UserID: []string{"12345"},
ScreenName: []string{"sumname"},
IncludeEntities: true,
UserID: []string{"12345"},
ScreenName: []string{"sumname"},
})

Ω(err).ShouldNot(HaveOccurred())
Expand Down

0 comments on commit 094feb9

Please sign in to comment.