Backported API updates.
This commit is contained in:
parent
dd52d265e1
commit
4acdf6090f
1 changed files with 44 additions and 1 deletions
|
@ -71,7 +71,7 @@ const Flashii = function(baseUrl) {
|
||||||
const url = createUrl(path, fields);
|
const url = createUrl(path, fields);
|
||||||
if(params)
|
if(params)
|
||||||
for(const name in params) {
|
for(const name in params) {
|
||||||
if(name === 'fields')
|
if(name === 'fields' || params[name] === null || params[name] === undefined)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
url.setParam(name, params[name]);
|
url.setParam(name, params[name]);
|
||||||
|
@ -197,5 +197,48 @@ const Flashii = function(baseUrl) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const verifyKaomojiId = id => {
|
||||||
|
if(typeof id === 'number')
|
||||||
|
id = id.toString();
|
||||||
|
if(/^([^0-9]+)$/gu.test(id))
|
||||||
|
throw new Error('id argument is not an acceptable kaomoji id.');
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
|
||||||
|
fii.v1.kaomoji = function({ as=null, fields=null, fresh=false }) {
|
||||||
|
return new Commitment((success, fail) => {
|
||||||
|
send({ method: 'GET', path: '/v1/kaomoji', params: { as }, fields, fresh })
|
||||||
|
.success(({ status, body }) => {
|
||||||
|
if(status === 400)
|
||||||
|
throw new Error('As or fields argument contains unsupported value.');
|
||||||
|
if(status > 299)
|
||||||
|
throw new Error(`Failed to fetch kaomoji with error code ${status}.`);
|
||||||
|
|
||||||
|
success(body);
|
||||||
|
})
|
||||||
|
.fail(fail)
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
fii.v1.kaomoji.kaomoji = function({ id, fields=null, fresh=false }) {
|
||||||
|
return new Commitment((success, fail) => {
|
||||||
|
id = verifyKaomojiId(id);
|
||||||
|
|
||||||
|
send({ method: 'GET', path: `/v1/kaomoji/${id}`, fields, fresh })
|
||||||
|
.success(({ status, body }) => {
|
||||||
|
if(status === 400)
|
||||||
|
throw new Error('Fields argument contains unsupported value.');
|
||||||
|
if(status === 404)
|
||||||
|
throw new Error('Requested kaomoji does not exist.');
|
||||||
|
if(status > 299)
|
||||||
|
throw new Error(`Failed to fetch kaomoji "${id}" with error code ${status}.`);
|
||||||
|
|
||||||
|
success(body);
|
||||||
|
})
|
||||||
|
.fail(fail)
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return fii;
|
return fii;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue