Ejemplo n.º 1
0
        //SAVE - Will be used in the Image getting functions
        //recipe.ImageURL = m_URL + "/recipeImages/" + recipe.Id + "-" + m_RecipeImagex + "x" + m_RecipeImagey;

        /// <summary>
        /// Used to set up the struct with the recommended configuration.
        /// </summary>
        /// <param name="query">The query. The only needed value</param>
        /// <param name="number">The number of results to return</param>
        /// <param name="offset">Number of items to skip. Leave default unless needed</param>
        /// <param name="cuisine">Leave default unless needed</param>
        /// <param name="diet">Leave default unless needed</param>
        /// <param name="excludeIngredients">Leave default unless needed</param>
        /// <param name="intolerances">Leave default unless needed</param>
        /// <param name="limitLicense">Leave default unless needed</param>
        /// <param name="instructionsRequired">Leave default unless needed</param>
        /// <returns></returns>
        public RecipeSearchParams SetUpParams(string query,
                                              int number                = 5,
                                              int offset                = 0,
                                              string cuisine            = "",
                                              string diet               = "",
                                              string excludeIngredients = "",
                                              string intolerances       = "",
                                              bool limitLicense         = true,
                                              bool instructionsRequired = true)
        {
            RecipeSearchParams param = new RecipeSearchParams
            {
                query                = query,
                number               = number,
                offset               = offset,
                cuisine              = cuisine,
                diet                 = diet,
                excludeIngredients   = excludeIngredients,
                intolerances         = intolerances,
                limitLicense         = limitLicense,
                instructionsRequired = instructionsRequired
            };

            return(param);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Queries the API for short recipes based off the passed params
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        private SpoonacularRecipeShortSearchResult QueryAPI(RecipeSearchParams param)
        {
            RestClient  client  = new RestClient(SpoonacularAPI.m_URL);
            RestRequest request = new RestRequest(SpoonacularAPI.m_RecipeSearchURL, Method.GET);

            //Set up the query parameters
            request.AddParameter("query", param.query);
            if (param.number > m_maxResults)
            {
                param.number = 20;
            }
            if (param.number < 0)
            {
                param.number = 1;
            }
            request.AddParameter("number", param.number);
            if (param.offset < 0)
            {
                param.offset = 0;
            }
            request.AddParameter("offset", param.offset);
            if (param.cuisine != "")
            {
                request.AddParameter("cuisine", param.cuisine);
            }
            if (param.diet != "")
            {
                request.AddParameter("diet", param.diet);
            }
            if (param.excludeIngredients != "")
            {
                request.AddParameter("excludeIngredients", param.excludeIngredients);
            }
            if (param.intolerances != "")
            {
                request.AddParameter("intolerances", param.intolerances);
            }
            request.AddParameter("limitLicense", param.limitLicense);
            request.AddParameter("instructionsRequired", param.instructionsRequired);
            request.AddParameter("apiKey", m_APYKey);

            //Execute the query
            SpoonacularRecipeShortSearchResult result;

            try
            {
                RestResponse response = client.Execute(request);
                //try to get the data out of the response

                result = JsonConvert.DeserializeObject <SpoonacularRecipeShortSearchResult>(response.Content);
                return(result);
            }
            catch (Exception)
            {
                //add call to exception logger
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="query"></param>
        /// <param name="maxResults">default 5, max 20</param>
        /// <param name="offset"> default 0</param>
        /// <returns>
        /// Returns a List of Recipe models
        /// </returns>
        public List <Recipe_Short> RecipeSearch(string query, int maxResults, int offset)
        {
            RecipeSearchParams param = SetUpParams(query, maxResults, offset);
            SpoonacularRecipeShortSearchResult result = QueryAPI(param);

            return(result.results);
            //List<RecipeInformationRootObject> recipeInfoList = ToRecipeInformationList(result);
            //return ToRecipeShortList(recipeInfoList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// A Spoonacular specific search.  Is MUCH better than the alternatives
        /// </summary>
        /// <param name="query">The query. The only needed value</param>
        /// <param name="number">The number of results to return. Capped by the MAX_RESULTS value</param>
        /// <param name="offset">Number of items to skip. Leave default unless needed</param>
        /// <param name="cuisine">Leave default unless needed</param>
        /// <param name="diet">Leave default unless needed</param>
        /// <param name="excludeIngredients">Leave default unless needed</param>
        /// <param name="intolerances">Leave default unless needed</param>
        /// <param name="limitLicense">Leave default unless needed</param>
        /// <param name="instructionsRequired">Leave default unless needed</param>
        /// <returns></returns>
        public List <Recipe_Short> RecipeSearch(string query,
                                                int number                = 5,
                                                int offset                = 0,
                                                string cuisine            = "",
                                                string diet               = "",
                                                string excludeIngredients = "",
                                                string intolerances       = "",
                                                bool limitLicense         = true,
                                                bool instructionsRequired = true)
        {
            RecipeSearchParams param = SetUpParams(query, number, offset, cuisine, diet, excludeIngredients, intolerances, limitLicense,
                                                   instructionsRequired);
            SpoonacularRecipeShortSearchResult result = QueryAPI(param);

            return(result.results);
        }