Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MrScopes committed Jan 18, 2021
1 parent f5cd0b7 commit b44ba07
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Create an issue on the repo or contact me on Discord @MrScopes#5548

## Example
```js
const { Client } = require('anilist-js');
const { Client } = require('anilist.js');
const AniList = new Client('API TOKEN'); // token is only required for some features

(async () => {
Expand Down Expand Up @@ -40,7 +40,7 @@ _Italics_ represents authorization required.
<br><br>
- _`.me()`_ -> Currently authorized user
- `.getUser(id)`
- `.searchUsers(variables)`
- `.searchUsers(variables)`
<br><br>
- `.getStaff(id)`
- `.searchStaff(variables)`
Expand Down Expand Up @@ -68,6 +68,7 @@ _Italics_ represents authorization required.
- `User >`
- .info
- _.follow()_
- .getStats()
<br><br>
- `Staff >`
- .info
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anilist.js",
"version": "1.1.0",
"version": "1.2.0",
"description": "Communicate with the AniList API.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -16,7 +16,8 @@
"author": "MrScopes",
"license": "ISC",
"dependencies": {
"node-fetch": "^2.6.1"
"node-fetch": "^2.6.1",
"tslib": "^2.1.0"
},
"devDependencies": {
"@types/node-fetch": "^2.5.7",
Expand Down
237 changes: 237 additions & 0 deletions src/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,243 @@ query ($id: Int) {
}
`

export const UserStatsQuery = `
query ($id: Int) {
User(id: $id) {
statistics {
anime {
count
meanScore
standardDeviation
minutesWatched
episodesWatched
chaptersRead
volumesRead
formats {
count
meanScore
minutesWatched
chaptersRead
mediaIds
format
}
statuses {
count
meanScore
minutesWatched
chaptersRead
mediaIds
status
}
scores {
count
meanScore
minutesWatched
chaptersRead
mediaIds
score
}
lengths {
count
meanScore
minutesWatched
chaptersRead
mediaIds
length
}
releaseYears {
count
meanScore
minutesWatched
chaptersRead
mediaIds
releaseYear
}
startYears {
count
meanScore
minutesWatched
chaptersRead
mediaIds
startYear
}
genres {
count
meanScore
minutesWatched
chaptersRead
mediaIds
genre
}
tags {
count
meanScore
minutesWatched
chaptersRead
mediaIds
tag {
id
}
}
countries {
count
meanScore
minutesWatched
chaptersRead
mediaIds
country
}
voiceActors {
count
meanScore
minutesWatched
chaptersRead
mediaIds
voiceActor {
id
}
characterIds
}
staff {
count
meanScore
minutesWatched
chaptersRead
mediaIds
staff {
id
}
}
studios {
count
meanScore
minutesWatched
chaptersRead
mediaIds
studio {
id
}
}
}
manga {
count
meanScore
standardDeviation
minutesWatched
episodesWatched
chaptersRead
volumesRead
formats {
count
meanScore
minutesWatched
chaptersRead
mediaIds
format
}
statuses {
count
meanScore
minutesWatched
chaptersRead
mediaIds
status
}
scores {
count
meanScore
minutesWatched
chaptersRead
mediaIds
score
}
lengths {
count
meanScore
minutesWatched
chaptersRead
mediaIds
length
}
releaseYears {
count
meanScore
minutesWatched
chaptersRead
mediaIds
releaseYear
}
startYears {
count
meanScore
minutesWatched
chaptersRead
mediaIds
startYear
}
genres {
count
meanScore
minutesWatched
chaptersRead
mediaIds
genre
}
tags {
count
meanScore
minutesWatched
chaptersRead
mediaIds
tag {
id
}
}
countries {
count
meanScore
minutesWatched
chaptersRead
mediaIds
country
}
voiceActors {
count
meanScore
minutesWatched
chaptersRead
mediaIds
voiceActor {
id
}
characterIds
}
staff {
count
meanScore
minutesWatched
chaptersRead
mediaIds
staff {
id
}
}
studios {
count
meanScore
minutesWatched
chaptersRead
mediaIds
studio {
id
}
}
}
}
}
}
`

export const UserSearchQuery = `
query ($id: Int, $name: String, $search: String, $sort: [UserSort], $page: Int, $perPage: Int) {
Page(page: $page, perPage: $perPage) {
Expand Down
8 changes: 7 additions & 1 deletion src/structures/user/UserStructure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client } from '../..';
import { UserFollow } from '../../queries/mutations';
import { User } from '../../types/types';
import { UserStatsQuery } from '../../queries/queries';
import { User, UserStatisticTypes } from '../../types/types';

/** Represents an AniList User. */
export class UserStructure {
Expand All @@ -21,4 +22,9 @@ export class UserStructure {
if (!this.client?.token) throw new Error('This feature requires you to be logged in.');
return this.client.utilities.APIRequest(UserFollow, { userId: this.info.id }, this.client);
}

/** Get this user's AniList stats. */
async getStats(): Promise<UserStatisticTypes> {
return this.client?.utilities.APIRequest(UserStatsQuery, { id: this.info.id }, this.client)
}
}
5 changes: 3 additions & 2 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Client } from './index';
const AniList = new Client(process.env.token);

(async function () {
const media = await AniList.searchMedia({ genre_in: ['ACTION'] });
console.log(media);
const user = await AniList.me();
const stats = await user.getStats();
console.log(stats);
})();
6 changes: 4 additions & 2 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,10 @@ export type User = {
mediaListOptions?: Maybe<MediaListOptions>;
/** The users favourites */
favourites?: Maybe<Favourites>;
/** The users anime & manga list statistics */
statistics?: Maybe<UserStatisticTypes>;
/** The users anime & manga list statistics
*
* **NOTE: USE <User>.getStats() for this!** */
statistics?: null; //Maybe<UserStatisticTypes>;
/** The number of unread notifications the user has */
unreadNotificationCount?: Maybe<Scalars['Int']>;
/** The url for the user page on the AniList website */
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"strict": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"importHelpers": true
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ node-fetch@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

tslib@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==

0 comments on commit b44ba07

Please sign in to comment.