Skip to content

Instantly share code, notes, and snippets.

@jjgg22zh
Created December 6, 2024 07:54
Show Gist options
  • Select an option

  • Save jjgg22zh/11305f2fa1e7cfa7d462235765161191 to your computer and use it in GitHub Desktop.

Select an option

Save jjgg22zh/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;
@jjgg22zh
Copy link
Copy Markdown
Author

jjgg22zh commented Dec 6, 2024

just an sample

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