|
2 | 2 |
|
3 | 3 | A JavaScript library for interacting with IGDB - a database of video game data. This implementation utilizes the Apicalypse module provided by IGDB to assist with request building. |
4 | 4 |
|
5 | | -## Testing Setup |
| 5 | +## Usage |
6 | 6 |
|
7 | | -You can test the library out-of-the-box with some simple setup. |
| 7 | +First you will need to acquire credentials from the Twitch API in order to call IGDB. Once you have a valid API token, you can call IGDB for data. |
8 | 8 |
|
9 | | -1. Install the latest stable versions of Node and NPM. |
10 | | -2. Clone/Download the project. |
11 | | -3. From the root directory of the library, run `npm install`. |
12 | | -4. Store client credentials (details below). |
13 | | -5. From the project directory, run `node app.js`. |
14 | | -6. Observe output data. |
| 9 | +1. Instantiate an instance of IGDB_Helper. |
| 10 | +2. Call `createRequest(CLIENT_ID, API_TOKEN)` with your appropriate credentials for accessing the API |
| 11 | +3. Chain any desired filters and options for that request. |
| 12 | +4. Call `.request(URL)` with your desired API endpoint. |
| 13 | +5. Handle the Promise as you see fit and observe the results. |
15 | 14 |
|
16 | | -## Client Credentials |
| 15 | +### Examples |
17 | 16 |
|
18 | | -You will need to create a file for storing your client credentials. Typically these secrets would be handled through your server environment, but for basic testing you can create this secrets file to immediately test the library. |
| 17 | +Get an API token from Twitch and prepare to build an IGDB request. |
19 | 18 |
|
20 | | -Reminder: DON'T COMMIT SECRETS TO VERSION CONTROL! |
| 19 | +```JavaScript |
| 20 | +// Get an OAuth Access token from Twitch |
| 21 | +const twitchApi = new TwitchApi(); |
| 22 | +const apiToken = twitchApi.requestOauthToken(CLIENT_ID, CLIENT_SECRET); // Store these in your environment! |
21 | 23 |
|
22 | | -### Twitch Account for Authentication |
| 24 | +// Instantiate our helper and create a builder request |
| 25 | +const igdb = new IGDB_Helper(); |
| 26 | +const igdbRequest = igdb.createRequest(CLIENT_ID, apiToken); |
| 27 | +``` |
23 | 28 |
|
24 | | -IGDB is owned and operated by Twitch.tv. In order to authenticate with the api, you will need an active Twitch account and register a developer application with it to acquire a Client ID and Client Secret. See IGDB's documentation here for details: [IGDB Account Creation](https://api-docs.igdb.com/#account-creation) |
| 29 | +Get 5 genres and sort them by when they were last updated. |
25 | 30 |
|
26 | | -### Create Secrets File |
| 31 | +```JavaScript |
| 32 | +igdbRequest |
| 33 | + .fields("name", "updated_at") |
| 34 | + .limit(5); |
27 | 35 |
|
28 | | -1. Create a `secrets.json` file at the project root. |
29 | | -2. Add two fields called `clientId` and `clientSecret`. |
30 | | -3. Set those values to their respective values from your Twitch Developer App. |
| 36 | +const responseData = igdbRequest.request("/genres") |
| 37 | + .then( |
| 38 | + /* Handle promise here as desired */ |
| 39 | + ); |
| 40 | +``` |
0 commit comments