-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in an authorization method for users.
- Loading branch information
1 parent
002e940
commit 32738d6
Showing
10 changed files
with
454 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,44 @@ | ||
# Anilist-Node | ||
A simple, lightweight Node.js wrapper for the AniList API. | ||
|
||
##Installing | ||
``` | ||
npm install anilist-node | ||
``` | ||
## Installing | ||
Install with: `npm install anilist-node --dev` for the following: | ||
1. Searches that need a user login | ||
2. Uses such as editing a user's list | ||
AND not having a client and token with AniList | ||
|
||
Then, in order to begin using the package, just refer to it as with any other package. | ||
```javascript | ||
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. Next, change the name of the settings_example.json to settings.json or copy paste into a new JSON file. As long as the end result leads to a settings.json with content like in the example JSON file. Add your email, password, and client id in the proper spots and save. In the same directory, run `node authorization.js`. A file titled "token.txt" should appear. That is your token. Store it securely. There is an example in the Example section on how to use the token. | ||
|
||
Optional: | ||
- You may delete your AniList credentials from the settings.json file (Email, password, and client id if you feel inclined) | ||
- You may uninstall puppeteer via `npm uninstall puppeeteer` in the anilist-node directory | ||
- You may delete authorization.js file if you don't need it. | ||
- You may delete token.txt (Do store your token securely elsewhere before doing so) | ||
|
||
## Example | ||
### General lookup search (no login): | ||
```javascript | ||
const anilist = require('anilist-node'); | ||
const Anilist = new anilist(); | ||
|
||
Anilist.media.anime(21708).then(data => { | ||
console.log(data); | ||
}); | ||
``` | ||
|
||
##Example | ||
```javascript | ||
const list = require('anilist-node'); | ||
const anilist = new list(); | ||
### Lookup search (login): | ||
```javascript | ||
const settings = require('./settings.json'); | ||
const anilist = require('anilist-node'); | ||
const Anilist = new anilist(settings.token /* This being your token */); | ||
|
||
anilist.media.anime(21708).then(data => { | ||
Anilist.media.anime(21708).then(data => { | ||
console.log(data); | ||
}); | ||
``` | ||
|
||
##Documentation | ||
Please see [documentation.md](Documentation.md) file for more information | ||
## Documentation | ||
Please see [documentation.md](documentation.md) file for more information |
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,30 +1,36 @@ | ||
const User = require('./user'); | ||
const media = require('./media'); | ||
const people = require('./people'); | ||
const search = require('./search.json'); | ||
const fetcher = require('./fetcher'); | ||
const Fetch = new fetcher(); | ||
|
||
module.exports = class AniList { | ||
constructor () { | ||
this.user = new User(); | ||
this.media = new media(); | ||
this.people = new people(); | ||
constructor (accessKey) { | ||
if (!accessKey) { var accessKey = null; } | ||
this.user = new User(accessKey); | ||
this.media = new media(accessKey); | ||
this.people = new people(accessKey); | ||
this.accessKey = accessKey; | ||
}; | ||
|
||
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 }); | ||
return Fetch.send(`query($id: Int) { Studio(id: $id) { id name media { edges { id } } siteUrl isFavourite } }`, { id: id }, this.accessKey); | ||
}; | ||
|
||
search(term, page, amount){ | ||
if (!term || !page || !amount) { throw new Error("Search term, page count, or amount per page was not provided!"); } | ||
search(type, term, page, amount) { | ||
if (!type) { throw new Error("Type of search not defined!"); } | ||
else if (!term || !page || !amount) { throw new Error("Search term, page count, or amount per page was not provided!"); } | ||
switch (type) { | ||
case "anime": var query = search["anime"]; break; | ||
case "manga": var query = search["manga"]; break; | ||
case "char": var query = search["char"]; break; | ||
case "staff": var query = search["staff"]; break; | ||
case "studio": var query = search["studio"]; break; | ||
default: throw new Error("Type not supported."); | ||
} | ||
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}); | ||
Page (page: $page, perPage: $perPage) { pageInfo { total currentPage lastPage hasNextPage perPage } ${query} } }`, { search: term, page: page, perPage: amount}); | ||
}; | ||
}; |
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
Oops, something went wrong.