Skip to content

Commit

Permalink
refactor: rename trophy methods
Browse files Browse the repository at this point in the history
Convert trophy methods to belong to either `title` or `user` submodules.

BREAKING CHANGE: Several methods have been renamed so they are a bit more ergonomic to use and
understand.
  • Loading branch information
wescopeland committed Oct 23, 2021
1 parent 9b0d7b7 commit e913810
Show file tree
Hide file tree
Showing 28 changed files with 165 additions and 165 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ Click the function names for complete docs.

### Trophies

- [`getSummarizedTrophiesByTrophyGroup()`](src/trophy/getSummarizedTrophiesByTrophyGroup.md) - Get a summary of trophies earned for a user broken down by trophy group within a title.
- [`getTitleTrophyGroups()`](src/trophy/getTitleTrophyGroups.md) - Get a list of trophy groups (typically the base set and DLCs) for a title.
- [`getTrophiesEarnedForTitle()`](src/trophy/getTrophiesEarnedForTitle.md) - Retrieve the earned status of trophies for a user from either a single or all trophy groups in a title.
- [`getTrophiesForTitle()`](src/trophy/getTrophiesForTitle.md) - Retrieve the individual trophy details of a single or all trophy groups for a title.
- [`getTrophyProfileSummary()`](src/trophy/getTrophyProfileSummary.md) - Retrieve an overall summary of the number of trophies earned for a user broken down by type.
- [`getTrophyTitlesForUser()`](src/trophy/getTrophyTitlesForUser.md) - Retrieve a list of the titles associated with an account and a summary of trophies earned from them.
- [`getTitleTrophies()`](src/trophy/title/getTitleTrophies.md) - Retrieve the individual trophy details of a single or all trophy groups for a title.
- [`getTitleTrophyGroups()`](src/trophy/title/getTitleTrophyGroups.md) - Get a list of trophy groups (typically the base set and DLCs) for a title.
- [`getUserSummarizedTrophiesByTrophyGroup()`](src/trophy/user/getUserSummarizedTrophiesByTrophyGroup.md) - Get a summary of trophies earned for a user broken down by trophy group within a title.
- [`getUserTitles()`](src/trophy/user/getUserTitles.md) - Retrieve a list of the titles associated with an account and a summary of trophies earned from them.
- [`getUserTrophiesEarnedForTitle()`](src/trophy/user/getUserTrophiesEarnedForTitle.md) - Retrieve the earned status of trophies for a user from either a single or all trophy groups in a title.
- [`getUserTrophyProfileSummary()`](src/trophy/user/getUserTrophyProfileSummary.md) - Retrieve an overall summary of the number of trophies earned for a user broken down by type.

## Examples

Expand Down
12 changes: 6 additions & 6 deletions examples/buildUserTrophyList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Trophy } from "../src";
import {
exchangeCodeForAccessToken,
exchangeNpssoForCode,
getTrophiesEarnedForTitle,
getTrophiesForTitle,
getTrophyTitlesForUser,
getTitleTrophies,
getUserTitles,
getUserTrophiesEarnedForTitle,
TrophyRarity
} from "../src";

Expand All @@ -15,13 +15,13 @@ export const buildUserTrophyList = async (userId: string, npsso: string) => {
const accessCode = await exchangeNpssoForCode(npsso);
const authorization = await exchangeCodeForAccessToken(accessCode);

const { trophyTitles } = await getTrophyTitlesForUser(authorization, userId);
const { trophyTitles } = await getUserTitles(authorization, userId);

const games: any[] = [];

let count = 1;
for (const title of trophyTitles) {
const { trophies: titleTrophies } = await getTrophiesForTitle(
const { trophies: titleTrophies } = await getTitleTrophies(
authorization,
title.npCommunicationId,
"all",
Expand All @@ -31,7 +31,7 @@ export const buildUserTrophyList = async (userId: string, npsso: string) => {
}
);

const { trophies: earnedTrophies } = await getTrophiesEarnedForTitle(
const { trophies: earnedTrophies } = await getUserTrophiesEarnedForTitle(
authorization,
userId,
title.npCommunicationId,
Expand Down
8 changes: 4 additions & 4 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export * from "./access-token-response.model";
export * from "./authorization-payload.model";
export * from "./call-valid-headers.model";
export * from "./summarized-trophies-by-trophy-group-response.model";
export * from "./title-platform.model";
export * from "./title-trophies-response.model";
export * from "./title-trophy-groups-response.model";
export * from "./trophies-earned-for-title-response.model";
export * from "./trophy.model";
export * from "./trophy-counts.model";
export * from "./trophy-profile-summary-response.model";
export * from "./trophy-rarity.model";
export * from "./trophy-title.model";
export * from "./trophy-title.model";
export * from "./user-trophy-titles-response.model";
export * from "./user-summarized-trophies-by-trophy-group-response.model";
export * from "./user-titles-response.model";
export * from "./user-trophies-earned-for-title-response.model";
export * from "./user-trophy-profile-summary-response.model";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TrophyCounts } from "./trophy-counts.model";
import type { TrophyGroup } from "./trophy-group.model";

export interface SummarizedTrophiesByTrophyGroupResponse {
export interface UserSummarizedTrophiesByTrophyGroupResponse {
/** The current version of the trophy set. Some trophy sets receive updates. */
trophySetVersion: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TrophyTitle } from "./trophy-title.model";

export interface UserTrophyTitlesResponse {
export interface UserTitlesResponse {
trophyTitles: TrophyTitle[];
totalItemCount: number;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Trophy } from "./trophy.model";

export interface TrophiesEarnedForTitleResponse {
export interface UserTrophiesEarnedForTitleResponse {
/** The current version of the trophy set. Some trophy sets receive updates. */
trophySetVersion: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TrophyCounts } from "./trophy-counts.model";

export interface TrophyProfileSummaryResponse {
export interface UserTrophyProfileSummaryResponse {
/** The ID of the account being accessed. */
accountId: string;

Expand Down
8 changes: 2 additions & 6 deletions src/trophy/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
export * from "./getSummarizedTrophiesByTrophyGroup";
export * from "./getTitleTrophyGroups";
export * from "./getTrophiesEarnedForTitle";
export * from "./getTrophiesForTitle";
export * from "./getTrophyProfileSummary";
export * from "./getTrophyTitlesForUser";
export * from "./title";
export * from "./user";
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# getTrophiesForTitle
# getTitleTrophies

```ts
/**
* A request to this URL will retrieve the individual trophy detail of a
* A call to this function will retrieve the individual trophy detail of a
* single - or all - trophy groups for a title. A title can have multiple
* groups of trophies (a `default` group which all titles have, and additional
* groups named `"001"` incrementing for each additional group). To retrieve
Expand All @@ -20,11 +20,11 @@
* @param options.offset Return trophy data from this result onwards.
* @param options.headerOverrides Override the headers in the request to the PSN API, such as to change the language.
*/
export const getTrophiesForTitle = async (
export const getTitleTrophies = async (
authorization: AuthorizationPayload,
npCommunicationId: string,
trophyGroupId: string,
options?: Partial<GetTrophiesForTitleOptions>
options?: Partial<GetTitleTrophiesOptions>
): Promise<TitleTrophiesResponse> => { ... }
```

Expand Down Expand Up @@ -52,10 +52,7 @@ interface TitleTrophiesResponse {

// Returns a list of all trophies for all groups of Astro's Playroom.
// This response contains extended metadata for each trophy.
const response = await getTrophiesForTitle(
authorization,
"NPWR20188_00",
"all",
{ npServiceName: "trophy2" }
);
const response = await getTitleTrophies(authorization, "NPWR20188_00", "all", {
npServiceName: "trophy2"
});
```
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { rest } from "msw";
import { setupServer } from "msw/node";

import type { AuthorizationPayload, TitleTrophiesResponse } from "../models";
import { getTrophiesForTitle } from "./getTrophiesForTitle";
import { TROPHY_BASE_URL } from "./TROPHY_BASE_URL";
import type { AuthorizationPayload, TitleTrophiesResponse } from "../../models";
import { TROPHY_BASE_URL } from "../TROPHY_BASE_URL";
import { getTitleTrophies } from "./getTitleTrophies";

const server = setupServer();

describe("Function: getTrophiesForTitle", () => {
describe("Function: getTitleTrophies", () => {
// MSW Setup
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

it("is defined #sanity", () => {
// ASSERT
expect(getTrophiesForTitle).toBeDefined();
expect(getTitleTrophies).toBeDefined();
});

it("retrieves trophies for a given title", async () => {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe("Function: getTrophiesForTitle", () => {
);

// ACT
const response = await getTrophiesForTitle(
const response = await getTitleTrophies(
mockAuthorization,
mockNpCommunicationId,
mockTrophyGroupId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import urlcat from "urlcat";

import { call } from "../call";
import { call } from "../../call";
import type {
AuthorizationPayload,
CallValidHeaders,
TitleTrophiesResponse
} from "../models";
import { TROPHY_BASE_URL } from "./TROPHY_BASE_URL";
} from "../../models";
import { TROPHY_BASE_URL } from "../TROPHY_BASE_URL";

interface GetTrophiesForTitleOptions {
interface GetTitleTrophiesOptions {
/**
* Not required unless the platform is PS3, PS4, or PS Vita.
* If one of these platforms, the value __must__ be `"trophy"`.
Expand All @@ -32,7 +32,7 @@ interface GetTrophiesForTitleOptions {
}

/**
* A request to this URL will retrieve the individual trophy detail of a
* A call to this function will retrieve the individual trophy detail of a
* single - or all - trophy groups for a title. A title can have multiple
* groups of trophies (a `default` group which all titles have, and additional
* groups named `"001"` incrementing for each additional group). To retrieve
Expand All @@ -50,11 +50,11 @@ interface GetTrophiesForTitleOptions {
* @param options.offset Return trophy data from this result onwards.
* @param options.headerOverrides Override the headers in the request to the PSN API, such as to change the language.
*/
export const getTrophiesForTitle = async (
export const getTitleTrophies = async (
authorization: AuthorizationPayload,
npCommunicationId: string,
trophyGroupId: string,
options?: Partial<GetTrophiesForTitleOptions>
options?: Partial<GetTitleTrophiesOptions>
): Promise<TitleTrophiesResponse> => {
const url = buildRequestUrl(npCommunicationId, trophyGroupId, options);

Expand All @@ -67,7 +67,7 @@ export const getTrophiesForTitle = async (
const buildRequestUrl = (
npCommunicationId: string,
trophyGroupId: string,
options: Partial<GetTrophiesForTitleOptions> = {}
options: Partial<GetTitleTrophiesOptions> = {}
) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- This is an intentional pick.
const { headerOverrides, ...pickedOptions } = options;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { setupServer } from "msw/node";
import type {
AuthorizationPayload,
TitleTrophyGroupsResponse
} from "../models";
import { generateTrophyCounts } from "../test/generators";
} from "../../models";
import { generateTrophyCounts } from "../../test/generators";
import { TROPHY_BASE_URL } from "../TROPHY_BASE_URL";
import { getTitleTrophyGroups } from "./getTitleTrophyGroups";
import { TROPHY_BASE_URL } from "./TROPHY_BASE_URL";

const server = setupServer();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import urlcat from "urlcat";

import { call } from "../call";
import { call } from "../../call";
import type {
AuthorizationPayload,
CallValidHeaders,
TitleTrophyGroupsResponse
} from "../models";
import { TROPHY_BASE_URL } from "./TROPHY_BASE_URL";
} from "../../models";
import { TROPHY_BASE_URL } from "../TROPHY_BASE_URL";

interface GetTitleTrophyGroupsOptions {
/**
Expand Down
2 changes: 2 additions & 0 deletions src/trophy/title/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./getTitleTrophies";
export * from "./getTitleTrophyGroups";
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# getSummarizedTrophiesByTrophyGroup
# getUserSummarizedTrophiesByTrophyGroup

```ts
/**
* A request to this URL will retrieve a summary of the trophies earned for
* A call to this function will retrieve a summary of the trophies earned for
* a user broken down by trophy group within a title. A title can have
* multiple groups of trophies (a `"default"` group which all titles have,
* and additional groups beginning with the name `"001"` and incrementing for
Expand Down Expand Up @@ -30,16 +30,16 @@
* @param options.npServiceName `"trophy"` for PS3, PS4, or PS Vita platforms. `"trophy2"` for the PS5 platform.
* @param options.headerOverrides Override the headers in the request to the PSN API, such as to change the language.
*/
export const getSummarizedTrophiesByTrophyGroup = async (
export const getUserSummarizedTrophiesByTrophyGroup = async (
authorization: AuthorizationPayload,
accountId: string,
npCommunicationId: string,
options?: Partial<GetSummarizedTrophiesByTrophyGroupOptions>
): Promise<SummarizedTrophiesByTrophyGroupResponse> => { ... }
options?: Partial<GetUserSummarizedTrophiesByTrophyGroupOptions>
): Promise<UserSummarizedTrophiesByTrophyGroupResponse> => { ... }
```

```ts
interface SummarizedTrophiesByTrophyGroupResponse {
interface UserSummarizedTrophiesByTrophyGroupResponse {
/** The current version of the trophy set. Some trophy sets receive updates. */
trophySetVersion: string;

Expand Down Expand Up @@ -68,7 +68,7 @@ interface SummarizedTrophiesByTrophyGroupResponse {
// Usage example

// Returns a summary of your trophies earned for Astro's Playroom (NPWR20188_00).
const response = await getSummarizedTrophiesByTrophyGroup(
const response = await getUserSummarizedTrophiesByTrophyGroup(
authorization,
"me",
"NPWR20188_00",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { setupServer } from "msw/node";

import type {
AuthorizationPayload,
SummarizedTrophiesByTrophyGroupResponse
} from "../models";
import { generateTrophyCounts } from "../test/generators";
import { getSummarizedTrophiesByTrophyGroup } from "./getSummarizedTrophiesByTrophyGroup";
import { TROPHY_BASE_URL } from "./TROPHY_BASE_URL";
UserSummarizedTrophiesByTrophyGroupResponse
} from "../../models";
import { generateTrophyCounts } from "../../test/generators";
import { TROPHY_BASE_URL } from "../TROPHY_BASE_URL";
import { getUserSummarizedTrophiesByTrophyGroup } from "./getUserSummarizedTrophiesByTrophyGroup";

const server = setupServer();

describe("Function: getSummarizedTrophiesByTrophyGroup", () => {
describe("Function: getUserSummarizedTrophiesByTrophyGroup", () => {
// MSW Setup
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

it("is defined #sanity", () => {
// ASSERT
expect(getSummarizedTrophiesByTrophyGroup).toBeDefined();
expect(getUserSummarizedTrophiesByTrophyGroup).toBeDefined();
});

it("retrieves a summarized count of trophy earnings for a given user", async () => {
Expand All @@ -31,7 +31,7 @@ describe("Function: getSummarizedTrophiesByTrophyGroup", () => {
const mockAccountId = "mockAccountId";
const mockNpCommunicationId = "mockNpCommunicationId";

const mockResponse: SummarizedTrophiesByTrophyGroupResponse = {
const mockResponse: UserSummarizedTrophiesByTrophyGroupResponse = {
trophySetVersion: "1.00",
hiddenFlag: false,
progress: 80,
Expand All @@ -50,7 +50,7 @@ describe("Function: getSummarizedTrophiesByTrophyGroup", () => {
);

// ACT
const response = await getSummarizedTrophiesByTrophyGroup(
const response = await getUserSummarizedTrophiesByTrophyGroup(
mockAuthorization,
mockAccountId,
mockNpCommunicationId
Expand Down
Loading

0 comments on commit e913810

Please sign in to comment.