private IEnumerable <string> GetArgs(GetRandomWordRequest getRandomWordRequest)
        {
            yield return(WordnikUrlHelper.GetMinCorpusCountArgument(getRandomWordRequest.MinCorpusCount));

            yield return(WordnikUrlHelper.GetMaxCorpusCountArgument(getRandomWordRequest.MaxCorpusCount));

            foreach (var arg in WordnikUrlHelper.GetWithDictionaryDefinitionArguments(getRandomWordRequest.WithDictionaryDefinitions))
            {
                yield return(arg);
            }
            yield return(WordnikUrlHelper.GetMinimumDictionaryCountArgument(getRandomWordRequest.MinimumDictionaryCount));

            yield return(WordnikUrlHelper.GetMaximumDictionaryCountArgument(getRandomWordRequest.MaximumDictionaryCount));

            yield return(WordnikUrlHelper.GetMaximumLengthArgument(getRandomWordRequest.MaximumLength));

            yield return(WordnikUrlHelper.GetMinimumLengthArgument(getRandomWordRequest.MinimumLength));

            foreach (var arg in WordnikUrlHelper.GetExpludePartsOfSpeechArguments(getRandomWordRequest.ExcludePartsOfSpeech))
            {
                yield return(arg);
            }
            foreach (var arg in WordnikUrlHelper.GetIncludePartsOfSpeechArguments(getRandomWordRequest.IncludePartsOfSpeech))
            {
                yield return(arg);
            }
            yield return(WordnikUrlHelper.GetApiKeyArgument(getRandomWordRequest.ApiKey));
        }
        private string GetRandomWordUrl(GetRandomWordRequest getRandomWordRequest)
        {
            StringBuilder urlBuilder = new StringBuilder();

            urlBuilder.Append(_getWordnikBaseUrlQuery.Query());
            urlBuilder.Append(RandomWordPath);

            var args = GetArgs(getRandomWordRequest).ToList();

            if (args.Any())
            {
                urlBuilder.Append("?");
                urlBuilder.Append(string.Join("&", args));
            }

            var url = urlBuilder.ToString();

            return(url);
        }
        public GetRandomWordResponse GetRandomWord(GetRandomWordRequest getRandomWordRequest)
        {
            var url = GetRandomWordUrl(getRandomWordRequest);

            WebRequest request = WebRequest.Create(url);

            request.Method      = "GET";
            request.ContentType = "application/json";
            using (WebResponse webResponse = request.GetResponse())
            {
                using (Stream stream = webResponse.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(stream);
                    string       responseFromWordnik = reader.ReadToEnd();
                    var          wordnikWord         = JsonConvert.DeserializeObject <WordnikWord>(responseFromWordnik);

                    return(new GetRandomWordResponse(new WordResponse()
                    {
                        Id = wordnikWord.Id, Word = wordnikWord.Word
                    }));
                }
            }
        }