From 49b194ba8d333e2ce8ad8cf787d33adb467c7bab Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Wed, 30 Jun 2021 10:05:55 -0500 Subject: [PATCH] Initial API exploration with default max outputs (100 messages by query), before implementing pagination. --- Datanalitica.package/.filetree | 5 +++++ Datanalitica.package/TwitterAPI.class/README.md | 0 Datanalitica.package/TwitterAPI.class/class/keys.st | 3 +++ .../TwitterAPI.class/class/loadKeys.st | 4 ++++ .../TwitterAPI.class/instance/bearerKey.st | 3 +++ .../TwitterAPI.class/instance/bearerToken.st | 3 +++ .../instance/defaultQueryParameters.st | 3 +++ .../TwitterAPI.class/instance/keys.st | 3 +++ .../TwitterAPI.class/instance/loadKeys.st | 4 ++++ .../TwitterAPI.class/instance/rawResponseForURL..st | 6 ++++++ .../TwitterAPI.class/instance/userIDFrom..st | 5 +++++ .../TwitterAPI.class/instance/userMentionsFor..st | 7 +++++++ .../TwitterAPI.class/instance/userTweetsFor..st | 8 ++++++++ .../TwitterAPI.class/instance/userTweetsFrom..st | 8 ++++++++ .../TwitterAPI.class/instance/usersBaseEndPoint.st | 3 +++ .../TwitterAPI.class/properties.json | 13 +++++++++++++ Datanalitica.package/monticello.meta/categories.st | 1 + .../monticello.meta/initializers.st | 0 Datanalitica.package/monticello.meta/package | 1 + Datanalitica.package/properties.json | 1 + 20 files changed, 81 insertions(+) create mode 100644 Datanalitica.package/.filetree create mode 100644 Datanalitica.package/TwitterAPI.class/README.md create mode 100644 Datanalitica.package/TwitterAPI.class/class/keys.st create mode 100644 Datanalitica.package/TwitterAPI.class/class/loadKeys.st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/bearerKey.st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/bearerToken.st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/defaultQueryParameters.st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/keys.st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/loadKeys.st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/rawResponseForURL..st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/userIDFrom..st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/userMentionsFor..st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/userTweetsFor..st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/userTweetsFrom..st create mode 100644 Datanalitica.package/TwitterAPI.class/instance/usersBaseEndPoint.st create mode 100644 Datanalitica.package/TwitterAPI.class/properties.json create mode 100644 Datanalitica.package/monticello.meta/categories.st create mode 100644 Datanalitica.package/monticello.meta/initializers.st create mode 100644 Datanalitica.package/monticello.meta/package create mode 100644 Datanalitica.package/properties.json diff --git a/Datanalitica.package/.filetree b/Datanalitica.package/.filetree new file mode 100644 index 0000000..57a6797 --- /dev/null +++ b/Datanalitica.package/.filetree @@ -0,0 +1,5 @@ +{ + "separateMethodMetaAndSource" : false, + "noMethodMetaData" : true, + "useCypressPropertiesFile" : true +} \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/README.md b/Datanalitica.package/TwitterAPI.class/README.md new file mode 100644 index 0000000..e69de29 diff --git a/Datanalitica.package/TwitterAPI.class/class/keys.st b/Datanalitica.package/TwitterAPI.class/class/keys.st new file mode 100644 index 0000000..03ed198 --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/class/keys.st @@ -0,0 +1,3 @@ +accessing +keys + ^ keys ifNil: [ keys := Dictionary new] \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/class/loadKeys.st b/Datanalitica.package/TwitterAPI.class/class/loadKeys.st new file mode 100644 index 0000000..63657c6 --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/class/loadKeys.st @@ -0,0 +1,4 @@ +accessing +loadKeys + keys := STONJSON fromString: FileLocator home / '.config/Datanalitica/twitter-api-keys.json' contents. + ^ self keys \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/bearerKey.st b/Datanalitica.package/TwitterAPI.class/instance/bearerKey.st new file mode 100644 index 0000000..a0da83f --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/bearerKey.st @@ -0,0 +1,3 @@ +accessing +bearerKey + self keys at: 'Bearer Token' \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/bearerToken.st b/Datanalitica.package/TwitterAPI.class/instance/bearerToken.st new file mode 100644 index 0000000..6c8427f --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/bearerToken.st @@ -0,0 +1,3 @@ +accessing +bearerToken + ^ 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 new file mode 100644 index 0000000..5c7ee34 --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/defaultQueryParameters.st @@ -0,0 +1,3 @@ +accessing +defaultQueryParameters + ^ '?tweet.fields=created_at&expansions=author_id&user.fields=created_at&max_results=100' \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/keys.st b/Datanalitica.package/TwitterAPI.class/instance/keys.st new file mode 100644 index 0000000..03ed198 --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/keys.st @@ -0,0 +1,3 @@ +accessing +keys + ^ keys ifNil: [ keys := Dictionary new] \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/loadKeys.st b/Datanalitica.package/TwitterAPI.class/instance/loadKeys.st new file mode 100644 index 0000000..68e3e7d --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/loadKeys.st @@ -0,0 +1,4 @@ +accessing +loadKeys + keys := self class loadKeys. + ^ keys \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/rawResponseForURL..st b/Datanalitica.package/TwitterAPI.class/instance/rawResponseForURL..st new file mode 100644 index 0000000..2c3b790 --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/rawResponseForURL..st @@ -0,0 +1,6 @@ +accessing +rawResponseForURL: anUrl + ^ ZnClient new + headerAt: 'Authorization' put: 'Bearer ', self bearerToken; + url: anUrl; + get. \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/userIDFrom..st b/Datanalitica.package/TwitterAPI.class/instance/userIDFrom..st new file mode 100644 index 0000000..746989f --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/userIDFrom..st @@ -0,0 +1,5 @@ +queries +userIDFrom: username + | rawResponse | + rawResponse := self rawResponseForURL: self usersBaseEndPoint, 'by/username/', username. + ^ (STONJSON fromString: rawResponse) at: 'data' at: 'id' \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor..st b/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor..st new file mode 100644 index 0000000..4fa1e3f --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/userMentionsFor..st @@ -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) \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/userTweetsFor..st b/Datanalitica.package/TwitterAPI.class/instance/userTweetsFor..st new file mode 100644 index 0000000..c40869f --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/userTweetsFor..st @@ -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) \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/userTweetsFrom..st b/Datanalitica.package/TwitterAPI.class/instance/userTweetsFrom..st new file mode 100644 index 0000000..9a24a9a --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/userTweetsFrom..st @@ -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) \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/instance/usersBaseEndPoint.st b/Datanalitica.package/TwitterAPI.class/instance/usersBaseEndPoint.st new file mode 100644 index 0000000..9e2d942 --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/instance/usersBaseEndPoint.st @@ -0,0 +1,3 @@ +utilities api +usersBaseEndPoint + ^ 'https://api.twitter.com/2/users/' \ No newline at end of file diff --git a/Datanalitica.package/TwitterAPI.class/properties.json b/Datanalitica.package/TwitterAPI.class/properties.json new file mode 100644 index 0000000..5798ddd --- /dev/null +++ b/Datanalitica.package/TwitterAPI.class/properties.json @@ -0,0 +1,13 @@ +{ + "commentStamp" : "", + "super" : "Object", + "category" : "Datanalitica", + "classinstvars" : [ ], + "pools" : [ ], + "classvars" : [ + "keys" + ], + "instvars" : [ ], + "name" : "TwitterAPI", + "type" : "normal" +} \ No newline at end of file diff --git a/Datanalitica.package/monticello.meta/categories.st b/Datanalitica.package/monticello.meta/categories.st new file mode 100644 index 0000000..72c02a8 --- /dev/null +++ b/Datanalitica.package/monticello.meta/categories.st @@ -0,0 +1 @@ +SystemOrganization addCategory: #Datanalitica! diff --git a/Datanalitica.package/monticello.meta/initializers.st b/Datanalitica.package/monticello.meta/initializers.st new file mode 100644 index 0000000..e69de29 diff --git a/Datanalitica.package/monticello.meta/package b/Datanalitica.package/monticello.meta/package new file mode 100644 index 0000000..fc65896 --- /dev/null +++ b/Datanalitica.package/monticello.meta/package @@ -0,0 +1 @@ +(name 'Datanalitica') \ No newline at end of file diff --git a/Datanalitica.package/properties.json b/Datanalitica.package/properties.json new file mode 100644 index 0000000..6f31cf5 --- /dev/null +++ b/Datanalitica.package/properties.json @@ -0,0 +1 @@ +{ } \ No newline at end of file