コード例 #1
0
        public IList<SearchResponse> Search(SearchRequest search)
        {
            if (search == null || string.IsNullOrEmpty(search.Q)) return new List<SearchResponse>();
            /*
             * http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&result_type=mixed
             * */
            string query = _httpServer.UrlEncode(search.Q);

            string url = "http://search.twitter.com/search.json";
            string fullUrl = string.Format("{0}?q={1}&rpp=25&include_entities=true", url, query);

            if (!string.IsNullOrEmpty(search.ResultType))
            {
                fullUrl = string.Format("{0}&result_type={1}", fullUrl, search.ResultType);
            }

            if (search.GeoInfoCode != null && !string.IsNullOrEmpty(search.GeoInfoCode.Latitude))
            {
                fullUrl = string.Format("{0}&geocode={1}", fullUrl, search.GeoInfoCode.Code);
            }

            string signatureString = _oAuthCreationService.CreateSignature(url);
            string authorizationHeaderParams = _oAuthCreationService.CreateAuthorizationHeaderParameter(
                signatureString, _oAuthCreationService.OAuthTimeStamp);

            string method = "GET";
            HttpWebRequest request = _httpRequestResponse.GetRequest(fullUrl, authorizationHeaderParams, method);
            var responseText = _httpRequestResponse.GetResponse(request);
            var searchResponse = _mapSearch.Map(responseText);
            return searchResponse;
        }
コード例 #2
0
        public ActionResult Index()
        {
            var search = new SearchRequest
                             {
                                 GeoInfoCode = new GeoInfo
                                                   {
                                                       Latitude = "-80.19084",
                                                       Longitude = "26.209278",
                                                       RadiusMiles = 10
                                                   }
                                 ,
                                 Q = "grace",
                                 ResultType = "recent"
                             };

            IList<SearchResponse> geo = _twitterSearchService.Search(search);
            return View(geo);
        }
コード例 #3
0
        public void Should_be_able_to_map_search_request_object_to_view_data()
        {
            var task = new AutoMapperTask();
            task.Execute();

            var src = new SearchRequest
                                    {
                                        GeoInfoCode =
                                            new GeoInfo {Latitude = "100", Longitude = "100", RadiusMiles = 10},
                                        Q = "#usguys",
                                        ShowUser = true,
                                        ResultType = "json",
                                        Until = new DateTime(2000, 1, 1)
                                    };
            var item = Mapper.Map<SearchRequest, TwitterSearchViewModel>(src);
            Assert.IsNotNull(item);
            Assert.AreEqual("#usguys",item.Q);
            Assert.AreEqual("100",item.Latitude);
        }