/// <summary>The search to perform.</summary> /// <param name="urbanRequest">The urban request.</param> /// <returns>The <see cref="UrbanResponse"/>.</returns> public UrbanResponse Search(UrbanRequest urbanRequest) { var request = new RestRequest { Resource = "define/{term}.json", RequestFormat = DataFormat.Json }; request.AddParameter("term", urbanRequest.Term, ParameterType.UrlSegment); return(this.Execute <UrbanResponse>(request)); }
/// <summary>The search to perform on Urban Dictionary.</summary> /// <param name="urbanRequest">The urban request.</param> /// <returns>The <see cref="UrbanResponse"/>.</returns> public UrbanResponse Search(UrbanRequest urbanRequest) { try { var html = new WebClient().DownloadString(Url + HttpUtility.UrlEncode(urbanRequest.Term)); var definition = this.definitionRegex.Match(html); var example = this.exampleRegex.Match(html); var word = this.exampleRegex.Match(html); return(new UrbanResponse { Definition = HttpUtility.HtmlDecode(Regex.Replace(definition.Groups[1].Captures[0].Value, "<.*?>", string.Empty)), Example = HttpUtility.HtmlDecode(Regex.Replace(example.Groups[1].Captures[0].Value, "<.*?>", string.Empty)), Url = Url + urbanRequest.Term, Word = Regex.Replace(word.Groups[1].Captures[0].Value, "<.*?>", string.Empty), }); } catch (Exception) { } return(null); }