Skip to content

Commit 9cd0a57

Browse files
committed
Push v0.3.0
1 parent b1d2d70 commit 9cd0a57

File tree

15 files changed

+46
-298
lines changed

15 files changed

+46
-298
lines changed

XIVAPI.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
const resources = require('./resources/'),
2-
32
Search = require('./lib/search'),
43
Data = require('./lib/data'),
54
Character = require('./lib/character'),
65
FreeCompany = require('./lib/freecompany'),
76
Linkshell = require('./lib/linkshell'),
8-
PvPTeam = require('./lib/pvpteam'),
9-
Lodestone = require('./lib/lodestone'),
10-
Market = require('./lib/market')
7+
PvPTeam = require('./lib/pvpteam')
118

129
class XIVAPI {
1310
/*{
@@ -45,15 +42,14 @@ See how in https://github.com/xivapi/xivapi-js/releases/tag/v0.1.3.\n\
4542
this.verbose = options.verbose
4643

4744
this.resources = resources
45+
this.utils = require('./utils')
4846

4947
this.search = Search.bind(this)
5048
this.data = new Data(this)
5149
this.character = new Character(this)
5250
this.freecompany = new FreeCompany(this)
5351
this.linkshell = new Linkshell(this)
5452
this.pvpteam = new PvPTeam(this)
55-
this.lodestone = Lodestone.bind(this)
56-
this.market = new Market(this)
5753
}
5854
}
5955

lib/Lib.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
const { req } = require('../utils')
1+
const utils = require('../utils')
22

33
class Lib {
44
constructor(parent) {
55
this.parent = parent
66

7-
this.req = req.bind(parent)
7+
this.req = utils.req.bind(parent)
8+
this.reqJSON = utils.reqJSON.bind(parent)
9+
this.makeCSV = utils.makeCSV
10+
this.throwError = utils.throwError
811
}
912
}
1013

lib/character.js

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
// https://xivapi.com/docs/Character
22
const Lib = require('./Lib')
3-
let { makeStatus, correctCase } = require('../utils')
43

54
class Character extends Lib {
65
constructor(parent) {
76
super(parent)
8-
makeStatus = makeStatus.bind(parent)
97
}
108

119
/*
1210
{
13-
server string optional
14-
page int optional
11+
server
12+
page
1513
}
1614
*/
1715
search(name, params = {}) {
1816
return new Promise((resolve, reject) => {
1917
if(!name)
20-
reject(Error('The name must be defined for Character searching.'))
18+
reject(this.throwError('character.search()', 'a name'))
2119

2220
this.req(
2321
'/character/search',
@@ -39,57 +37,21 @@ class Character extends Lib {
3937
get(id, params = {}) {
4038
return new Promise((resolve, reject) => {
4139
if(!id)
42-
reject(Error('The id must be defined for get() in Character.'))
40+
reject(this.throwError('character.get()', 'an ID'))
4341

4442
params.extended = params.extended ? 1 : 0
4543

4644
this.req(
4745
'/character/' + id,
4846
params
4947
).then((res) => {
50-
res = makeStatus(res, 'character')
5148
resolve(res)
5249
}).catch((err) => {
5350
reject(err)
5451
})
5552
})
5653
}
5754

58-
/*
59-
token optional
60-
*/
61-
verification(id, token) {
62-
return new Promise((resolve, reject) => {
63-
if(!id)
64-
reject(Error('The id must be defined for Character verification.'))
65-
66-
this.req(
67-
`/character/${id}/verification`,
68-
{token: token}
69-
).then((res) => {
70-
if(token)
71-
resolve(res[correctCase('pass', this.parent.globalParams.snake_case)])
72-
else
73-
resolve(res[correctCase('bio', this.parent.globalParams.snake_case)])
74-
}).catch((err) => {
75-
reject(err)
76-
})
77-
})
78-
}
79-
80-
update(id) {
81-
return new Promise((resolve, reject) => {
82-
if(!id)
83-
reject(Error('The id must be defined for Character update.'))
84-
85-
this.req(`/character/${id}/update`).then((res) => {
86-
resolve(res === 1)
87-
}).catch((err) => {
88-
reject(err)
89-
})
90-
})
91-
}
92-
9355
}
9456

9557
module.exports = Character

lib/data.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// https://xivapi.com/docs/Welcome#section-4
22
const Lib = require('./Lib')
3-
let { cleanContent, makeCSV } = require('../utils')
43

54
class Content extends Lib {
65
constructor(parent) {
76
super(parent)
8-
9-
cleanContent = cleanContent.bind(parent)
107
}
118

129
content() {
@@ -28,9 +25,9 @@ class Content extends Lib {
2825
list(name, params = {}) {
2926
return new Promise((resolve, reject) => {
3027
if(typeof(name) === 'undefined')
31-
reject(Error('The name must be defined for Content list.'))
28+
reject(this.throwError('content.list()', 'a name'))
3229

33-
params.ids = makeCSV(params.ids)
30+
params.ids = this.parent.utils.makeCSV(params.ids)
3431

3532
this.req(
3633
`/${name}`,
@@ -43,28 +40,35 @@ class Content extends Lib {
4340
})
4441
}
4542

46-
schema(name) {
43+
get(name, id) {
4744
return new Promise((resolve, reject) => {
4845
if(typeof(name) === 'undefined')
49-
reject(Error('The name must be defined for Content schema.'))
46+
reject(this.throwError('content.get()', 'a name'))
47+
if(typeof(id) === 'undefined')
48+
reject(this.throwError('content.get()', 'an ID'))
5049

51-
this.req(`/${name}/schema`).then((res) => {
50+
this.req(`/${name}/${id}`).then((res) => {
5251
resolve(res)
5352
}).catch((err) => {
5453
reject(err)
5554
})
5655
})
5756
}
5857

59-
get(name, id) {
58+
servers() {
6059
return new Promise((resolve, reject) => {
61-
if(typeof(name) === 'undefined')
62-
reject(Error('The name must be defined for get() in Content.'))
63-
if(typeof(id) === 'undefined')
64-
reject(Error('The id must be defined for get() in Content.'))
60+
this.req('/servers').then((res) => {
61+
resolve(res)
62+
}).catch((err) => {
63+
reject(err)
64+
})
65+
})
66+
}
6567

66-
this.req(`/${name}/${id}`).then((res) => {
67-
resolve(cleanContent(res, this.parent.globalParams.snake_case))
68+
datacenters() {
69+
return new Promise((resolve, reject) => {
70+
this.req('/servers/dc').then((res) => {
71+
resolve(res)
6872
}).catch((err) => {
6973
reject(err)
7074
})

lib/freecompany.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// https://xivapi.com/docs/Free-Company
22
const Lib = require('./Lib')
3-
let { makeStatus, sanitizeInt, makeCSV } = require('../utils')
43

54
class FreeCompany extends Lib {
65
constructor(parent) {
76
super(parent)
8-
makeStatus = makeStatus.bind(parent)
97
}
108

119
/*
@@ -17,7 +15,7 @@ class FreeCompany extends Lib {
1715
search(name, params = {}) {
1816
return new Promise((resolve, reject) => {
1917
if(typeof(name) === 'undefined')
20-
reject(Error('The name must be defined for FreeCompany search.'))
18+
reject(this.throwError('freecompany.search()', 'a name'))
2119

2220
this.req(
2321
'/freecompany/search',
@@ -39,16 +37,14 @@ class FreeCompany extends Lib {
3937
get(id, params = {}) {
4038
return new Promise((resolve, reject) => {
4139
if(typeof(id) === 'undefined')
42-
reject(Error('The id must be defined for get() in FreeCompany.'))
40+
reject(this.throwError('freecompany.get()', 'an ID'))
4341

44-
id = sanitizeInt(id)
45-
params.data = makeCSV(params.data)
42+
params.data = this.makeCSV(params.data)
4643

4744
this.req(
4845
'/freecompany/' + id,
4946
params
5047
).then((res) => {
51-
res = makeStatus(res, 'free_company')
5248
resolve(res)
5349
}).catch((err) => {
5450
reject(err)

lib/linkshell.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// https://xivapi.com/docs/Linkshell
22
const Lib = require('./Lib')
3-
let { makeStatus, sanitizeInt } = require('../utils')
43

54
class Linkshell extends Lib {
65
constructor(parent) {
76
super(parent)
8-
makeStatus = makeStatus.bind(parent)
97
}
108

119
/*
@@ -17,7 +15,7 @@ class Linkshell extends Lib {
1715
search(name, params = {}) {
1816
return new Promise((resolve, reject) => {
1917
if(typeof(name) === 'undefined')
20-
reject(Error('The name must be defined for Linkshell search.'))
18+
reject(this.throwError('linkshell.search()', 'a name'))
2119

2220
this.req(
2321
'/linkshell/search',
@@ -33,11 +31,9 @@ class Linkshell extends Lib {
3331
get(id) {
3432
return new Promise((resolve, reject) => {
3533
if(typeof(id) === 'undefined')
36-
reject(Error('The id must be defined for get() in Linkshell.'))
37-
id = sanitizeInt(id)
34+
reject(this.throwError('linkshell.get()', 'an ID'))
3835

3936
this.req('/linkshell/' + id).then((res) => {
40-
res = makeStatus(res, 'linkshell')
4137
resolve(res)
4238
}).catch((err) => {
4339
reject(err)

lib/lodestone.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/market.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)