Skip to content

Commit

Permalink
New function: Studio
Browse files Browse the repository at this point in the history
Added the studio function

Added and moved the search function under the class AniList

Fleshed out more of the package.json file.

Added the start of the documentation file.
  • Loading branch information
AurelicButter committed Jun 20, 2018
1 parent 8b470ae commit 002e940
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 11 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Butterstroke
Copyright (c) 2018 Yvain Hoekstra

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
52 changes: 52 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#Media
- `media.anime(id)` | Fetches an anime by its id
- `media.manga(id)` | Fetches a manga by its id

#People
- `people.character(id)` | Fetches a character by their id
- `character.id` | Character's id
- `character.name` | Character's name (Three sub-values: first, last, native.)
- `character.image` | Character's image (Two sub-values: large and medium)
- `character.description` | Character's description
- `character.isFavourite` | [Requires login]: Character on the user's favourite list
- `character.siteUrl` | Character's AniList URL
- `character.media` | All media that the character is in (Returns ids only)

- `people.staff(id)` | Fetches a staff member by their id
- `staff.id` | Staff's id
- `staff.name` | Staff's name (Three sub-values: first, last, native)
- `staff.language` | Staff's language
- `staff.image` | Staff's image (Two sub-values: large and medium)
- `staff.description` | Staff's description
- `staff.isFavourite` | [Requires login]: Staff is on the user's favourite list
- `staff.siteUrl` | Staff's AniList URL
- `staff.staffMedia` | All media that the staff has been apart of (Returns ids only)
- `staff.characters` | All characters that the staff has voiced (Returns ids only)

#Search
- `Anilist.search(term, page, amount)` | Searches the database for an anime or manga that resembles the term provided.
- `search.pageInfo` | Page object
- `pageInfo.total` | Total amount of pages in search
- `pageInfo.currentPage` | Current page of the search
- `pageInfo.lastPage` | Last page of searched term
- `pageInfo.hasNextPage` | If the page has a next page or not
- `pageInfo.perPage` | How many results are on each page
- `search.media` | Search results (Returns as an array)
- `media.id` | Media ID
- `media.title` | Title of the media (Four sub-values: english, native, romaji, userPreferred)

#User
- `user.profile(username|id)` | Fetches an AniList user by either their username or id. Usernames must be strings and ids must be integers.
- `profile.id` | User's id
- `profile.name` | User's username
- `profile.about` | User's description
- `profile.avatar` | User's avatar (Two sub-values: large and medium)
- `profile.bannerImage` | User's banner image
- `profile.isFollowing` | [Requires login] Logged in user following user
- `profile.options` | User's options (Four sub-values: titleLanguage, displayAdultContent, airingNotifications, profileColor)
- `profile.mediaListOptions` | Undocumented (Five sub-values: scoreFormat, rowOrder, useLegacyLists, sharedTheme, sharedThemeEnabled)
- `profile.unreadNotificationCount` | Amount of unreadNotifications the user has
- `profile.siteUrl` | User's AniList URL
- `profile.donatorTier` | Check if the user is a donator
- `profile.moderatorStatus` | Check if the user is a moderator
- `profile.updatedAt` | Timestamp of the last update of the user
2 changes: 2 additions & 0 deletions fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = class fetcher {
if (json.data.Media) { return json.data.Media; }
else if (json.data.Character) { return json.data.Character; }
else if (json.data.Staff) { return json.data.Staff; }
else if (json.data.Page) { return json.data.Page; }
else if (json.data.Studio) { return json.data.Studio; }
else if (json.data.User) {
if (json.data.User.stats) { return json.data.User.stats; }
else { return json.data.User; }
Expand Down
24 changes: 19 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
const User = require('./user');
const media = require('./media');
const extra = require('./extras');
const people = require('./people');
const fetcher = require('./fetcher');
const Fetch = new fetcher();

module.exports = class AniList {
constructor () {
this.user = new User();

this.user = new User();
this.media = new media();
this.people = new people();
};

this.extra = new extra();
studio(id) {
if (!id) { throw new Error("Studio id is not provided."); }
return Fetch.send(`query($id: Int) { Studio(id: $id) {
id name media { edges { id } }
siteUrl isFavourite } }`, { id: id });
};

this.people = new people();
search(term, page, amount){
if (!term || !page || !amount) { throw new Error("Search term, page count, or amount per page was not provided!"); }
return Fetch.send(`query ($id: Int, $page: Int, $perPage: Int, $search: String) {
Page (page: $page, perPage: $perPage) {
pageInfo { total currentPage lastPage hasNextPage perPage }
media (id: $id, search: $search) { id title { romaji english native userPreferred } }
}
}`, { search: term, page: page, perPage: amount});
};
};
4 changes: 2 additions & 2 deletions media.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = class media {
constructor() { };

anime(id) {
if (!id) { throw new Error("Media id is not provided!"); }
if (!id) { throw new Error("Anime id is not provided!"); }
return Fetch.send(`query ($id: Int) { Media (id: $id, type: ANIME) {
id idMal title { romaji english native userPreferred }
type episodes description
Expand Down Expand Up @@ -34,7 +34,7 @@ module.exports = class media {
};

manga(id) {
if (!id) { throw new Error("Media id is not provided!"); }
if (!id) { throw new Error("Manga id is not provided!"); }
return Fetch.send(`query ($id: Int) { Media (id: $id, type: MANGA) { id idMal
title { romaji english native userPreferred }
type description format status
Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
{
"name": "anilist-node",
"version": "1.0.0",
"description": "",
"description": "A lightweight Node.js wrapper for the AniList API",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Butterstroke",
"author": {
"name": "Yvain Hoekstra",
"email": "[email protected]"
},
"repository": {
"type": "git",
"url": "git+https://github.com/butterstroke/Anilist-Node"
},
"bugs": {
"url": "https://github.com/butterstroke/Anilist-Node/issues"
},
"license": "MIT",
"dependencies": {
"node-fetch": "^2.1.2"
}
}
}

0 comments on commit 002e940

Please sign in to comment.