public async Task <RecipePayload> RunSearch(SearchParams searchParams, string appId, string appKey)
        {
            RestClient  client  = new RestClient("https://api.edamam.com");
            RestRequest request = new RestRequest("search", Method.GET);

            request.AddQueryParameter("q", searchParams.SearchTerm);
            request.AddQueryParameter("app_id", appId);
            request.AddQueryParameter("app_key", appKey);
            request.AddQueryParameter("from", searchParams.From.ToString());
            request.AddQueryParameter("to", searchParams.To.ToString());

            try {
                IRestResponse <RecipePayload> response = await client.ExecuteAsync <RecipePayload> (request);

                if (response.IsSuccessful)
                {
                    response.Data.Warning = "";
                    return(response.Data);
                }
                return(FailureRequest(response.ErrorMessage, searchParams));
            } catch (System.Exception ex) {
                _errorWriter.WriteException(ex);
                return(RecipeErrorResponses.ExceptionResponse(ex, searchParams.SearchTerm));
            }
        }
Beispiel #2
0
        public async Task <RecipePayload> SearchRecipes(string searchTerm, int from = 0, int to = 10)
        {
            try {
                RuntimeSetting       setting = GetRuntimeSetting();
                IRecipeSearchHandler recipeSearchHandler;

                switch (setting)
                {
                case RuntimeSetting.Production:
                    // setup for prod
                    recipeSearchHandler = new ProdRecipeSearchHandlerImpl(_configuration);
                    break;

                case RuntimeSetting.Development:
                    // setup for dev
                    recipeSearchHandler = new DevRecipeSearchHandlerImpl(_configuration);
                    break;

                case RuntimeSetting.Both:
                    return(RuntimeMisconfiguration(RuntimeSetting.Both, searchTerm, from, to));

                case RuntimeSetting.Neither:
                    return(RuntimeMisconfiguration(RuntimeSetting.Neither, searchTerm, from, to));

                default:
                    return(RuntimeMisconfiguration(RuntimeSetting.Unknown, searchTerm, from, to));
                }

                SearchParams searchParams = new SearchParams(searchTerm, from, to);

                RecipePayload payload = await recipeSearchHandler.Search(searchParams);

                return(payload);
            } catch (System.Exception ex) {
                HandleEx(ex);
                return(RecipeErrorResponses.ExceptionResponse(ex, searchTerm));
            }
        }