diff --git a/twitter/rate_limit.go b/twitter/rate_limit.go index 6afe8a1..29a37a4 100644 --- a/twitter/rate_limit.go +++ b/twitter/rate_limit.go @@ -43,6 +43,7 @@ var RateLimitResource = [...]Endpoint{ {Resource: "/tweets/search/recent", Regex: `^/tweets/search/recent$`}, {Resource: "/tweets/search/all", Regex: `^/tweets/search/all$`}, {Resource: "/users/:id/tweets", Regex: `^/users/\d+/tweets$`}, + {Resource: "/users/:id/timelines/reverse_chronological", Regex: `^/users/\d+/timelines/reverse_chronological$`}, {Resource: "/users/:id/mentions", Regex: `^/users/\d+/mentions$`}, {Resource: "/tweets/:id/liking_users", Regex: `^/tweets/\d+/liking_users$`}, {Resource: "/tweets/:id/retweeted_by", Regex: `^/tweets/\d+/retweeted_by$`}, diff --git a/twitter/request_test.go b/twitter/request_test.go index 05e5f0f..6d66de1 100644 --- a/twitter/request_test.go +++ b/twitter/request_test.go @@ -26,6 +26,9 @@ func TestParseDataResponse(t *testing.T) { func TestDo(t *testing.T) { cli := NewBearerClient("") + // make tests run more quickly + cli.Cli.SetTimeout(1) + err := cli.Do("DELETE", "", "", "", "") assert.IsType(t, &APIError{}, err) diff --git a/twitter/tweet_timelines.go b/twitter/tweet_timelines.go index 39d6ecf..cc82fc6 100644 --- a/twitter/tweet_timelines.go +++ b/twitter/tweet_timelines.go @@ -25,6 +25,19 @@ func (r *TweetResource) GetTimelines(id string, args TimelinesOpts) (*TweetsResp return resp, nil } +// GetTimelinesReverseChronological Allows you to retrieve a collection of the most recent Tweets and Retweets posted by you and users you follow +// Refer: https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-reverse-chronological +func (r *TweetResource) GetTimelinesReverseChronological(id string, args TimelinesOpts) (*TweetsResp, *APIError) { + path := "/users/" + id + "/timelines/reverse_chronological" + + resp := new(TweetsResp) + err := r.Cli.DoGet(path, args, resp) + if err != nil { + return nil, err + } + return resp, nil +} + // MentionsOpts specifies the parameters for get mentions type MentionsOpts struct { MaxResults int `url:"max_results,omitempty"` diff --git a/twitter/tweet_timelines_test.go b/twitter/tweet_timelines_test.go index 35296df..ec7879a 100644 --- a/twitter/tweet_timelines_test.go +++ b/twitter/tweet_timelines_test.go @@ -29,6 +29,33 @@ func (bc BCSuite) TestGetTimelines() { bc.Equal(*resp.Data[0].PublicMetrics.LikeCount, 37) } +func (uc UCSuite) TestGetTimelinesReverseChronological() { + uid := "2244994945" + + httpmock.RegisterResponder( + HttpGet, Baseurl+"/users/"+uid+"/timelines/reverse_chronological", + httpmock.NewStringResponder( + 401, + `{"title":"Unauthorized","type":"about:blank","status":401,"detail":"Unauthorized"}`, + ), + ) + _, err := uc.Tw.Tweets.GetTimelinesReverseChronological(uid, TimelinesOpts{}) + uc.IsType(&APIError{}, err) + + httpmock.RegisterResponder( + HttpGet, Baseurl+"/users/"+uid+"/timelines/reverse_chronological", + httpmock.NewStringResponder( + 200, + `{"data":[{"created_at":"2022-05-12T17:00:00.000Z","text":"Today marks the launch of Devs in the Details, a technical video series made for developers by developers building with the Twitter API. 🚀nnIn this premiere episode, @jessicagarson walks us through how she built @FactualCat #WelcomeToOurTechTalkn⬇️nnhttps://t.co/nGa8JTQVBJ","author_id":"2244994945","id":"1524796546306478083"},{"created_at":"2022-05-11T19:16:40.000Z","text":"📢 Join @jessicagarson @alanbenlee and @i_am_daniele tomorrow, May 12 | 5:30 ET / 2:30pm PT as they discuss the future of bots https://t.co/sQ2bIO1fz6","author_id":"2244994945","id":"1524468552404668416"},{"created_at":"2022-05-09T20:12:01.000Z","text":"Do you make bots with the Twitter API? 🤖nnJoin @jessicagarson @alanbenlee and @iamdaniele on Thursday, May 12 | 5:30 ET / 2:30pm PT as they discuss the future of bots and answer any questions you might have. 🎙📆⬇️nnhttps://t.co/2uVt7hCcdG","author_id":"2244994945","id":"1523757705436958720"},{"created_at":"2022-05-06T18:19:54.000Z","text":"If you’d like to apply, or would like to nominate someone else for the program, please feel free to fill out the following form:nnhttps://t.co/LUuWj24HLu","author_id":"2244994945","id":"1522642324781633536"},{"created_at":"2022-05-06T18:19:53.000Z","text":"We’ve gone into more detail on each Insider in our forum post. nnJoin us in congratulating the new additions! 🥳nnhttps://t.co/0r5maYEjPJ","author_id":"2244994945","id":"1522642323535847424"}],"includes":{"users":[{"created_at":"2013-12-14T04:35:55.000Z","name":"Twitter Dev","username":"TwitterDev","id":"2244994945"}]},"meta":{"result_count":5,"newest_id":"1524796546306478083","oldest_id":"1522642323535847424","next_token":"7140dibdnow9c7btw421dyz6jism75z99gyxd8egarsc4"}}`, + ), + ) + + resp, _ := uc.Tw.Tweets.GetTimelinesReverseChronological(uid, TimelinesOpts{}) + uc.Equal(len(resp.Data), 5) + uc.Equal(*resp.Data[0].ID, "1524796546306478083") + uc.Equal(*resp.Meta.NewestID, "1524796546306478083") +} + func (bc BCSuite) TestGetMentions() { uid := "2244994945"