コード例 #1
0
        public static TasteKidResponse Search(TasteKidRequestParams reqParams)
        {
            WebClient wc   = new WebClient();
            string    resp = wc.DownloadString(GenerateUri(reqParams));

            return(JsonDeserialize <TasteKidResponse>(resp));
        }
コード例 #2
0
        public static TasteKidResponse Search(string query, HashSet <TasteKidSearchFilter> filterSet)
        {
            var reqParams = new TasteKidRequestParams(filterSet);

            reqParams.AddQuery(query);
            return(Search(reqParams));
        }
コード例 #3
0
        public static TasteKidResponse Search(string query)
        {
            var reqParams = new TasteKidRequestParams();

            reqParams.AddQuery(query);
            return(Search(reqParams));
        }
コード例 #4
0
        public static TasteKidResponse Search(string query, TasteKidSearchFilter filter)
        {
            var reqParams = new TasteKidRequestParams(true);

            reqParams.AddQuery(query);
            reqParams.Filters.Add(filter);
            return(Search(reqParams));
        }
コード例 #5
0
        private static string GenerateUri(TasteKidRequestParams reqParams)
        {
            var url = "http://www.tastekid.com/ask/ws?";

            /// get queries
            string query = "";

            foreach (var item in reqParams.QueryItems)
            {
                if (!string.IsNullOrEmpty(query))
                {
                    query += ",";
                }
                query += item.GetValueForUrlQuery();
            }

            /// result filter goes into query, if all items are in filter we don't have to set it
            int allFiltersCount = Enum.GetNames(typeof(TasteKidSearchFilter)).ToList().Count;

            if (reqParams.Filters.Count < allFiltersCount)
            {
                foreach (var flt in reqParams.Filters)
                {
                    query += "//" + flt.ToString();
                }
            }

            url += "q=" + WebUtility.UrlEncode(query);

            /// app id
            if (!string.IsNullOrEmpty(reqParams.K_Param) && !string.IsNullOrEmpty(reqParams.F_Param))
            {
                url += "&f=" + reqParams.F_Param;
                url += "&k=" + reqParams.K_Param;
            }

            url += "&verbose=" + (reqParams.Verbose ? "1" : "0");
            url += "&format=JSON";
            return(url);
        }