Example #1
0
        // token received from CreateSession/RenewSession API call
        public SearchForImagesResponse Search(string token)
        {
            var searchForImagesRequest = new SearchForImagesRequest
            {
                RequestHeader = new RequestHeader {
                    Token = token
                },
                SearchForImages2RequestBody = new SearchForImages2RequestBody
                {
                    Query = new Query {
                        SearchPhrase = SearchTerm
                    },
                    Filter = new Filter {
                        ImageFamilies = new List <string> {
                            "Editorial"
                        }
                    },
                    ResultOptions = new ResultOptions {
                        ItemCount = 25, ItemStartNumber = 1
                    }
                }
            };

            return(MakeWebRequest(SearchForImagesRequestUrl, searchForImagesRequest));
        }
Example #2
0
        //You may wish to replace this code with your preferred library for posting and receiving JSON data.
        private static SearchForImagesResponse MakeWebRequest(string requestUrl, SearchForImagesRequest request)
        {
            var webRequest = WebRequest.Create(requestUrl) as HttpWebRequest;

            webRequest.Method      = "POST";
            webRequest.ContentType = "application/json";

            var jsonSerializer = new JavaScriptSerializer();
            var requestStr     = jsonSerializer.Serialize(request);

            Debug.WriteLine(requestStr);

            using (var writer = new StreamWriter(webRequest.GetRequestStream()))
            {
                writer.Write(requestStr);
                writer.Close();
            }

            var response = webRequest.GetResponse() as HttpWebResponse;

            string jsonResult;

            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                jsonResult = reader.ReadToEnd();
                reader.Close();
            }

            Debug.WriteLine(jsonResult);

            return(jsonSerializer.Deserialize <SearchForImagesResponse>(jsonResult));
        }
        // token received from CreateSession/RenewSession API call
        public SearchForImagesResponse Search(string token, int page)
        {
            const int itemCount       = 25;
            var       itemStartNumber = PageStart(page, itemCount);

            var searchForImagesRequest = new SearchForImagesRequest
            {
                RequestHeader = new RequestHeader {
                    Token = token
                },
                SearchForImages2RequestBody = new SearchForImages2RequestBody
                {
                    Query = new Query {
                        SearchPhrase = SearchTerm
                    },
                    Filter = new Filter {
                        ImageFamilies = new List <string> {
                            "Creative"
                        }
                    },
                    ResultOptions = new ResultOptions {
                        ItemCount = itemCount, ItemStartNumber = itemStartNumber
                    }
                }
            };

            return(MakeWebRequest(SearchForImagesRequestUrl, searchForImagesRequest));
        }
        public SearchForImagesResponse defaultSearch(string token, string termpharse)
        {
            var searchForImagesRequest = new SearchForImagesRequest
            {
                RequestHeader = new RequestHeader {
                    Token = token
                },
                SearchForImages2RequestBody = new SearchForImages2RequestBody
                {
                    Query = new Query {
                        SearchPhrase = !string.IsNullOrEmpty(termpharse) ? termpharse : SearchTerm, DateCreatedRange = new DateCreatedRange {
                            EndDate = System.DateTime.Now.AddYears(1).ToString("yyyy-MM-dd"), StartDate = System.DateTime.Now.AddYears(-20).ToString("yyyy-MM-dd")
                        }
                    },
                    Filter = new Filter {
                        ImageFamilies = new List <string> {
                            _imagefamilies
                        }, Orientations = new List <string> {
                            _Orientations
                        }, EditorialSegments = new List <string> {
                            "Sports"
                        }
                    },
                    ResultOptions = new ResultOptions {
                        ItemCount = 75, ItemStartNumber = _startcnt, EditorialSortOrder = "MostRecent"
                    }
                }
            };

            return(MakeWebRequest(SearchForImagesRequestUrl, searchForImagesRequest));
        }
        public SearchForImagesResponse EventSearch(string token, string termpharse)
        {
            var searchForImagesRequest = new SearchForImagesRequest
            {
                RequestHeader = new RequestHeader {
                    Token = token
                },
                SearchForImages2RequestBody = new SearchForImages2RequestBody
                {
                    Query = new Query {
                        SearchPhrase = !string.IsNullOrEmpty(termpharse) ? termpharse : SearchTerm, EventId = _eventID
                    },
                    Filter = new Filter {
                        ImageFamilies = new List <string> {
                            _imagefamilies
                        }, Orientations = new List <string> {
                            _Orientations
                        }
                    },
                    ResultOptions = new ResultOptions {
                        ItemCount = 75, ItemStartNumber = _startcnt
                    }
                }
            };

            return(MakeWebRequest(SearchForImagesRequestUrl, searchForImagesRequest));
        }
        // token received from CreateSession/RenewSession API call
        public SearchForImagesResponse Search(string token)
        {
            var searchForImagesRequest = new SearchForImagesRequest
            {
                RequestHeader = new RequestHeader{Token = token},
                SearchForImages2RequestBody = new SearchForImages2RequestBody
                                  {
                                      Query = new Query{SearchPhrase = SearchTerm},
                                      Filter = new Filter { ImageFamilies = new List<string> { "Creative" } },
                                      ResultOptions = new ResultOptions { ItemCount = 25, ItemStartNumber = 1 }
                                  }
            };

            return MakeWebRequest(SearchForImagesRequestUrl, searchForImagesRequest);
        }
        //You may wish to replace this code with your preferred library for posting and receiving JSON data.
        private static SearchForImagesResponse MakeWebRequest(string requestUrl, SearchForImagesRequest request)
        {
            var webRequest = WebRequest.Create(requestUrl) as HttpWebRequest;

            webRequest.Method = "POST";
            webRequest.ContentType = "application/json";

            var jsonSerializer = new JavaScriptSerializer();
            var requestStr = jsonSerializer.Serialize(request);

            Debug.WriteLine(requestStr);

            using (var writer = new StreamWriter(webRequest.GetRequestStream()))
            {
                writer.Write(requestStr);
                writer.Close();
            }

            var response = webRequest.GetResponse() as HttpWebResponse;

            string jsonResult;
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                jsonResult = reader.ReadToEnd();
                reader.Close();
            }

            Debug.WriteLine(jsonResult);

            return jsonSerializer.Deserialize<SearchForImagesResponse>(jsonResult);
        }