Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
W.I.P.
Browse files Browse the repository at this point in the history
  • Loading branch information
pierce-h committed Sep 8, 2020
1 parent 598d7a2 commit 219b1f2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default abstract class BaseCommand extends Base {
public async getCurrentUser(): Promise<AppUser> {
const apiKey = await ApiKeyStore.get()
const apiClient = new APIClient(apiKey);
const user = await apiClient.user.getCurrent()
const user = await apiClient.users.getCurrent()

return user;
}
Expand Down
10 changes: 7 additions & 3 deletions src/core/api-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import ono from '@jsdevtools/ono';
import Apps from "./resources/apps";
import Deployments from "./resources/deployments";
import Diagnostics from "./resources/diagnostics";
import User from "./resources/user";
import Sellers from "./resources/sellers";
import Users from "./resources/users";

export interface ApiClientParams {
endpoint: string;
Expand Down Expand Up @@ -37,7 +38,9 @@ export default class APIClient {

diagnostics: Diagnostics;

user: User;
sellers: Sellers;

users: Users;

apiKey: string;

Expand All @@ -49,7 +52,8 @@ export default class APIClient {
this.apps = new Apps(this);
this.deployments = new Deployments(this);
this.diagnostics = new Diagnostics(this);
this.user = new User(this);
this.sellers = new Sellers(this);
this.users = new Users(this);
}

async call<T>({
Expand Down
23 changes: 23 additions & 0 deletions src/core/api-client/resources/sellers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AppUser } from "../../types";
import AppsAPIClient from '..';

export default class Sellers {
private client: AppsAPIClient;

constructor(apiClient: AppsAPIClient) {
this.client = apiClient;
}

/**
* Gets the current user for the given API key.
* @returns {Promise<AppUser>} Promise that resolves to an AppUser.
*/
async getCurrent(): Promise<AppUser> {
const response = await this.client.call<AppUser>({
endpoint: "diagnostics/whoami",
method: "GET",
});

return response;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppUser } from "../../types";
import AppsAPIClient from '..';

export default class User {
export default class Users {
private client: AppsAPIClient;

constructor(apiClient: AppsAPIClient) {
Expand Down
4 changes: 2 additions & 2 deletions test/specs/core/api-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ describe("AppsApiClient @integration", () => {
let errorResponse;

try {
response = await validClient.user.getCurrent();
response = await validClient.users.getCurrent();
} catch (error) {
errorResponse = error;
}
Expand All @@ -578,7 +578,7 @@ describe("AppsApiClient @integration", () => {
let errorResponse;

try {
response = await invalidClient.user.getCurrent();
response = await invalidClient.users.getCurrent();
} catch (error) {
errorResponse = error;
}
Expand Down

0 comments on commit 219b1f2

Please sign in to comment.