0.2.1: Add support for contract type and team.

This commit is contained in:
Fijxu 2024-06-22 03:46:40 -04:00
parent c085b71ede
commit 89b7ae32bc
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
4 changed files with 46 additions and 7 deletions

View file

@ -15,10 +15,10 @@
### NOT SO IMPORTANT TODO
- ~~STOP USING KEMAL FOR SIMPLE THINGS~~ Nevermind, kemal is pretty useful and it should stay
- `programAgreement { type }` in the Next commit.
- ~~`programAgreement { type }` in the Next commit~~ Done.
- Guide on how to get the tokens to get it working
- Kick API
### Suggestions
~~3:45 RyanPotat: add team~~ Next commit.
~~3:45 RyanPotat: add team~~ Done.

View file

@ -44,7 +44,7 @@ module TwAPI::Datahandlers::Twitch
def userLogin(env)
if skipCache != "true"
if (json = Utils::Redis.retrieveFromCache("user-login_#{env.params.query["login"].try &.split(',')}"))
if (json = Utils::Redis.retrieveFromCache("user-login_#{env.params.query["login"].try &.split(',').to_s}"))
json = JSON.parse(json)
return json.to_json
end
@ -89,6 +89,16 @@ module TwAPI::Datahandlers::Twitch
json.field "updatedAt", gql["user"]["updatedAt"]
json.field "deletedAt", gql["user"]["deletedAt"]
json.field "emotePrefix", gql["user"]["emoticonPrefix"]["name"]
if gql["user"]["primaryTeam"] != nil
json.field "team", gql["user"]["primaryTeam"]["displayName"]
else
json.field "team", nil
end
if gql["user"]["primaryTeam"] != nil
json.field "contract", gql["user"]["programAgreement"]["type"]
else
json.field "contract", nil
end
json.field "roles", gql["user"]["roles"]
json.field "badges", gql["user"]["displayBadges"]
json.field "chatterCount", gql["user"]["channel"]["chatters"]["count"]
@ -113,7 +123,7 @@ module TwAPI::Datahandlers::Twitch
def userId(env)
if skipCache != "true"
if (json = Utils::Redis.retrieveFromCache("user-id_#{env.params.query["id"].try &.split(',')}"))
if (json = Utils::Redis.retrieveFromCache("user-id_#{env.params.query["id"].try &.split(',').to_s}"))
json = JSON.parse(json)
return json.to_json
end
@ -128,7 +138,8 @@ module TwAPI::Datahandlers::Twitch
json_data = JSON.build do |json|
json.array do
gql.each do |gql|
gql = gql["data"]
pp gql = gql["data"]
pp typeof(gql)
if (gql["user"] == nil)
# v3 could add some feedback error message instead of an empty array.
@ -159,6 +170,22 @@ module TwAPI::Datahandlers::Twitch
json.field "updatedAt", gql["user"]["updatedAt"]
json.field "deletedAt", gql["user"]["deletedAt"]
json.field "emotePrefix", gql["user"]["emoticonPrefix"]["name"]
# failed attempts
# pp "1: #{gql["user"]["primaryTeam"]? || nil}"
# pp "2: #{gql["user"].try &.["primaryTeam"]?.try &.["displayName"]? || nil}"
# json.field "team", gql["user"]["primaryTeam"].try &.["displayName"]?
#
if gql["user"]["primaryTeam"] != nil
json.field "team", gql["user"]["primaryTeam"]["displayName"]
else
json.field "team", nil
end
if gql["user"]["primaryTeam"] != nil
json.field "contract", gql["user"]["programAgreement"]["type"]
else
json.field "contract", nil
end
json.field "roles", gql["user"]["roles"]
json.field "badges", gql["user"]["displayBadges"]
json.field "chatterCount", gql["user"]["channel"]["chatters"]["count"]

View file

@ -13,9 +13,17 @@ module TwAPI::Routes::Twitch
def user(env)
if env.params.query.has_key?("login")
handleData(userLogin)
begin
handleData(userLogin)
rescue ex
puts ex.message
end
else
handleData(userId)
begin
handleData(userId)
rescue ex
puts ex.message
end
end
end

View file

@ -45,6 +45,8 @@ module TwAPI::GqlAPI
language
login
displayName
programAgreement { type }
primaryTeam { displayName name }
description
bannerImageURL
profileImageURL(width: 600)
@ -158,6 +160,8 @@ module TwAPI::GqlAPI
language
login
displayName
programAgreement { type }
primaryTeam { displayName name }
description
bannerImageURL
profileImageURL(width: 600)