Skip to content

Commit

Permalink
Merge pull request #9 from XboxReplay/allow_xuid
Browse files Browse the repository at this point in the history
Allow XUID for each method
  • Loading branch information
Alexis-Bize authored Apr 22, 2020
2 parents 82b6459 + 233c0d2 commit d282e7d
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 114 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The fastest way to generate a valid authorization is to use our [XboxLive-Auth](

```javascript
getPlayerXUID(
gamertag: string;
gamertagOrXUID: string;
authorization: {
userHash: string;
XSTSToken: string;
Expand All @@ -63,7 +63,7 @@ getPlayerXUID(

```javascript
getPlayerSettings(
gamertag: string;
gamertagOrXUID: string;
authorization: {
userHash: string;
XSTSToken: string;
Expand Down Expand Up @@ -112,7 +112,7 @@ getPlayerSettings(

```javascript
getPlayerScreenshots(
gamertag: string; // Or a valid XUID
gamertagOrXUID: string;
authorization: {
userHash: string;
XSTSToken: string;
Expand Down Expand Up @@ -171,7 +171,7 @@ getPlayerScreenshots(

```javascript
getPlayerScreenshotsFromActivityHistory(
gamertag: string; // Or a valid XUID
gamertagOrXUID: string;
authorization: {
userHash: string;
XSTSToken: string;
Expand Down Expand Up @@ -276,7 +276,7 @@ getPlayerScreenshotsFromActivityHistory(

```javascript
getPlayerGameClips(
gamertag: string, // Or a valid XUID
gamertagOrXUID: string;
authorization: {
userHash: string,
XSTSToken: string
Expand Down Expand Up @@ -338,7 +338,7 @@ getPlayerGameClips(

```javascript
getPlayerGameClipsFromActivityHistory(
gamertag: string; // Or a valid XUID
gamertagOrXUID: string;
authorization: {
userHash: string;
XSTSToken: string;
Expand Down Expand Up @@ -448,7 +448,7 @@ getPlayerGameClipsFromActivityHistory(

```javascript
getPlayerActivityHistory(
gamertag: string;
gamertagOrXUID: string;
authorization: {
userHash: string;
XSTSToken: string;
Expand Down Expand Up @@ -476,9 +476,8 @@ getPlayerActivityHistory(
```javascript
call(
config: {
uri: string;
url: string;
method: GET | PUT | POST | PATCH | DELETE,
params: any // querystring
... // Please refer to https://github.com/axios/axios#request-config for further information
};
authorization: {
Expand Down
226 changes: 148 additions & 78 deletions __tests__/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,119 +11,189 @@ const {
getPlayerScreenshotsFromActivityHistory
} = require('../src');

const successCase_getPlayerXUID = () =>
getPlayerXUID('Major Nelson', { XSTSToken, userHash })
.then(response => {
const match = '2584878536129841';
const successCase_getPlayerXUID = () => {
const onResponses = responses =>
new Promise((resolve, reject) => {
for (const response of responses) {
const match = '2584878536129841';

if (match !== response) {
throw new Error('successCase_getPlayerXUID - FAILED');
if (match !== response) {
return reject(
new Error('successCase_getPlayerXUID - FAILED')
);
} else return resolve();
}
})
});

return Promise.all([
getPlayerXUID('Major Nelson', { XSTSToken, userHash }),
getPlayerXUID('2584878536129841', { XSTSToken, userHash })
])
.then(onResponses)
.catch(err => {
console.error(err);
process.exit(1);
});
};

const successCase_getPlayerSettings = () =>
getPlayerSettings('Major Nelson', { XSTSToken, userHash }, [
'Gamertag',
'ModernGamertag',
'UniqueModernGamertag',
'ModernGamertagSuffix'
])
.then(response => {
const compare = obj => {
const a = obj.id.toLowerCase();
const b = obj.id.toLowerCase();

if (a > b) return 1;
else if (a < b) return -1;
else return 0;
};

const match = [
{ id: 'Gamertag', value: 'Major Nelson' },
{ id: 'ModernGamertag', value: 'Major Nelson' },
{ id: 'UniqueModernGamertag', value: 'Major Nelson' },
{ id: 'ModernGamertagSuffix', value: '' }
];

const isEqual =
JSON.stringify(match.sort(compare)) ===
JSON.stringify(response.sort(compare));

if (isEqual === false) {
throw new Error('successCase_getPlayerSettings - FAILED');
const successCase_getPlayerSettings = () => {
const onResponses = responses =>
new Promise((resolve, reject) => {
for (const response of responses) {
const compare = obj => {
const a = obj.id.toLowerCase();
const b = obj.id.toLowerCase();

if (a > b) return 1;
else if (a < b) return -1;
else return 0;
};

const match = [
{ id: 'Gamertag', value: 'Major Nelson' },
{ id: 'ModernGamertag', value: 'Major Nelson' },
{ id: 'UniqueModernGamertag', value: 'Major Nelson' },
{ id: 'ModernGamertagSuffix', value: '' }
];

const isEqual =
JSON.stringify(match.sort(compare)) ===
JSON.stringify(response.sort(compare));

if (isEqual === false) {
return reject(
new Error('successCase_getPlayerSettings - FAILED')
);
} else return resolve();
}
})
});

return Promise.all([
getPlayerSettings('Major Nelson', { XSTSToken, userHash }, [
'Gamertag',
'ModernGamertag',
'UniqueModernGamertag',
'ModernGamertagSuffix'
]),
getPlayerSettings('2584878536129841', { XSTSToken, userHash }, [
'Gamertag',
'ModernGamertag',
'UniqueModernGamertag',
'ModernGamertagSuffix'
])
])
.then(onResponses)
.catch(err => {
console.error(err);
process.exit(1);
});
};

const successCase_getPlayerActivityHistory = () => {
const onResponses = responses =>
new Promise((resolve, reject) => {
for (const response of responses) {
const match = {
numItems: 0,
activityItems: [],
pollingToken: '0',
pollingIntervalSeconds: null,
contToken: '0'
};

const successCase_getPlayerActivityHistory = () =>
getPlayerActivityHistory(
'Major Nelson',
{ XSTSToken, userHash },
{ numItems: 0 }
)
.then(response => {
const match = {
numItems: 0,
activityItems: [],
pollingToken: '0',
pollingIntervalSeconds: null,
contToken: '0'
};

if (JSON.stringify(match) !== JSON.stringify(response)) {
throw new Error(
'successCase_getPlayerActivityHistory - FAILED'
);
if (JSON.stringify(match) !== JSON.stringify(response)) {
return reject(
new Error(
'successCase_getPlayerActivityHistory - FAILED'
)
);
} else return resolve();
}
})
});

return Promise.all([
getPlayerActivityHistory(
'Major Nelson',
{ XSTSToken, userHash },
{ numItems: 0 }
),
getPlayerActivityHistory(
'2584878536129841',
{ XSTSToken, userHash },
{ numItems: 0 }
)
])
.then(onResponses)
.catch(err => {
console.error(err);
process.exit(1);
});
};

const successCase_getPlayerScreenshots = () =>
getPlayerScreenshots(
'Major Nelson',
{ XSTSToken, userHash },
{ maxItems: 1 }
).catch(err => {
Promise.all([
getPlayerScreenshots(
'Major Nelson',
{ XSTSToken, userHash },
{ maxItems: 1 }
),
getPlayerScreenshots(
'2584878536129841',
{ XSTSToken, userHash },
{ maxItems: 1 }
)
]).catch(err => {
console.error(err);
process.exit(1);
});

const successCase_getPlayerGameClips = () =>
getPlayerGameClips(
'Major Nelson',
{ XSTSToken, userHash },
{ maxItems: 1 }
).catch(err => {
Promise.all([
getPlayerGameClips(
'Major Nelson',
{ XSTSToken, userHash },
{ maxItems: 1 }
),
getPlayerGameClips(
'2584878536129841',
{ XSTSToken, userHash },
{ maxItems: 1 }
)
]).catch(err => {
console.error(err);
process.exit(1);
});

const successCase_getPlayerScreenshotsFromActivityHistory = () =>
getPlayerScreenshotsFromActivityHistory(
'Major Nelson',
{ XSTSToken, userHash },
{ numItems: 1 }
).catch(err => {
Promise.all([
getPlayerScreenshotsFromActivityHistory(
'Major Nelson',
{ XSTSToken, userHash },
{ numItems: 1 }
),
getPlayerScreenshotsFromActivityHistory(
'2584878536129841',
{ XSTSToken, userHash },
{ numItems: 1 }
)
]).catch(err => {
console.error(err);
process.exit(1);
});

const successCase_getPlayerGameClipsFromActivityHistory = () =>
getPlayerGameClipsFromActivityHistory(
'Major Nelson',
{ XSTSToken, userHash },
{ numItems: 1 }
).catch(err => {
Promise.all([
getPlayerGameClipsFromActivityHistory(
'Major Nelson',
{ XSTSToken, userHash },
{ numItems: 1 }
),
getPlayerGameClipsFromActivityHistory(
'2584878536129841',
{ XSTSToken, userHash },
{ numItems: 1 }
)
]).catch(err => {
console.error(err);
process.exit(1);
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@xboxreplay/xboxlive-api",
"description": "Simple Xbox Live API wrapper.",
"version": "3.2.0",
"version": "3.3.0",
"keywords": [
"xboxreplay",
"xboxlive",
Expand Down
Loading

0 comments on commit d282e7d

Please sign in to comment.