public string GetSearchTweetsQuery(ITweetSearchParameters tweetSearchParameters) { if (tweetSearchParameters == null || !_searchQueryValidator.IsSearchParameterValid(tweetSearchParameters) || !_searchQueryValidator.IsSearchQueryValid(tweetSearchParameters.SearchQuery)) { return(null); } var formattedQuery = _twitterStringFormatter.TwitterEncode(tweetSearchParameters.SearchQuery); StringBuilder query = new StringBuilder(String.Format(Resources.Search_SearchTweets, formattedQuery)); query.Append(String.Format(Resources.SearchParameter_ResultType, tweetSearchParameters.SearchType)); if (_searchQueryValidator.IsGeoCodeValid(tweetSearchParameters.GeoCode)) { string latitude = tweetSearchParameters.GeoCode.Coordinates.Latitude.ToString(CultureInfo.InvariantCulture); string longitude = tweetSearchParameters.GeoCode.Coordinates.Longitude.ToString(CultureInfo.InvariantCulture); string radius = tweetSearchParameters.GeoCode.Radius.ToString(CultureInfo.InvariantCulture); string measure = tweetSearchParameters.GeoCode.DistanceMeasure == DistanceMeasure.Kilometers ? "km" : "mi"; query.Append(String.Format(Resources.SearchParameter_GeoCode, latitude, longitude, radius, measure, CultureInfo.InvariantCulture)); } if (_searchQueryValidator.IsLangDefined(tweetSearchParameters.Lang)) { query.Append(String.Format(Resources.SearchParameter_Lang, tweetSearchParameters.Lang.GetDescriptionAttribute())); } if (_searchQueryValidator.IsLocaleParameterValid(tweetSearchParameters.Locale)) { query.Append(String.Format(tweetSearchParameters.Locale)); } if (_searchQueryValidator.IsSinceIdDefined(tweetSearchParameters.SinceId)) { query.Append(String.Format(Resources.QueryParameter_SinceId, tweetSearchParameters.SinceId)); } if (_searchQueryValidator.IsMaxIdDefined(tweetSearchParameters.MaxId)) { query.Append(String.Format(Resources.QueryParameter_MaxId, tweetSearchParameters.MaxId)); } if (_searchQueryValidator.IsMaximumNumberOfResultsDefined(tweetSearchParameters.MaximumNumberOfResults)) { query.Append(String.Format(Resources.QueryParameter_Count, tweetSearchParameters.MaximumNumberOfResults)); } if (_searchQueryValidator.IsUntilDefined(tweetSearchParameters.Until)) { query.Append(String.Format(Resources.SearchParameter_Until, tweetSearchParameters.Until.ToString("yyyy-MM-dd"))); } return(query.ToString()); }
public string GenerateGeoCodeParameter(IGeoCode geoCode) { if (!_searchQueryValidator.IsGeoCodeValid(geoCode)) { return(string.Empty); } string latitude = geoCode.Coordinates.Latitude.ToString(CultureInfo.InvariantCulture); string longitude = geoCode.Coordinates.Longitude.ToString(CultureInfo.InvariantCulture); string radius = geoCode.Radius.ToString(CultureInfo.InvariantCulture); string measure = geoCode.DistanceMeasure == DistanceMeasure.Kilometers ? "km" : "mi"; return(string.Format(Resources.SearchParameter_GeoCode, latitude, longitude, radius, measure, CultureInfo.InvariantCulture)); }