Initial API exploration with default max outputs (100 messages by query), before implementing pagination.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2021-06-30 10:05:55 -05:00
parent 9401982be6
commit 49b194ba8d
20 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,5 @@
{
"separateMethodMetaAndSource" : false,
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}

View File

@ -0,0 +1,3 @@
accessing
keys
^ keys ifNil: [ keys := Dictionary new]

View File

@ -0,0 +1,4 @@
accessing
loadKeys
keys := STONJSON fromString: FileLocator home / '.config/Datanalitica/twitter-api-keys.json' contents.
^ self keys

View File

@ -0,0 +1,3 @@
accessing
bearerKey
self keys at: 'Bearer Token'

View File

@ -0,0 +1,3 @@
accessing
bearerToken
^ self keys at: 'Bearer Token'

View File

@ -0,0 +1,3 @@
accessing
defaultQueryParameters
^ '?tweet.fields=created_at&expansions=author_id&user.fields=created_at&max_results=100'

View File

@ -0,0 +1,3 @@
accessing
keys
^ keys ifNil: [ keys := Dictionary new]

View File

@ -0,0 +1,4 @@
accessing
loadKeys
keys := self class loadKeys.
^ keys

View File

@ -0,0 +1,6 @@
accessing
rawResponseForURL: anUrl
^ ZnClient new
headerAt: 'Authorization' put: 'Bearer ', self bearerToken;
url: anUrl;
get.

View File

@ -0,0 +1,5 @@
queries
userIDFrom: username
| rawResponse |
rawResponse := self rawResponseForURL: self usersBaseEndPoint, 'by/username/', username.
^ (STONJSON fromString: rawResponse) at: 'data' at: 'id'

View File

@ -0,0 +1,7 @@
accessing
userMentionsFor: username
| rawResponse queryURL parameters |
"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.
rawResponse := self rawResponseForURL:queryURL.
^ (STONJSON fromString: rawResponse)

View File

@ -0,0 +1,8 @@
accessing
userTweetsFor: username
| rawResponse queryURL parameters |
"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', parameters.
rawResponse := self rawResponseForURL:queryURL.
^ (STONJSON fromString: rawResponse)

View File

@ -0,0 +1,8 @@
accessing
userTweetsFrom: username
| rawResponse queryURL parameters |
"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', parameters.
rawResponse := self rawResponseForURL:queryURL.
^ (STONJSON fromString: rawResponse)

View File

@ -0,0 +1,3 @@
utilities api
usersBaseEndPoint
^ 'https://api.twitter.com/2/users/'

View File

@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "Object",
"category" : "Datanalitica",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [
"keys"
],
"instvars" : [ ],
"name" : "TwitterAPI",
"type" : "normal"
}

View File

@ -0,0 +1 @@
SystemOrganization addCategory: #Datanalitica!

View File

@ -0,0 +1 @@
(name 'Datanalitica')

View File

@ -0,0 +1 @@
{ }