Exemplo n.º 1
0
        private static void AddAPIOptions(SearchAPIArguments APIArgs, RestRequest request)
        {
            request.AddParameter("q", APIArgs.q);
            request.AddParameter("start", APIArgs.start);
            request.AddParameter("limit", APIArgs.limit);
            if (APIArgs.sortby != null)
            {
                request.AddParameter("sortby", APIArgs.sortby);
            }

            request.AddParameter("apikey", APIArgs.apikey);
            request.AddParameter("pretty_print", APIArgs.pretty_print);
            request.AddParameter("suppress_status_codes", APIArgs.suppress_status_codes);

            if (APIArgs.datasheets == true)
            {
                request.AddParameter("include[]", "datasheets");
            }
            if (APIArgs.compliance_documents == true)
            {
                request.AddParameter("include[]", "compliance_documents");
            }
            if (APIArgs.descriptions == true)
            {
                request.AddParameter("include[]", "descriptions");
            }
            if (APIArgs.specs == true)
            {
                request.AddParameter("include[]", "specs");
            }
            if (APIArgs.imagesets == true)
            {
                request.AddParameter("include[]", "imagesets");
            }
            if (APIArgs.category_uids == true)
            {
                request.AddParameter("include[]", "category_uids");
            }
            if (APIArgs.external_links == true)
            {
                request.AddParameter("include[]", "external_links");
            }

            foreach (string Show in APIArgs.ShowDirectives)
            {
                request.AddParameter("show[]", Show);
            }
            foreach (string Hide in APIArgs.HideDirectives)
            {
                request.AddParameter("hide[]", Hide);
            }
        }
Exemplo n.º 2
0
        public SearchResponse GetSearchObject <T>(SearchAPIArguments APIArgs) where T : class, new()
        {
            var type = typeof(T);

            if (!urls.ContainsKey(type))
            {
                return(null);
            }

            var request = new RestRequest(Method.GET);

            request.Resource = urls[type] + "/search";
            AddAPIOptions(APIArgs, request);

            IRestResponse response = Execute(request);

            return(Deserialize <SearchResponse>(response));
        }