Giter Site home page Giter Site logo

paton7 / type-steamapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tekkenthuuug/type-steamapi

0.0 1.0 0.0 84 KB

Steam API wrapper with typescript support

Home Page: https://www.npmjs.com/package/type-steamapi

License: MIT License

TypeScript 100.00%

type-steamapi's Introduction

Typescript Steam API

GitHub npm

Installation

npm install type-steamapi

or if you are using yarn

yarn add type-steamapi

Typescript

If you are using typescript, you don't need to install any type definitions, since this package is created with typescript

Usage

API key

Once installed, you would need to get Steam API key from Steam Developer Platform

Creating an instance

After receiving an API key, you would need to create an instance of SteamAPI class, imported as a default from package.

WARNING: You should never pass your API key directly as a string! Use environmental variables instead!

import SteamAPI from 'type-steamapi';

const steam = new SteamAPI({
    apiKey: 'YOUR_API_KEY',
    cache: {
      enabled:  true,
      expiresIn:  1000  *  60  *  5  // 5 min
    }
});

By default cache is enabled and expires in 5 minutes. However, if you want to overwrite this behaviour, you can add cache property to configuration object.

Examples

Now you can call methods on SteamAPI instance. Lets try a few things.

Fetching user ID

const steamid = await steam.resolve('https://steamcommunity.com/id/tekkenthuuug/');

console.log(steamid);

// Output: 76561198129961822

Fetching user owned games

const  userOwnedGames  =  await steam.getUserOwnedGames(steamid);

console.log(userOwnedGames);

// Output:
// [OwnedGame {
//    name: 'Broken Dreams',
//    appId: 444480,
//    playtimeTotal: 222,
//    playtime2weeks: 0,
//    imgIconUrl: 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/444480/ab25220f8ae0432881195c8532776e634922bb7f.jpg',
//    imgLogoUrl: 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/444480/fa699b3f546806db99c4f8f9b5078224ca606893.jpg'
// }, ...]

Caching

When enabling cache, responses for getAppDetails and resolve methods would be cached. If there would be another request when key found in cache and haven't expired yet, response would be returned from cache.

Types

All interfaces, types, and classes could be accessed.

Type GraphQL

Full type-graphql support would be added some day. Currently it is working only for some classes.

import  { OwnedGame }  from  'type-steamapi'

type-steamapi's People

Contributors

tekkenthuuug avatar paton7 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.