Adding pagination support for longer chronological queries.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2021-06-30 15:56:53 -05:00
parent 49b194ba8d
commit 99436b6ebb
3 changed files with 21 additions and 4 deletions

View File

@ -1,6 +1,6 @@
accessing accessing
userMentionsFor: username userMentionsFor: username
| rawResponse queryURL parameters | | rawResponse queryURL |
"The following query gets the last tweets, that is the maximun allowed for a particular user without pagination:" "The following query gets the last tweets, that is the maximun allowed for a particular user without pagination:"
queryURL := self usersBaseEndPoint, (self userIDFrom: username), '/mentions', self defaultQueryParameters. queryURL := self usersBaseEndPoint, (self userIDFrom: username), '/mentions', self defaultQueryParameters.
rawResponse := self rawResponseForURL:queryURL. rawResponse := self rawResponseForURL:queryURL.

View File

@ -1,8 +1,7 @@
accessing accessing
userTweetsFrom: username userTweetsFrom: username
| rawResponse queryURL parameters | | rawResponse queryURL |
"The following query gets the last 100 tweets, that is the maximun allowed for a particular user without pagination:" "The following query gets the last 100 tweets, that is the maximun allowed for a particular user without pagination:"
parameters := '?tweet.fields=created_at&expansions=author_id&user.fields=created_at&max_results=100'. queryURL := self usersBaseEndPoint, (self userIDFrom: username), '/tweets', self defaultQueryParameters.
queryURL := self usersBaseEndPoint, (self userIDFrom: username), '/tweets', parameters.
rawResponse := self rawResponseForURL:queryURL. rawResponse := self rawResponseForURL:queryURL.
^ (STONJSON fromString: rawResponse) ^ (STONJSON fromString: rawResponse)

View File

@ -0,0 +1,18 @@
accessing
userTweetsFrom: username since: startDateString until: endDateString
| nextToken queryUrl sinceDate untilDate messages response |
sinceDate := 'start_time=',startDateString, 'T17:00:00Z'.
untilDate := 'end_time=',endDateString, 'T01:00:00Z'.
messages := OrderedCollection new.
nextToken := ''.
[ nextToken includesSubstring: 'stop' ] whileFalse: [
queryUrl := self usersBaseEndPoint,
(self userIDFrom: username), '/tweets', self defaultQueryParameters,
'&', sinceDate,
'&', untilDate,
'&', nextToken.
response := STONJSON fromString: (self rawResponseForURL: queryUrl).
messages addAll: (response at: 'data').
nextToken := 'pagination_token=',((response at: 'meta') at: 'next_token' ifAbsent: [ 'stop' ])].
^ messages.