Skip to content

Instantly share code, notes, and snippets.

@jonajosejg
Created December 6, 2024 07:54
Show Gist options
  • Save jonajosejg/11305f2fa1e7cfa7d462235765161191 to your computer and use it in GitHub Desktop.
Save jonajosejg/11305f2fa1e7cfa7d462235765161191 to your computer and use it in GitHub Desktop.
/**
* api.js - client for interracting with the steam client
* https://github.com/jonajosejg/steamclient
* Copyright (C) 2024, Jonathan Gonzales (MIT License)
*/
'use strict';
const assert = require('bsert');
const {Client} = require('bcurl');
/**
* API
* @alias module:client.SteamClient
* @extends {bcurl.Client}
*/
class API extends Client {
/**
* Creates a client that interracts with the steam client
* @constructor
* @param {Object} options
*/
constructor(options) {
super();
this.options = new APIOptions(options);
this.host = this.options.host;
this.headers = this.options.headers;
}
/**
* Returns the current QueryTime made via the TwoFactor Endpoint
* @returns {Promise}
*/
async getCurrentTime() {
return this.post('/ITwoFactorService/QueryTime/V1');
}
/**
* Retrieves the current WebAPI's interfaces servertime
* @returns {Promise}
*/
async getServerInfo() {
return this.get('ISteamWebAPIUtil/GetServerInfo/v1');
}
/**
* Returns the list of all the API Clients available methods
* and interfaces available on the steam client
* @returns {Promise}
*/
async getSupportedAPIList() {
return this.get('ISteamWebAPIUtil/GetSupportedAPIList/v0001/');
}
async getWorldStatus() {
return this.get('ITFSystem_440/GetWorldStatus/v0001');
}
}
/**
* APIOptions
* @alias module:client.APIOptions
*/
class APIOptions {
/**
* Creates the options, settings for the steam client.
* @constructor
* @param {Object} options
*/
constructor(options) {
this.host = 'api.steampowered.com';
this.headers = {'Content-Type': 'application/json'};
if (options)
this.fromOptions(options);
}
/**
* Inject properties from object.
* @private
* @param {Object} options
* @returns {APIOptions}
*/
fromOptions(options) {
assert(options);
this.host = options.host;
this.headers = options.headers;
if (options.host != null) {
assert(typeof options.host === 'string');
this.host = options.host;
}
return this;
}
/**
* Instantiate http options from object.
* @param {Object} options
* @returns {APIOptions}
*/
static fromOptions(options) {
return new APIOptions().fromOptions(options);
}
}
module.exports = API;
@jonajosejg
Copy link
Author

just an sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment