public string ToXml()
        {
            var          data = new XmlDocument();
            XmlElement   root = data.CreateElement(RootElement);
            XmlAttribute name = data.CreateAttribute(NameAttr);

            name.Value = Name;

            XmlAttribute providerId = data.CreateAttribute(ProviderIdAttr);

            providerId.Value = ProviderId;

            XmlAttribute resultPerPage = data.CreateAttribute(ResultsAttr);

            resultPerPage.Value = ResultsPerPage.ToString(CultureInfo.InvariantCulture);

            XmlAttribute showMoreResultsLink = data.CreateAttribute(ShowMoreAttr);

            showMoreResultsLink.Value = ShowMoreResultsLink.ToString(CultureInfo.InvariantCulture);

            XmlAttribute textonlyResults = data.CreateAttribute(TextOnlyAttr);

            textonlyResults.Value = TextOnlyResults.ToString(CultureInfo.InvariantCulture);

            root.Attributes.Append(name);
            root.Attributes.Append(providerId);
            root.Attributes.Append(resultPerPage);
            root.Attributes.Append(showMoreResultsLink);
            root.Attributes.Append(textonlyResults);
            data.AppendChild(root);

            return(data.InnerXml);
        }
Exemplo n.º 2
0
        public IDictionary <string, string> ToDictionary()
        {
            var options = new Dictionary <string, string>();

            if (Status != null)
            {
                options.Add("status", Status);
            }
            if (Page.HasValue)
            {
                options.Add("page", Page.ToString());
            }
            if (ResultsPerPage.HasValue)
            {
                options.Add("per_page", ResultsPerPage.ToString());
            }
            if (LastUpdated.HasValue)
            {
                options.Add("last_updated_at", LastUpdated.Value.ToString("O"));
            }
            if (OrderNumber != null)
            {
                options.Add("order_number", OrderNumber);
            }
            return(options);
        }
Exemplo n.º 3
0
        internal static void DisplayVacancies(ResultsPerPage pageResults)
        {
            if (pageResults != null)
            {
                //_found = vacanciesData.found;
                //_page = vacanciesData.page;
                //_pages = vacanciesData.pages;
                //_perPage = vacanciesData.per_page;
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine("Page number: " + pageResults.page);
                //Console.WriteLine("Header.TotalVacancies: " + _found);
                Console.WriteLine("Header.TotalVacancies: " + pageResults.found);
                //Console.WriteLine("Header.currentPage: " + _page);
                //Console.WriteLine("Header.currentPage: " + pageResults.page);
                //Console.WriteLine("Header.pagesTotal: " + _pages);
                //Console.WriteLine("Header.itemsPerPage:" + _perPage);
                Console.WriteLine("Header.itemsPerPage:" + pageResults.per_page);
                Console.WriteLine("Header.alternate_url: " + pageResults.alternate_url);
                Console.WriteLine("Header.clusters: " + pageResults.clusters);

                Console.WriteLine("Start listing vacancies...:" + Environment.NewLine);
                foreach (ResultsPerPage.Item vacancy in pageResults.items)
                {
                    DisplayVacancyId(vacancy);
                }
                //int counter = 0;
                //foreach (SearchByTextData.Item item in vacanciesData.items)
                //{
                //   DisplayVacancyId(item);
                //   counter++;
                //}
            }
        }
Exemplo n.º 4
0
 private static void AddVacancyIdToList(ResultsPerPage resultsByPage,
                                        IList <string> vacanciesIdList)
 {
     foreach (ResultsPerPage.Item item in resultsByPage.items)
     {
         vacanciesIdList.Add(item.id);
     }
 }
Exemplo n.º 5
0
        internal static void DisplayVacanciesJson(ResultsPerPage vacanciesData)
        {
            if (vacanciesData != null)
            {
                _found   = vacanciesData.found;
                _page    = vacanciesData.page;
                _pages   = vacanciesData.pages;
                _perPage = vacanciesData.per_page;
                Console.WriteLine("List Header:");
                Console.WriteLine("Header.found: " + _found);
                Console.WriteLine("Header.currentPage: " + _page);
                Console.WriteLine("Header.pagesTotal: " + _pages);
                Console.WriteLine("Header.itemsPerPage:" + _perPage);
                Console.WriteLine("Header.alternate_url: " + vacanciesData.alternate_url);
                Console.WriteLine("Header.clusters: " + vacanciesData.clusters);

                //Console.WriteLine("vacanciesData.pages: " + vacanciesData.pages);
                //Console.WriteLine("vacanciesData.per_page: " + vacanciesData.per_page);
                Console.WriteLine("Start listing vacancies...:" + Environment.NewLine);

                int counter = 0;
                foreach (var item in vacanciesData.items)
                {
                    Console.WriteLine("Vacancy #: " + counter);

                    Console.WriteLine("item.id: " + item.id);
                    Console.WriteLine("item.name: " + item.name);
                    Console.WriteLine("item.employer: " + item.employer.id);
                    Console.WriteLine("item.employer: " + item.employer.name);
                    if (item.address != null)
                    {
                        Console.WriteLine("item.address.id: " + item.address.id); //null exception?
                        Console.WriteLine("item.address.city: " + item.address.city);
                    }

                    Console.WriteLine("item.area.id: " + item.area.id);
                    Console.WriteLine("item.area.name: " + item.area.name);
                    if (item.salary != null)
                    {
                        Console.WriteLine("item.salary.from" + item.salary.from);
                        Console.WriteLine("item.salary.from" + item.salary.to);
                        Console.WriteLine("item.salary.from" + item.salary.currency);
                    }
                    Console.WriteLine("item.type.id " + item.type.id);
                    Console.WriteLine("item.type.name: " + item.type.name);

                    Console.WriteLine("item.created_at: " + item.created_at);
                    Console.WriteLine("item.published_at: " + item.published_at);
                    Console.WriteLine("item.url: " + item.url);
                    Console.WriteLine("item.url: " + item.alternate_url);
                    Console.WriteLine("------------------------------------");
                    counter++;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Allows you to retrieve the BitSkins inventory currently on sale.
        /// This includes items you cannot buy (i.e., items listed for sale by you).
        /// </summary>
        /// <param name="app">Inventory's game id.</param>
        /// <param name="page">Page number.</param>
        /// <param name="marketHashName">Full or partial item name. (optional)</param>
        /// <param name="minPrice">Minimum price. (optional)</param>
        /// <param name="maxPrice">Maximum price. (optional)</param>
        /// <param name="sortBy">{created_at|price}. (optional)</param>
        /// <param name="sortOrder">{desc|asc}. (optional)</param>
        /// <param name="hasStickers">{-1|0|1}. For CS:GO only. (optional)</param>
        /// <param name="isStattrak">{-1|0|1}. For CS:GO only. (optional)</param>
        /// <param name="isSouvenir">{-1|0|1}. For CS:GO only. (optional)</param>
        /// <param name="resultsPerPage">Results per page. Must be either 30, or 480.</param>
        /// <param name="tradeDelayedItems">{-1|0|1}. For CS:GO only. (optional)</param>
        /// <returns>List of items on sale.</returns>
        public static List <ItemOnSale> GetInventoryOnSale(AppId.AppName app, int page, string marketHashName, double minPrice, double maxPrice,
                                                           SortBy sortBy, SortOrder sortOrder, ThreeChoices hasStickers, ThreeChoices isStattrak, ThreeChoices isSouvenir,
                                                           ResultsPerPage resultsPerPage, ThreeChoices tradeDelayedItems)
        {
            CheckParameters(page);
            string urlRequest = GetUrlRequest(app, page, marketHashName, minPrice, maxPrice, sortBy, sortOrder, hasStickers,
                                              isStattrak, isSouvenir, resultsPerPage, tradeDelayedItems);
            string            result      = Server.ServerRequest.RequestServer(urlRequest);
            List <ItemOnSale> itemsOnSale = ReadItemsOnSale(result);

            return(itemsOnSale);
        }
Exemplo n.º 7
0
        public IList <string> GetAllVacanciesByName(string searchParam, string searchfield,
                                                    string pageParam, int page, string perPageParam, int perPage)
        {
            _allVacancies = 0;
            int    currentPage = page;
            int    pages       = 0;
            string url         = GetUrl(searchParam, searchfield, pageParam, page, perPageParam, perPage);

            _vacanciesIdList = new List <string>();
            do
            {
                try
                {
                    var            contentString = ConsumeJson(url);
                    ResultsPerPage pageResults   = SerializeToObject2(contentString);

                    if (pageResults != null)
                    {
                        AddVacancyIdToList(pageResults, _vacanciesIdList);

                        Helper.DisplayVacancies(pageResults);
                        _allVacancies = pageResults.found;
                        pages         = pageResults.pages;
                    }
                    else
                    {
                        Console.WriteLine("failed to serialize page: " + currentPage);
                    }
                }
                catch (WebException wex)
                {
                    HandleWebException(wex);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                finally
                {
                    currentPage++;
                    Console.WriteLine("{0} of {1} vacancies processed: ", Helper.TotalCounter,
                                      _allVacancies);
                }
            }while (currentPage < pages);
            return(_vacanciesIdList);
        }
Exemplo n.º 8
0
        private static string GetUrlRequest(AppId.AppName app, int page, string marketHashName, double minPrice, double maxPrice,
                                            SortBy sortBy, SortOrder sortOrder, ThreeChoices hasStickers, ThreeChoices isStattrak, ThreeChoices isSouvenir,
                                            ResultsPerPage resultsPerPage, ThreeChoices tradeDelayedItems)
        {
            Server.UrlCreator urlCreator = new Server.UrlCreator($"https://bitskins.com/api/v1/get_inventory_on_sale/");
            urlCreator.AppendUrl($"&page={page}");
            urlCreator.AppendUrl($"&app_id={(int)app}");
            urlCreator.AppendUrl($"&per_page={(int)resultsPerPage}");

            if (!string.IsNullOrEmpty(marketHashName))
            {
                urlCreator.AppendUrl($"&market_hash_name={marketHashName}");
            }

            if (minPrice > 0)
            {
                urlCreator.AppendUrl($"&min_price={minPrice}");
            }

            if (maxPrice > 0)
            {
                urlCreator.AppendUrl($"&max_price={maxPrice}");
            }

            if (sortBy != SortBy.Not)
            {
                urlCreator.AppendUrl($"&sort_by={SortByToString(sortBy)}");
            }

            if (sortOrder != SortOrder.Not)
            {
                urlCreator.AppendUrl($"&order={SortOrderToString(sortOrder)}");
            }

            if (app == AppId.AppName.CounterStrikGlobalOffensive)
            {
                urlCreator.AppendUrl($"&has_stickers={(int)hasStickers}");
                urlCreator.AppendUrl($"&is_stattrak={(int)isStattrak}");
                urlCreator.AppendUrl($"&is_souvenir={(int)isSouvenir}");
                urlCreator.AppendUrl($"&show_trade_delayed_items={(int)tradeDelayedItems}");
            }

            return(urlCreator.ReadUrl());
        }
Exemplo n.º 9
0
        private ResultsPerPage SerializeToObject2(string contentString)
        {
            DataContractJsonSerializer serializer =
                new DataContractJsonSerializer(typeof(ResultsPerPage));
            ResultsPerPage vacanciesData = null;

            using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(contentString)))
            {
                try
                {
                    // deserialize the JSON object using the WeatherData type.
                    vacanciesData = (ResultsPerPage)serializer.ReadObject(ms);
                }
                catch (SerializationException ex)
                {
                    Console.WriteLine("SerializationException on: ");
                    //Todo - filter vacany id out of contentString
                }
                catch (Exception ex)
                {
                }
            }
            return(vacanciesData);
        }
Exemplo n.º 10
0
 private static void AddVacancyIdToList(ResultsPerPage resultsByPage,
     IList<string> vacanciesIdList)
 {
     foreach (ResultsPerPage.Item item in resultsByPage.items)
     {
         vacanciesIdList.Add(item.id);
     }
 }
Exemplo n.º 11
0
        private static string GetUrlRequest(AppId.AppName app, int page, List <string> names, ResultsPerPage resultsPerPage)
        {
            const string delimiter = ",";

            Server.UrlCreator urlCreator = new Server.UrlCreator($"https://bitskins.com/api/v1/get_item_history/");
            urlCreator.AppendUrl($"&page={page}");
            urlCreator.AppendUrl($"&app_id={(int)app}");
            urlCreator.AppendUrl($"&per_page={(int)resultsPerPage}");

            if (names != null && names.Count > 0)
            {
                urlCreator.AppendUrl($"&names={names.ToStringWithDelimiter(delimiter)}");
                urlCreator.AppendUrl($"&delimiter={delimiter}");
            }

            return(urlCreator.ReadUrl());
        }
Exemplo n.º 12
0
        /// <summary>
        /// Allows you to retrieve bought/sold/listed item history.
        /// </summary>
        /// <param name="app">Inventory's game id.</param>
        /// <param name="page">Page number.</param>
        /// <param name="names">Item names. (optional)</param>
        /// <param name="resultsPerPage">Results per page.</param>
        /// <returns>List of item's history records.</returns>
        public static List <ItemHistoryRecord> GetItemHistory(AppId.AppName app, int page, List <string> names, ResultsPerPage resultsPerPage)
        {
            CheckParameters(page);
            string urlRequest = GetUrlRequest(app, page, names, resultsPerPage);
            string result     = Server.ServerRequest.RequestServer(urlRequest);
            List <ItemHistoryRecord> itemHistoryRecords = ReadItemHistoryRecords(result);

            return(itemHistoryRecords);
        }