Adding pagination support for longer chronological queries.
This commit is contained in:
parent
49b194ba8d
commit
99436b6ebb
@ -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.
|
||||||
|
@ -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)
|
@ -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.
|
Loading…
Reference in New Issue
Block a user