Skip to content

Commit

Permalink
fix (DDragonRequest): Address case where a cache is not used and vers…
Browse files Browse the repository at this point in the history
…ion is unspecified / implicit #60
  • Loading branch information
cnguy committed Dec 25, 2018
1 parent 5f08a60 commit 18b4de1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ kayn.DDragon.Champion.list()
})

// Let's say the config region is North America and that the latest version
// for the champion endpoint in NA is 8.15.1
kayn.DDragon.Champion.list() // Implicitly targets 8.15.1
// for the champion endpoint in NA is 8.24.1
kayn.DDragon.Champion.list() // Implicitly targets 8.24.1
.callback(function(error, champions) {
console.log(champions)
})
Expand Down
18 changes: 4 additions & 14 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,7 @@ const kayn = Kayn()({
delayBeforeRetry: 1000,
},
cacheOptions: {
cache: myCache,
ttls: {},
timeToLives: {
useDefault: true,
byGroup: {
DDRAGON: 10000,
},
byMethod: {
[METHOD_NAMES.DDRAGON.RUNES_REFORGED_LIST]: 5000,
[METHOD_NAMES.CHAMPION.GET_CHAMPION_ROTATIONS]: 5000,
},
},
cache: new BasicJSCache(),
},
})

Expand All @@ -55,8 +44,9 @@ const main = async () => {
const challengers = await kayn.ChallengerV4.list('RANKED_SOLO_5x5')
const grandmasters = await kayn.GrandmasterV4.list('RANKED_SOLO_5x5')
// const inori = await kayn.SummonerV4.by.name('ìnori')
console.log(kayn.TournamentV4.create('123', { test: 'boo' }))
console.log(kayn.TournamentStubV4.create('123', { test: 'boo' }))
kayn.DDragon.Champion.list().callback(function(error, champions) {
console.log(Object.keys(champions).length)
})
} catch (ex) {
console.log(ex)
}
Expand Down
57 changes: 36 additions & 21 deletions lib/RequestClient/DDragonRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,45 @@ DDragonRequest.prototype.callback = async function(cb) {
}
const realmArg = { endpoint: (region || this.config.region) + '.json' }
const self = this
this.config.cacheOptions.cache.get(
{
key: ddragonRequestTypeToUrl(
DDragonRequestTypes.REALMS,
realmArg,
),
},
function(err, data) {
if (data) {
executeWithVersion(endpoint, data.n)
} else {
const url = ddragonRequestTypeToUrl(
if (this.config.cacheOptions.cache) {
// Cache exists and version is unspecified
this.config.cacheOptions.cache.get(
{
key: ddragonRequestTypeToUrl(
DDragonRequestTypes.REALMS,
realmArg,
)
self.execute(url, true, function(err, data) {
const { n: versions } = data
executeWithVersion(endpoint, versions)
})
}
},
)
return
),
},
function(err, data) {
if (data) {
executeWithVersion(endpoint, data.n)
} else {
const url = ddragonRequestTypeToUrl(
DDragonRequestTypes.REALMS,
realmArg,
)
self.execute(url, true, function(err, data) {
const { n: versions } = data
executeWithVersion(endpoint, versions)
})
}
},
)
return
} else {
// Cache does not exist and version is unspecified
const url = ddragonRequestTypeToUrl(
DDragonRequestTypes.REALMS,
realmArg,
)
self.execute(url, true, function(err, data) {
const { n: versions } = data
executeWithVersion(endpoint, versions)
})
return
}
}
// Cache does not exist and version was specified
const url = ddragonRequestTypeToUrl(type, { endpoint, locale, version })
this.execute(url, cb)
}
Expand Down

0 comments on commit 18b4de1

Please sign in to comment.