-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(managers): move managers to root of lib
- Loading branch information
Showing
4 changed files
with
104 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Document as IDocument } from "../types/document"; | ||
import { Document } from "../classes/Document"; | ||
import { ErrorMessage } from "../errors/Messages"; | ||
import { Base } from "./Base"; | ||
import type { MeUser } from "../types/me"; | ||
|
||
export class MeManager extends Base { | ||
/** | ||
* Show current user | ||
*/ | ||
public async get(): Promise<MeUser> { | ||
if (!this.client.apiToken) throw new Error(ErrorMessage("NO_TOKEN")); | ||
|
||
return this.client.rest.request<MeUser>("GET", "/user/@me"); | ||
} | ||
|
||
/** | ||
* Show recent documents for the current user | ||
*/ | ||
public async recent(): Promise<Document[] | null> { | ||
if (!this.client.apiToken) throw new Error(ErrorMessage("NO_TOKEN")); | ||
|
||
const data = await this.client.rest.request<IDocument[]>("GET", "/user/@me/recentDocuments"); | ||
|
||
if (!data) return null; | ||
|
||
return data.map((document) => new Document(this.client, document)); | ||
} | ||
|
||
/** | ||
* Change the icon of the current user | ||
*/ | ||
public async setIcon(method: "github" | "gravatar", url: string): Promise<MeUser> { | ||
if (!this.client.apiToken) throw new Error(ErrorMessage("NO_TOKEN")); | ||
|
||
return this.client.rest.request<MeUser>("PATCH", "/user/@me/icon", { | ||
data: { | ||
method, | ||
url, | ||
}, | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { User as IUser } from "../types/users"; | ||
import { User } from "../classes/User"; | ||
import { ErrorMessage } from "../errors/Messages"; | ||
import { Base } from "./Base"; | ||
|
||
export class UsersManager extends Base { | ||
/** | ||
* Get a user from Imperial. | ||
* @param username - The username of the user to get. | ||
* @example client.users.get("pxseu").then(console.log) // Logs the user to the console. | ||
*/ | ||
public async get(username: string): Promise<User> { | ||
if (!this.client.apiToken) throw new Error(ErrorMessage("NO_TOKEN")); | ||
if (!username) throw new Error(ErrorMessage("NO_USERNAME")); | ||
if (typeof username !== "string") throw new TypeError(ErrorMessage("USERNAME_WRONG_TYPE")); | ||
|
||
const data = await this.client.rest.request<IUser>("GET", `/user/${encodeURIComponent(username)}`); | ||
|
||
return new User(this.client, data); | ||
} | ||
} |