Example #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string url = req.Query["url"];

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            //name = name ?? data?.name;

            Console.WriteLine("URL {0}", url);
            Console.WriteLine("Body {0}" + Environment.NewLine, data);

            var response = new CustomStatusCodeResult(HttpStatusCode.NotFound,
                                                      new
            {
                Success = true,
                Result  = $"Not found mapping for {url}"
            });

            return(response);
        }
Example #2
0
        private static async Task <IActionResult> FromFile(string fileName)
        {
            var jsonContents = await WooCommerce.Mocks.Resources.GetContentAsync(fileName);

            var result = new CustomStatusCodeResult(HttpStatusCode.OK, jsonContents);

            return(result);
        }
Example #3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string url = req.Query["url"];

            url = url ?? string.Empty;
            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            //name = name ?? data?.name;

            Console.WriteLine("URL {0}", url);
            Console.WriteLine("Body {0}" + Environment.NewLine, data);

            if (url.EndsWith("/wp-json/wc/v3/products/categories"))
            {
                return(await FromFile("Categories.json"));
            }
            if (url.EndsWith("/wp-json/wc/v3/products/tags"))
            {
                return(await FromFile("Tags.json"));
            }
            if (url.EndsWith("/wp-json/wc/v3/products"))
            {
                return(await FromFile("Products.json"));
            }
            if (url.Contains("/wp-json/wc/v3/products/") && url.EndsWith("/variations"))
            {
                return(new CustomStatusCodeResult(HttpStatusCode.OK,
                                                  new Variation[] {
                    new Variation {
                        image = new VariationImage {
                            src = DEFAULT_IMAGE
                        }
                    },
                    new Variation {
                        image = new VariationImage {
                            src = DEFAULT_IMAGE
                        }
                    }
                }));
            }
            if (url.Contains(CATEGORY_ID_URL))
            {
                var id = GetParameterId(url, CATEGORY_ID_URL);

                return(new CustomStatusCodeResult(HttpStatusCode.OK,
                                                  new Product[] {
                    new Product {
                        id = 799,
                        name = "Ship Your Idea",
                        description = DESCRIPTION,
                        slug = "ship-your-idea-22",
                        images = new List <ProductImage> {
                            new ProductImage {
                                src = DEFAULT_IMAGE
                            }
                        },
                        categories = new List <ProductCategoryLine> {
                            new ProductCategoryLine {
                                id = id, name = "Category" + id
                            }
                        }
                    }
                }));
            }
            if (url.Contains(SEARCH_URL))
            {
                var keyword = GetParameter(url, SEARCH_URL);

                return(new CustomStatusCodeResult(HttpStatusCode.OK,
                                                  new Product[] {
                    new Product {
                        id = 800,
                        name = $"Ship Your Idea {keyword}",
                        description = DESCRIPTION,
                        slug = "ship-your-idea-22",
                        images = new List <ProductImage> {
                            new ProductImage {
                                src = DEFAULT_IMAGE
                            }
                        }
                    }
                }));
            }
            var response = new CustomStatusCodeResult(HttpStatusCode.OK,
                                                      new
            {
                Success = true,
                Result  = $"Not found mapping for {url}"
            });

            return(response);
        }