Skip to content

Commit

Permalink
feat: add getProfileFromAccountId() function
Browse files Browse the repository at this point in the history
Added missing documentation and an e2e test
  • Loading branch information
Travis Roy authored and wescopeland committed Feb 19, 2022
1 parent 4ed914f commit ac26e73
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Click the function names to open their complete docs on the docs site.
### Users

- [`getProfileFromUserName()`](https://psn-api.achievements.app/api-docs/users#getprofilefromusername) - Get a user's legacy profile from the username. Often used to check for legacy presence.
- [`getProfileFromAccountId()`](https://psn-api.achievements.app/api-docs/users#getprofilefromAccountId) - Get a user's profile from the `accountId`.
- [`getUserFriendsAccountIds()`](https://psn-api.achievements.app/api-docs/users#getuserfriendsaccountids) - Get a list of `accountId` values present on a target account's friends list.

### Trophies
Expand Down
24 changes: 24 additions & 0 deletions e2e/getProfileFromAccountId.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getProfileFromAccountId } from "../src";
import { getWorkingAccessToken } from "./utils/getWorkingAccessToken";

describe("E2E Health Check: getProfileFromAccountId", () => {
let authorization = { accessToken: "" };

beforeAll(async () => {
authorization = await getWorkingAccessToken();
});

it("can load a profile from a username", async () => {
// ACT
const response = await getProfileFromAccountId(
authorization,
"962157895908076652"
);

// ASSERT
const profile = response;

expect(profile).toBeDefined();
expect(profile.onlineId).toEqual("xelnia");
});
});
4 changes: 2 additions & 2 deletions src/user/getProfileFromAccountId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { USER_BASE_URL } from "./USER_BASE_URL";
type GetProfileFromAccountIdOptions = Pick<AllCallOptions, "headerOverrides">;

/**
* A call to this function will retrieve the profile of the accountId being requested.
* If the account profile cannot be found (either due to non-existence or privacy settings),
* A call to this function will retrieve some profile information of the accountId being requested.
* If the account's profile cannot be found (either due to non-existence or privacy settings),
* an error will be thrown.
*
* @param authorization An object containing your access token, typically retrieved with `exchangeCodeForAccessToken()`.
Expand Down
45 changes: 45 additions & 0 deletions website/docs/api-docs/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,51 @@ The following properties are contained within a `profile` object that is returne

---

## getProfileFromAccountId

A call to this function will retrieve some of the profile information of the account ID being requested. If the account's profile cannot be found (either due to non-existence or privacy settings), an error will be thrown.

### Examples

#### Look up a user

```ts
import { getProfileFromAccountId } from "psn-api";

const response = await getProfileFromAccountId(
authorization,
"962157895908076652"
);
```

### Returns

The following properties are contained within a `profile` object that is returned.

| Name | Type | Description |
| :--------------------- | :-------------------------------------- | :----------------------------------------------------------------- |
| `onlineId` | `string` | The account's online username. |
| `aboutMe` | `string` | |
| `avatars` | `Array<{ size: string; url: string; }>` | |
| `languages` | `string[]` | |
| `isPlus` | `boolean` | Whether or not the account is a PlayStation Plus subscriber. |
| `isOfficiallyVerified` | `boolean` | |
| `isMe` | `boolean` | Whether or not the profile is the one linked to the current Npsso. |

### Parameters

| Name | Type | Description |
| :-------------- | :-------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------- |
| `authorization` | [`AuthorizationPayload`](/api-docs/data-models/authorization-payload) | An object that must contain an `accessToken`. See [this page](/authentication/authenticating-manually) for how to get one. |
| `accountId` | `string` | The `accountId` for the user you wish to retrieve a profile for. |
| `options` | `GetProfileFromAccountIdOptions` | Can be used to specify `headerOverrides`. |

### Source

[user/getProfileFromAccountId.ts](https://github.com/achievements-app/psn-api/blob/main/src/user/getProfileFromAccountId.ts)

---

## getUserFriendsAccountIds

A call to this function will retrieve the list of friended `accountId` values associated with the given `accountId` parameter. If the friends list cannot be retrieved (either due to the given `accountId` not existing or due to the user's privacy settings), an error will be thrown.
Expand Down

0 comments on commit ac26e73

Please sign in to comment.