diff --git a/Datanalitica.package/Tweet.class/instance/fromDictionary..st b/Datanalitica.package/Tweet.class/instance/fromDictionary..st index c9d81d2..c05388c 100644 --- a/Datanalitica.package/Tweet.class/instance/fromDictionary..st +++ b/Datanalitica.package/Tweet.class/instance/fromDictionary..st @@ -4,4 +4,6 @@ fromDictionary: aDictionary text := aDictionary at: 'text'. id := aDictionary at: 'id'. authorId := aDictionary at: 'author_id'. + username := aDictionary at: 'username' ifAbsent: [''] . + conversationId := aDictionary at: 'conversation_id' ifAbsent: [ '' ]. ^ self \ No newline at end of file diff --git a/Datanalitica.package/Tweet.class/instance/words.st b/Datanalitica.package/Tweet.class/instance/words.st index f8af065..698a2f8 100644 --- a/Datanalitica.package/Tweet.class/instance/words.st +++ b/Datanalitica.package/Tweet.class/instance/words.st @@ -1,3 +1,3 @@ utilities words - ^ self text splitOn: Character space \ No newline at end of file + ^ self text allRegexMatches: '\w*' \ No newline at end of file diff --git a/Datanalitica.package/Tweet.class/properties.json b/Datanalitica.package/Tweet.class/properties.json index 236f531..3951199 100644 --- a/Datanalitica.package/Tweet.class/properties.json +++ b/Datanalitica.package/Tweet.class/properties.json @@ -9,7 +9,9 @@ "created", "text", "id", - "authorId" + "authorId", + "conversationId", + "username" ], "name" : "Tweet", "type" : "normal" diff --git a/Datanalitica.package/TwitterAPI.class/instance/bearerKey.st b/Datanalitica.package/TwitterAPI.class/instance/bearerKey.st deleted file mode 100644 index a0da83f..0000000 --- a/Datanalitica.package/TwitterAPI.class/instance/bearerKey.st +++ /dev/null @@ -1,3 +0,0 @@ -accessing -bearerKey - self keys at: 'Bearer Token' \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/defaultQueryParameters.st b/Datanalitica.package/TwitterAPI.class/instance/defaultQueryParameters.st index 5c7ee34..fdf58a2 100644 --- a/Datanalitica.package/TwitterAPI.class/instance/defaultQueryParameters.st +++ b/Datanalitica.package/TwitterAPI.class/instance/defaultQueryParameters.st @@ -1,3 +1,7 @@ accessing defaultQueryParameters - ^ '?tweet.fields=created_at&expansions=author_id&user.fields=created_at&max_results=100' \ No newline at end of file + ^ Dictionary new + at: 'tweetsOrig' put: '?tweet.fields=created_at&expansions=author_id&user.fields=created_at&max_results=100'; + at: 'tweets' put: '?', 'tweet.fields=created_at', '&', 'expansions=author_id', '&', 'max_results=100'; + at: 'mentionsOrig' put: '?expansions=author_id&tweet.fields=conversation_id,created_at,lang&user.fields=created_at,entities&max_results=100'; + yourself \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor.since..st b/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor.since..st new file mode 100644 index 0000000..312afa0 --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor.since..st @@ -0,0 +1,18 @@ +accessing +userMentionsFor: username since: startDateString + | nextToken queryUrl sinceDate untilDate messages response | + + sinceDate := 'start_time=',startDateString, 'T00:00:00Z'. + messages := OrderedCollection new. + nextToken := ''. + [ nextToken includesSubstring: 'stop' ] whileFalse: [ + queryUrl := self usersBaseEndPoint, + (self userIDFrom: username), '/mentions', (self defaultQueryParameters at: 'mentionsOrig') , + '&', sinceDate, + '&', nextToken. + response := STONJSON fromString: (self rawResponseForURL: queryUrl). + (response at: 'data') do: [:tweetData | + messages add: (Tweet new fromDictionary: tweetData) + ]. + nextToken := 'pagination_token=',((response at: 'meta') at: 'next_token' ifAbsent: [ 'stop' ])]. +^ messages. \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor.since.until..st b/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor.since.until..st new file mode 100644 index 0000000..488502f --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor.since.until..st @@ -0,0 +1,21 @@ +accessing +userMentionsFor: username since: startDateString until: endDateString + | nextToken queryUrl sinceDate untilDate messages response extraQueryParamenters | + + sinceDate := 'start_time=',startDateString, 'T17:00:00Z'. + untilDate := 'end_time=',endDateString, 'T01:00:00Z'. + extraQueryParamenters := '?expansions=author_id&tweet.fields=conversation_id&user.fields=created_at,entities&max_results=100'. + messages := OrderedCollection new. + nextToken := ''. + [ nextToken includesSubstring: 'stop' ] whileFalse: [ + queryUrl := self usersBaseEndPoint, + (self userIDFrom: username), '/mentions', extraQueryParamenters, + '&', sinceDate, + "'&', untilDate," + '&', nextToken. + response := STONJSON fromString: (self rawResponseForURL: queryUrl). + (response at: 'data') do: [:tweetData | + messages add: (Tweet new fromDictionary: tweetData) + ]. + nextToken := 'pagination_token=',((response at: 'meta') at: 'next_token' ifAbsent: [ 'stop' ])]. +^ messages. \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/userTweetsFrom.since.until..st b/Datanalitica.package/TwitterAPI.class/instance/userTweetsFrom.since.until..st index 3699894..2d82db2 100644 --- a/Datanalitica.package/TwitterAPI.class/instance/userTweetsFrom.since.until..st +++ b/Datanalitica.package/TwitterAPI.class/instance/userTweetsFrom.since.until..st @@ -2,13 +2,13 @@ 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'. + sinceDate := 'start_time=',startDateString, 'T00:00:00Z'. + untilDate := 'end_time=',endDateString, 'T23:59:59Z'. messages := OrderedCollection new. nextToken := ''. [ nextToken includesSubstring: 'stop' ] whileFalse: [ queryUrl := self usersBaseEndPoint, - (self userIDFrom: username), '/tweets', self defaultQueryParameters, + (self userIDFrom: username), '/tweets', (self defaultQueryParameters at: 'tweets'), '&', sinceDate, '&', untilDate, '&', nextToken.