Skip to content

Commit

Permalink
Removed Authorization Module
Browse files Browse the repository at this point in the history
Removed the authorization module as it bloated the package without having much purpose. Users will now be required to get their token manually which has been explained in the README file.
  • Loading branch information
AurelicButter committed Aug 12, 2018
1 parent efb0cbf commit 6b50c06
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 429 deletions.
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Anilist-Node
A simple, lightweight Node.js wrapper for the AniList API.

## Installing
Install with: `npm install anilist-node --dev` for the following:
1. Searches that need a user login (ie: Checking for favourites)
2. Uses such as editing a user's list
## Using Anilist-node
To install: `npm install anilist-node`

AND not having a client and token with AniList
For some features such as checking favourites, a token will be required. You only need to generate a token once in order to use. To start, head to [Anilist's Developer Page](https://anilist.co/settings/developer) and click "Create New Client". Note the client id. Then, copy paste this URL `https://anilist.co/api/v2/oauth/authorize?client_id={clientID}&response_type=token`, replacing the `{clientID}` with your client ID. It will ask you to log in and then provide you with the token to use.

If that doesn't apply (ie: general searches, user lookups), you may install with `npm install anilist-node`

### Getting your token
You only need to generate a token once in order to use. To start, head to [Anilist's Developer Page](https://anilist.co/settings/developer) and click "Create New Client". Note the client id. Then use the auth function, providing client id, email, and password. The function will return the token. Store it securely. There is an example in the Example section on how to use the token.

If you wish to save space afterwards and know how to do so, you may uninstall puppeteer from the anilist-node directory.
NOTE: Please store your token securely and privately! This gives access to __your__ AniList account. It is your responsibility to maintain your token.

## Example
### General lookup search (no login):
Expand All @@ -28,7 +21,7 @@ Anilist.media.anime(21708).then(data => {

### Lookup search (login):
```javascript
const settings = require('./settings.json');
const settings = require('./settings.json'); //Or wherever your store your token.
const anilist = require('anilist-node');
const Anilist = new anilist(settings.token /* This being your token */);

Expand Down
23 changes: 10 additions & 13 deletions documentation.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# List of functions
`Anilist.search(type, term, page, amount)` | Search function
`Anilist.auth(clientID, email, password)` | Token generator. All arguments are required.
`Anilist.studio(id)` | Studio function
`Anilist.search(type, term, page, amount)` | Search function<br/>
`Anilist.studio(id)` | Studio function<br/>

## Media functions
`Anilist.media.anime(id)` | Anime function. Fetches an anime by its id.
`Anilist.media.manga(id)` | Manga function. Fetches a manga by its id.
`Anilist.media.add(id)` |
`Anlist.media.update(id)` |
`Anilist.media.remove(id)` |
`Anilist.media.anime(id)` | Anime function. Fetches an anime by its id.<br/>
`Anilist.media.manga(id)` | Manga function. Fetches a manga by its id.<br/>

## People functions
`Anilist.people.staff(id)` | Staff function. Fetches a staff member by their id.
`Anilist.people.character(id)` | Character function. Fetches a character by their id.
`Anilist.people.staff(id)` | Staff function. Fetches a staff member by their id.<br/>
`Anilist.people.character(id)` | Character function. Fetches a character by their id.<br/>

## User Functions
`Anilist.user.all(username|id)` | All user profile function
`Anilist.user.stats(username|id)` | User stats function
`Anilist.user.profile(username|id)` | User profile function
Usernames must be strings and ids must be numbers!<br/>
`Anilist.user.all(username|id)` | All user profile function<br/>
`Anilist.user.stats(username|id)` | User stats function<br/>
`Anilist.user.profile(username|id)` | User profile function<br/>

# Media

Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const media = require('./lib/media');
const people = require('./lib/people');
const search = require('./search.json');
const Fetch = require('./lib/fetcher');
const auth = require('./lib/authorization');

module.exports = class AniList {
constructor (accessKey) {
Expand All @@ -12,7 +11,6 @@ module.exports = class AniList {
this.user = User;
this.media = media;
this.people = people;
this.auth = auth;
};

studio(id) {
Expand Down
28 changes: 0 additions & 28 deletions lib/authorization.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
var response = await fetch('https://graphql.anilist.co', options);
var json = await response.json();

if (json.errors) {
if (json.data === null) {
if (json.errors[0].status === 404) { return { data: null, status: 404, message: "Search item by that term is not found." } }
else { return { data: null, status: json.errors[0].status, message: json.errors[0].message } }
} else if (json.data !== null) {
Expand Down
18 changes: 0 additions & 18 deletions lib/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,5 @@ module.exports = {
popularity trending tags { name isMediaSpoiler } relations { edges { id } } characters { edges { id } } staff { edges { id } }
isFavourite isAdult trends { edges { node { averageScore popularity inProgress episode } } }
externalLinks { url } rankings { id } mediaListEntry { id } reviews { edges { node { id } } } } }`, { id: id });
},
add: function(obj) {
if (Fetch.key === null) { throw new Error("No token is provided for list updates!"); }
if (!obj.id) { throw new Error("Media list id not provided"); }
if (!obj.status) { obj.status = "PLANNING"; }
return Fetch.send(`mutation ($id: Int, $status: String) { SaveMediaListEntry (id: $id, status: $status) { id mediaId status score scoreRaw
progress repeat priority private notes progressVolumes hiddenFromStatusLists customLists advancedScores startedAt completedAt } }`, obj);
},
update: function(obj) {
if (Fetch.key === null) { throw new Error("No token is provided for list updates!"); }
if (!obj.ids) { throw new Error("Media list id not provided"); }
return Fetch.send(`mutation ($ids: Int, $status: String) { UpdateMediaListEntries (ids: $ids, status: $status) { status score scoreRaw
progress repeat priority private notes hiddenFromStatusLists advancedScores startedAt completedAt ids progressVolumes } }`, obj);
},
delete: function(id) {
if (Fetch.key === null) { throw new Error("No token is provided for list updates!"); }
if (!id) { throw new Error("No id is provided for list updates!"); }
return Fetch.send(`mutation ($id: Int) { DeleteMediaListEntry (id: $id) { deleted } }`, { id: id });
}
};
24 changes: 12 additions & 12 deletions lib/user.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const Fetch = require('./fetcher');

module.exports = {
variables: function(uname, id) {
if (uname.length > 1) { return [{ name: uname }, `query ($name: String) { User (name: $name) { `]; }
else if (id.length > 1) { return [{ id: id }, `query ($id: Int) { User (id: $id) { `]; }
variables: function(user) {
if (typeof user === 'string') { return [{ name: user }, `query ($name: String) { User (name: $name) { `]; }
else if (typeof user === 'number') { return [{ id: user }, `query ($id: Int) { User (id: $id) { `]; }
},
profile: function(uname, id) {
if (!uname && !id) { throw new Error("AniList username or id is missing!"); }
var start = this.variables(uname, id);
profile: function(user) {
if (!user) { throw new Error("AniList username or id is missing!"); }
var start = this.variables(user);
var query = start[1] + `id name about avatar { large medium } bannerImage isFollowing
options { titleLanguage displayAdultContent airingNotifications profileColor }
mediaListOptions { scoreFormat rowOrder useLegacyLists sharedTheme sharedThemeEnabled }
unreadNotificationCount siteUrl donatorTier moderatorStatus updatedAt } }`;
return Fetch.send(query, start[0]);
},
stats: function(uname, id) {
if (!uname && !id) { throw new Error("AniList username or id is missing!"); }
var start = this.variables(uname, id);
stats: function(user) {
if (!user) { throw new Error("AniList username or id is missing!"); }
var start = this.variables(user);
var query = start[1] + `stats { watchedTime chaptersRead activityHistory { date amount level } animeStatusDistribution { status amount }
mangaStatusDistribution { status amount } animeScoreDistribution { score amount } mangaScoreDistribution { score amount }
animeListScores { meanScore standardDeviation } mangaListScores { meanScore standardDeviation }
Expand All @@ -26,9 +26,9 @@ module.exports = {
favouredYears { year amount meanScore } favouredFormats { format amount } } } }`;
return Fetch.send(query, start[0]);
},
all: function(uname, id) {
if (!uname && !id) { throw new Error("AniList username or id is missing!"); }
var start = this.variables(uname, id);
all: function(user) {
if (!user) { throw new Error("AniList username or id is missing!"); }
var start = this.variables(user);
var query = start[1] + `id name about avatar { large medium } bannerImage isFollowing
stats { watchedTime chaptersRead activityHistory { date amount level } animeStatusDistribution { status amount }
mangaStatusDistribution { status amount } animeScoreDistribution { score amount } mangaScoreDistribution { score amount }
Expand Down
Loading

0 comments on commit 6b50c06

Please sign in to comment.