Skip to content

Commit 32176bd

Browse files
author
Kimon Kar
committed
Make changes for new API key system
1 parent 6157142 commit 32176bd

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

XIVAPI.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,29 @@ const resources = require('./resources/'),
1111

1212
class XIVAPI {
1313
/*{
14-
language string 'en' optional
15-
staging bool false optional
16-
snake_case bool false optional
14+
private_key string undefined optional
15+
language string 'en' optional
16+
staging bool false optional
17+
snake_case bool false optional
1718
}
1819
*/
19-
constructor(apikey, options = {}) {
20-
if(typeof(apikey) === 'undefined')
21-
throw Error('The apikey must be defined.')
20+
constructor(options = {}, legacyOptions = {}) {
21+
//handle attempted use of old API key
22+
if(typeof(options) === 'string') {
23+
console.error('[xivapi-js] BREAKING CHANGE:\n\
24+
The previous API keys for XIVAPI have been phased out, and are no longer mandatory. \
25+
This means you\'ll have to define your key during initialization slightly differently. \
26+
See how in https://github.com/xivapi/xivapi-js/releases/tag/v0.1.3.\n\
27+
**This instance of xivapi-js will run WITHOUT an API key**')
28+
options = legacyOptions
29+
}
2230

2331
this.endpoint = `https://${options.staging ? 'staging.' : ''}xivapi.com`
24-
this.globalParams = {
25-
key: apikey,
26-
language: options.language || 'en',
27-
snake_case: options.snake_case
28-
}
29-
if(!resources.languages.includes(this.globalParams.language))
32+
if(options.language && !resources.languages.includes(options.language))
3033
throw Error(`Invalid language given, must be: ${this.resources.languages}`)
3134

35+
this.globalParams = options
36+
3237
this.resources = resources
3338

3439
this.search = Search.bind(this)

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const XIVAPI = require('./XIVAPI'),
22
readline = require('readline')
33

4-
const xiv = new XIVAPI('yourAPIkey', {snake_case: true})
4+
const xiv = new XIVAPI({snake_case: true})
55

66
let rl = readline.createInterface({
77
input: process.stdin,

0 commit comments

Comments
 (0)