achievements-app / psn-api

A JavaScript library that lets you get trophy, user, and game data from the PlayStation Network.
https://psn-api.achievements.app
MIT License
263 stars 31 forks source link

feat: add function to fetch user playtime #131

Closed TheYuriG closed 1 year ago

TheYuriG commented 1 year ago

This is my first time making a module PR and a typescript PR so you can bet that I had a lot of fun figuring out why stuff didn't work.

const {
    exchangeNpssoForCode,
    exchangeCodeForAccessToken,
    makeUniversalSearch,
    getUserPlayedTime,
} = require('psn-api');
const fs = require('fs');

async function thisWillTestPlaytime() {
    const access = await exchangeNpssoForCode(
        'PUT-YOUR-NPSSO-CODE-HERE'
    );
    const auth = await exchangeCodeForAccessToken(access);
    const userList = await makeUniversalSearch(auth, 'PUT-THE-PSNID-YOU-WANT-TO-TEST-HERE', 'SocialAllAccounts');
    const userId = userList.domainResponses[0].results[0].socialMetadata.accountId;
    const timePlayed = await getUserPlayedTime(auth, userId);
    fs.writeFileSync('./timePlayed.json', JSON.stringify(timePlayed));
}

thisWillTestPlaytime();

Expect best practices not being followed and edits needing to be made, I punched way above my weight with this PR. Also, I didn't create a test, but maybe the repro code above will ease that process.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
psn-api ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 26, 2023 at 1:40PM (UTC)
wescopeland commented 1 year ago

I have adjusted the title to enforce a minor release. Releases are automated and entirely derived from commit messages. Check https://github.com/semantic-release/semantic-release and https://commitizen-tools.github.io/commitizen/tutorials/writing_commits/

wescopeland commented 1 year ago

Hi! This PR has exceeded 30 days of inactivity. I will be closing it as a courtesy. Please feel free to re-open it at any time you would like to revisit this work.