-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Butterstroke/1.2.3
Version 1.2.3
- Loading branch information
Showing
10 changed files
with
170 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
const Fetch = require('./fetcher'); | ||
const { send } = require('./fetcher'); | ||
|
||
module.exports = { | ||
/** | ||
* Fetch a character entry by its AniList ID. | ||
* @param { Number|String } id - Required. The ID tied to the AniList entry. | ||
* @returns { Object } Returns a customized data object. | ||
*/ | ||
character: function(id) { | ||
if (!id) { throw new Error("Person id is not provided"); } | ||
return Fetch.send(`query ($id: Int) { Character (id: $id) { id name { first last native } image { large medium } | ||
description isFavourite siteUrl media { nodes { id idMal title { romaji english native userPreferred } format } } } }`, { id: id }); | ||
if (!id) { throw new Error("Character term is not provided!"); } | ||
|
||
if (typeof id === 'string') { queryVars = [{ search: id }, `query ($search: String) { Character (search: $search) { `]; } | ||
else if (typeof id === 'number') { queryVars = [{ id: id }, `query ($id: Int) { Character (id: $id,) { `]; } | ||
else { throw new Error("Term does not match the required types!"); } | ||
|
||
return send(queryVars[1] + `id name { first last native } image { large medium } description isFavourite favourites | ||
siteUrl media { nodes { id idMal title { romaji english native userPreferred } format } } } }`, queryVars[0]); | ||
}, | ||
/** | ||
* Fetch a staff entry by its AniList ID or their name. | ||
* @param { Number|String } id - Required. The ID can either be the AniList ID or the staff's name. | ||
* @returns { Object } Returns a customized data object. | ||
*/ | ||
staff: function(id) { | ||
if (!id) { throw new Error("Person id is not provided"); } | ||
qStart = (typeof id === "string") ? [{ search: id }, `query ($search: String) { Staff (search: $search) { `] : [{ id: id }, `query ($id: Int) { Staff (id: $id) { `]; | ||
if (!id) { throw new Error("Person term is not provided"); } | ||
|
||
if (typeof id === 'string') { queryVars = [{ search: id }, `query ($search: String) { Staff (search: $search) { `]; } | ||
else if (typeof id === 'number') { queryVars = [{ id: id }, `query ($id: Int) { Staff (id: $id,) { `]; } | ||
else { throw new Error("Term does not match the required types!"); } | ||
|
||
return Fetch.send(qStart[1] + `id name { first last native } language image { large medium } | ||
description isFavourite siteUrl | ||
return send(queryVars[1] + `id name { first last native } language image { large medium } | ||
description isFavourite siteUrl favourites | ||
staffMedia { nodes { id title { romaji english native userPreferred } } } | ||
characters { nodes { id name { first last } } } } }`, qStart[0]); | ||
characters { nodes { id name { first last } } } } }`, queryVars[0]); | ||
} | ||
}; |
Oops, something went wrong.