Cache trophies

Basic cache for trophies
This commit is contained in:
Pablo Mayobre 2015-02-08 20:19:10 -03:00
parent bf5a4077bf
commit e91b39342d

View File

@ -6,6 +6,7 @@ local GJ = {
gameID, gameKey, gameID, gameKey,
isLoggedIn = false, isLoggedIn = false,
username, userToken username, userToken
trophies = {}
} }
local BASE_URL = "http://gamejolt.com/api/game/v1/" local BASE_URL = "http://gamejolt.com/api/game/v1/"
@ -193,7 +194,9 @@ end
-- trophies -- trophies
function GJ.giveTrophy(id) function GJ.giveTrophy(id)
return string.find(req("trophies/add-achieved/?trophy_id=" .. tostring(id), "dump", true, true), "SUCCESS") ~= nil local s = string.find(req("trophies/add-achieved/?trophy_id=" .. tostring(id), "dump", true, true), "SUCCESS") ~= nil
GJ.fetchAllTrophies(true)
return
end end
function GJ.fetchTrophy(id) function GJ.fetchTrophy(id)
@ -210,8 +213,11 @@ function GJ.fetchTrophiesByStatus(achieved)
return handleTrophies("achieved=" .. tostring(achieved)) return handleTrophies("achieved=" .. tostring(achieved))
end end
function GJ.fetchAllTrophies() function GJ.fetchAllTrophies(f)
return handleTrophies("") if f then
GJ.trophies = handleTrophies("")
end
return GJ.trophies
end end
-- scores -- scores