/// <summary> /// Fetches the Tf2 Item schema. /// </summary> /// <param name="apiKey">The API key.</param> /// <returns>A deserialized instance of the Item Schema.</returns> /// <remarks> /// The schema will be cached for future use if it is updated. /// </remarks> public static Schema Init(string apiKey, string schemaLang = null) { if (_schema != null) { return(_schema); } var url = SchemaApiUrlBase + apiKey; if (schemaLang != null) { url += "&language=" + schemaLang; } // Get Schema URL Regex regex = new Regex("https.*txt"); DateTime schemaLastModified; using (HttpWebResponse response = new SteamWeb().Request(url, "GET")) { schemaLastModified = response.LastModified; string result; using (var reader = new StreamReader(response.GetResponseStream())) { result = reader.ReadToEnd(); } url = regex.Match(result).Value; } _schema = GetSchema(url, schemaLastModified); return(_schema); }
/// <summary> /// Fetches the inventory for the given Steam ID using the Steam API. /// </summary> /// <returns>The give users inventory.</returns> /// <param name='steamId'>Steam identifier.</param> /// <param name='apiKey'>The needed Steam API key.</param> /// <param name="steamWeb">The SteamWeb instance for this Bot</param> public static Inventory FetchInventory(ulong steamId, string apiKey, SteamWeb steamWeb) { int attempts = 1; InventoryResponse result = null; while ((result == null || result.result.items == null) && attempts <= 3) { var url = "https://api.steampowered.com/IEconItems_570/GetPlayerItems/v0001/?key=" + apiKey + "&steamid=" + steamId; string response = steamWeb.Fetch(url, "GET", null, false); result = JsonConvert.DeserializeObject <InventoryResponse>(response); attempts++; } return(new Inventory(result.result)); }
/// <summary> /// Gets the inventory for the given Steam ID using the Steam Community website. /// </summary> /// <returns>The inventory for the given user. </returns> /// <param name='steamid'>The Steam identifier. </param> /// <param name="steamWeb">The SteamWeb instance for this Bot</param> public static dynamic GetInventory(SteamID steamid, SteamWeb steamWeb) { string url = String.Format( "http://steamcommunity.com/profiles/{0}/inventory/json/570/2/?trading=1", steamid.ConvertToUInt64() ); try { string response = steamWeb.Fetch(url, "GET"); return(JsonConvert.DeserializeObject(response)); } catch (Exception) { return(JsonConvert.DeserializeObject("{\"success\":\"false\"}")); } }
/// <summary> /// Initializes a new instance of the <see cref="SteamTrade.TradeManager"/> class. /// </summary> /// <param name='apiKey'> /// The Steam Web API key. Cannot be null. /// </param> /// <param name="steamWeb"> /// The SteamWeb instances for this bot /// </param> public TradeManager(string apiKey, SteamWeb steamWeb) { if (apiKey == null) { throw new ArgumentNullException(nameof(apiKey)); } if (steamWeb == null) { throw new ArgumentNullException(nameof(steamWeb)); } SetTradeTimeLimits(MaxTradeTimeDefault, MaxGapTimeDefault, TradePollingIntervalDefault); _apiKey = apiKey; _steamWeb = steamWeb; }
// Gets the schema from the web or from the cached file. private static Schema GetSchema(string url, DateTime schemaLastModified) { bool mustUpdateCache = !File.Exists(Cachefile) || schemaLastModified > File.GetCreationTime(Cachefile); var items = ParseLocalSchema(); List <string> lines = new List <string>(); Dictionary <string, Item> newItems = new Dictionary <string, Item>(); if (mustUpdateCache) { using (HttpWebResponse response = new SteamWeb().Request(url, "GET")) { using (var reader = new StreamReader(response.GetResponseStream())) { while (!reader.EndOfStream) { lines.Add(reader.ReadLine()); } } } newItems = ParseWebSchema(VDFConvert.ToJson(lines.ToArray())); } if (items == null) { items = newItems; } else { foreach (var item in newItems) { if (!items.ContainsKey(item.Key)) { items[item.Key] = item.Value; } } } var schema = new Schema() { _items = items }; System.IO.Directory.CreateDirectory(Path.GetDirectoryName(Cachefile) ?? ""); File.WriteAllText(Cachefile, new JavaScriptSerializer { MaxJsonLength = 62914560 }.Serialize(schema.GetItems())); return(schema); }
private long tradeOfferID; //Used for email confirmation internal Trade(SteamID me, SteamID other, SteamWeb steamWeb, Task <Inventory> myInventoryTask, Task <Inventory> otherInventoryTask) { TradeStarted = false; OtherIsReady = false; MeIsReady = false; MySteamId = me; OtherSID = other; session = new TradeSession(other, steamWeb); this.eventList = new List <TradeEvent>(); myOfferedItemsLocalCopy = new Dictionary <int, TradeUserAssets>(); otherOfferedItems = new List <TradeUserAssets>(); myOfferedItems = new List <TradeUserAssets>(); this.otherInventoryTask = otherInventoryTask; this.myInventoryTask = myInventoryTask; }
public GenericInventory(SteamWeb steamWeb) { SteamWeb = steamWeb; }