diff --git a/README.md b/README.md index 4085563..a71d642 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/datahandlers/twitch.cr b/src/datahandlers/twitch.cr index b191ecb..77465d5 100644 --- a/src/datahandlers/twitch.cr +++ b/src/datahandlers/twitch.cr @@ -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"] diff --git a/src/routes/twitch.cr b/src/routes/twitch.cr index 66e8fbe..9552be5 100644 --- a/src/routes/twitch.cr +++ b/src/routes/twitch.cr @@ -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 diff --git a/src/twitchapi/gqlapi.cr b/src/twitchapi/gqlapi.cr index 197b3a1..9fe699e 100644 --- a/src/twitchapi/gqlapi.cr +++ b/src/twitchapi/gqlapi.cr @@ -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)