/// <summary> /// Gets the inventory of the specifeid user. /// </summary> /// <param name="userID">An int containing the user identifier.</param> /// <returns>An ItemList containing the inventory.</returns> public ItemList GetInventory(int userID) { ItemList ReturnValue = null; try { NameValueCollection RequestData; ApiResponse <GetInventoryResponse> Result; // Build the post data RequestData = new NameValueCollection { { "uid", userID.ToString() } }; // Execute the request Result = OpSkinsWebRequest <GetInventoryResponse> .ExecuteGet(BuildUrl("/ITrade/GetUserInventory/v1/"), _AuthToken, RequestData); if (Result != null && Result.Response != null) { ReturnValue = Result.Response.Items; } else { throw new InvalidOperationException("No result data was received"); } } catch (Exception ex) { throw new InvalidOperationException("Could not get trade offers", ex); } return(ReturnValue); }
/// <summary> /// Executes a GET against the OpSkins API. /// </summary> /// <param name="url">A string containing the URL for the web request.</param> /// <param name="authToken">A string containing the OpSkins authentication token to use for the request.</param> /// <returns>An ApiResponse of T containing the result returned by the web request.</returns> internal static ApiResponse <T> ExecuteGet(string url, string authToken, NameValueCollection requestData) { string Response; ApiResponse <T> ReturnValue; Response = OpSkinsWebRequest.ExecuteGet(url, authToken, requestData); ReturnValue = ProcessResponse(Response); return(ReturnValue); }
/// <summary> /// Executes a GET against the OpSkins API. /// </summary> /// <param name="url">A string containing the URL for the web request.</param> /// <param name="authToken">A string containing the OpSkins authentication token to use for the request.</param> /// <returns>An ApiResponse of T containing the result returned by the web request.</returns> internal static ApiResponse <T> ExecuteGet(string url, string authToken) { string Response; ApiResponse <T> ReturnValue; Response = OpSkinsWebRequest.ExecuteGet(url, authToken); ReturnValue = ProcessResponse(Response); return(ReturnValue); }
/// <summary> /// Gets the specified trade offer. /// </summary> /// <param name="tradeID">An int indicating the identifier of the trade offer.</param> public TradeOffer GetTradeOffer(int tradeOfferID) { int Retries = 0; TradeOffer ReturnValue = null; while (Retries++ < 3) { try { NameValueCollection RequestData; ApiResponse <GetOfferResponse> Result; // Build the post data RequestData = new NameValueCollection { { "offer_id", tradeOfferID.ToString() } }; // Execute the request Result = OpSkinsWebRequest <GetOfferResponse> .ExecuteGet(BuildUrl("/ITrade/GetOffer/v1/"), _AuthToken, RequestData); if (Result != null && Result.Response != null) { ReturnValue = Result.Response.TradeOffer; Retries = 5; } else { throw new InvalidOperationException("No result data was received"); } } catch (Exception ex) { LogWriter.LogException(ex); } if (Retries < 5) { Thread.Sleep(5); } } return(ReturnValue); }
/// <summary> /// Gets a list of trade offers for the specified trade offer states. /// </summary> /// <param name="states">A List of TradeOfferState containing the states to get trade offers for.</param> /// <param name="state">A TradeOfferTypes indicating the types of trade offer to get.</param> public List <TradeOffer> GetTradeOffers(List <TradeOfferState> states, TradeOfferTypes tradeOfferTypes) { List <TradeOffer> ReturnValue = null; int Retries = 0; while (Retries++ < 3) { try { NameValueCollection RequestData; ApiResponse <GetOffersResponse> Result; // Build the post data RequestData = new NameValueCollection { { "twofactor_code", Authenticator.Compute2FA(_2FA) } }; if (states != null && states.Count > 0) { string StateList = string.Empty; foreach (TradeOfferState State in states) { StateList += string.Format("{0},", (int)State); } StateList = StateList.TrimEnd(new char[] { ',' }); RequestData.Add("state", StateList); } // Add the trade offer type switch (tradeOfferTypes) { case TradeOfferTypes.Received: RequestData.Add("type", "received"); break; case TradeOfferTypes.Sent: RequestData.Add("type", "sent"); break; } // Execute the request Result = OpSkinsWebRequest <GetOffersResponse> .ExecuteGet(BuildUrl("ITrade/GetOffers/v1/"), _AuthToken, RequestData); if (Result != null && Result.Response != null) { ReturnValue = Result.Response.TradeOffers; } else { throw new InvalidOperationException("No result data was received"); } } catch (Exception ex) { Console.WriteLine("Could not get trade offers: {0}", ex); } } return(ReturnValue); }
/// <summary> /// Gets all items for the specified application identifier. /// </summary> /// <param name="appID">An int indicating the application to get all items for.</param> /// <param name="pageNumber">An int indicating the current page to get items from.</param> /// <param name="perPage">An int indicating the size of each page that should be returned.</param> /// <param name="skuFilter">A List of int indicating the SKUs of items to return.</param> /// <param name="nameFilter">A string containing the name to filter items by.</param> /// <param name="showAllItems">A bool that indicates whether to return all items (some items are excluded by default).</param> /// <param name="sortOrder">An ItemSorts specifying the sort order of the items in the result set.</param> public void GetAllItems(int appID, int pageNumber = 1, int perPage = 100, List <int> skuFilter = null, string nameFilter = null, bool showAllItems = false, ItemSorts sortOrder = ItemSorts.Undefined) { ItemList ReturnValue = null; // Validate parameters if (appID < 1) { throw new ArgumentException("The specified application identifier is invalid", "appID"); } if (pageNumber < 1) { throw new ArgumentException("The specified page number is invalid", "pageNumber"); } if (perPage < 1 || perPage > 100) { throw new ArgumentException("The specified results per page is invalid", "perPage"); } try { NameValueCollection RequestData; ApiResponse <GetInventoryResponse> Result; // Build the post data RequestData = new NameValueCollection { { "app_id", appID.ToString() }, { "page", pageNumber.ToString() }, { "per_page", perPage.ToString() } }; if (skuFilter != null && skuFilter.Count > 0) { string SkuList = string.Empty; foreach (int Item in skuFilter) { SkuList += string.Format("{0},", Item); } SkuList = SkuList.Trim(','); RequestData.Add("sku", SkuList); } if (sortOrder != ItemSorts.Undefined) { RequestData.Add("sort", ((int)sortOrder).ToString()); } if (showAllItems) { RequestData.Add("no_exclusions", "1"); } if (nameFilter != null && nameFilter.Length > 0) { RequestData.Add("name", nameFilter); } GenerateAuthToken(); // Execute the request Result = OpSkinsWebRequest <GetInventoryResponse> .ExecuteGet("https://api-trade.opskins.com/IItem/GetAllItems/v1/", _AuthToken, RequestData); if (Result != null && Result.Response != null) { ReturnValue = Result.Response.Items; } else { throw new InvalidOperationException("No result data was received"); } } catch (Exception ex) { throw new InvalidOperationException("Could not get trade offers", ex); } // return ReturnValue; }