1.0.0 • Published 6 years ago

speedrundotcom v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

speedrundotcom

Speedrun.com API warpper for browser and node.js. As of right now, this module only allows read access to the API.

Installing

Using yarn:

yarm add speedrundotcom

Using bower:

bower install speedrundotcom

Using npm:

npm install speedrundotcom

Using cdn:

<script src="https://unpkg.com/speedrundotcom" />

Examples

Get all the endpoints

const speedrundotcom = require('speedrundotcom')
const api = speedrundotcom()

api.games.get('darksouls').then(console.log)

Pick whatever endpoints you need

const speedrundotcom = require('speedrundotcom')
const { games, users } = speedrundotcom()

games.get('darksouls').then(console.log)
users.get('CapitaineToinon').then(console.log)

Send custom params to the request

const speedrundotcom = require('speedrundotcom')
const { users, series } = speedrundotcom()

// Search for Pac
users.getAll({
  lookup: 'Pac'
}).then(console.log)

// Get the souls games and their categories
series.getGames('souls', {
  embed: 'categories'
}).then(console.log)

Modular design

If you only need some of the endpoints, you can do this:

const createClient = require('speedrundotcom/src/client')
const { createGamesEndpoint } = require('speedrundotcom/src/endpoints')

const client = createClient()
const games = createGamesEndpoint(client)

games.get('darksouls').then(console.log)

Custom HTTP client

You can refine your own client to avoid having to use axios. Each endpoints simply expects a client with a get methods having a url and params arguments. Here is for example how you could replace axios by fetch:

const { createUsersEndpoint } = require('speedrundotcom/src/endpoints')

/**
 * Custom HTTP client
 */
function createClient() {
  function get(url, params = {}) {
    const paramsUrl = Object.keys(params).map(key => {
      return `${key}=${params[key]}`
    }).join('&')

    return fetch(`https://www.speedrun.com/api/v1${url}?${paramsUrl}`)
      .then(resp => resp.json())
  }

  return {
    get,
  }
}

const client = createClient()
const users = createUsersEndpoint(client)

users.getAll({
  lookup: "Pac"
})
  .then(resp => resp.data)
  .then(users => console.log({ users }))
1.0.1

6 years ago

1.0.0

6 years ago