This project is read-only.

Documentation

Most methods, comments and various documentation are from the Team Fortress WebAPI documentation:

http://wiki.teamfortress.com/wiki/WebAPI

Installation

  1. Enter PM> Install-Package SteamWebAPI from the package manager console.
  2. You can also search for SteamWebAPI from the NuGet Package Manager.

Quick Start

Required Namespaces

using PortableSteam;

Optional Namespaces

using PortableSteam.Fluent;
using PortableSteam.Infrastructure;
using PortableSteam.Interfaces;

  1. Import PortableSteam
  2. Obtain your Steam Developer API Key from http://steamcommunity.com/dev/apikey
  3. Set the api key: SteamWebAPI.SetGlobalKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
  4. Begin exploring the steam web api interfaces and methods.

Usage Patterns

Most Interfaces, methods and parameters follow the same naming as the web api. All request and response methods and parameters are fully documented so feel free to explore the code through intellisense.

Configurations

You start off the request configuration by calling SteamWebAPI.

The portable steam fluent pattern follows the steam web api's method of organizing interfaces and methods.

SteamWebAPI
  -CustomRequest
  -Game
    -Dota2
    -Generic
    -Portal2
  -General
  -Other

For example if I wanted to get match history for Dota2, it would look something like this.

var r = SteamWebAPI.Game().Dota2().IDOTA2Match().GetMatchHistory().GetResponse();

Or if I wanted to resolve my steam ID using my community profile name, it would look something like this.

var r = SteamWebAPI.General().ISteamUser().ResolveVanityURL("munchies").GetResponse();

Requests

All requests must have an API key set by:

SteamWebAPI.SetGlobalKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

Web API requests have required parameters and optional parameters.

Required parameters are enforced and must be supplied through method parameters. For example,

var response = SteamWebAPI.Game().Generic()
                                 .IEconItems(GameType.TeamFortress2)
                                 .GetPlayerItems(SteamIdentity.FromSteamID(123456789))
                                 .GetResponse();

As you may have noticed, IEconItems interface requires a game type to be supplied in order for the request to be successful, thus you must supply the game type.

GetPlayerItems require a steam ID which is handled through the SteamIdentity object, which will be detailed in another section.

Optional Parameters can be accessed through the fluent syntax after the method has been called.

var response = SteamWebAPI.Game()
                          .Dota2()
                          .IDOTA2Match()
                          .GetMatchHistory()
                          .DateMax(DateTime.Now)
                          .GameMode(Dota2GameMode.CaptainsDraft)
                          .HeroID(5)
                          .Skill(Dota2Skill.Normal)
                          .TournamentGamesOnly()
                          .GetResponse();

After GetMatchHistory() was called, everything between that and GetResponse() are optional parameters.

Responses

There are 2 types of responses:

  1. A response object with its parameters de-serialized.

   Response objects are fully documented so feel free to explore the hiearchies.

   var response = SteamWebAPI.General().ISteamApps().GetAppList().GetResponse();

   foreach (var app in response.Data.Apps)
  {
     Console.WriteLine(app.AppID + ", " + app.Name);
  }

  1. A response string of a request based on user supplied format

   There are 3 different response string formats: JSON, XML and VDF (Valve Data Format).

   The default format if no format is supplied is JSON.

   var json = SteamWebAPI.General()
                        .IPlayerService()
                        .GetSteamLevel(SteamIdentity.FromSteamID(123456789))
                        .GetResponseString();

   var xml = SteamWebAPI.General()
                       .IPlayerService()
                       .GetSteamLevel(SteamIdentity.FromSteamID(123456789))
                       .GetResponseString(RequestFormat.XML);

  var vdf = SteamWebAPI.General()
                       .IPlayerService()
                       .GetSteamLevel(SteamIdentity.FromSteamID(123456789))
                       .GetResponseString(RequestFormat.VDF);

Responses also support asynchronous calls such as GetResponseAsync() and GetResponseStringAsync()

SteamIdentity

Requests or responses that require a SteamID are wrapped in the SteamIdentity class. One reason is to allow future OAuth development. Another reason is because some interfaces like Dota2 methods return a 32-bit account ID instead of the usual steam ID. To make conversion easy and seamless, the SteamIdentity class wraps both together. 

You can create a steam identity in one of 2 ways, using a SteamID or using an AccountID.

var identity = SteamIdentity.FromAccountID(123456789);

var identity = SteamIdentity.FromSteamID(123456789);

Afterwards you can use the identity object to obtain either ID

var accountid = identity.AccountID;
var steamid = identity.SteamID;

A real use example, I want to look up the player summary of a tournament player that I retrieved from the DOTA2 interface.

var response = SteamWebAPI.Game()
                          .Dota2()
                          .IDOTA2Match()
                          .GetTeamInfoByTeamID()
                          .GetResponse();

var teams = response.Data.Teams;

var playerIdentity = teams.FirstOrDefault().PlayerIdentities.FirstOrDefault();

var playerSummaries = SteamWebAPI.General()
                                 .ISteamUser()
                                 .GetPlayerSummaries(playerIdentity)
                                 .GetResponse();

playerIdentity can be used across all methods without worry about whether it requires a steamID or accountID.

Naming Patterns

  • API Interfaces are named the same way as the Web API interface names.
  • Interface methods are named the same way as the Web API method names.
  • Method parameters are named like Web API parameter names except the first letter is capitalized to follow C# code conventions.
  • Request objects are named methodnameRequest where methodname is the Web API's method name.
  • Response objects are named methodnameResponse where methodname is the Web API's method name.
  • Builder objects are named methodnameBuilder where methodname is the Web API's method name.

 

Last edited Jan 5, 2014 at 2:19 AM by helloworld65, version 14