Esempio n. 1
0
        /// <summary>
        /// Modifies an edge rule
        /// </summary>
        /// <param name="zoneId">Zone id to apply the rule to</param>
        /// <param name="edgeRule">Edge rule to modify</param>
        /// <returns>Success, throws if failed</returns>
        public async Task <bool> ModifyEdgeRule(long zoneId, EdgeRule edgeRule)
        {
            if (zoneId <= 0)
            {
                throw new BunnyBadRequestException("Invalid pullzone identifier provided.");
            }

            using (HttpContent httpContent = new StringContent(JsonWrapper.Serialize(edgeRule)))
            {
                HttpResponseMessage httpResponse = await this.AccountKey.Client.PostAsync(GetPath($"pullzone/{zoneId}/edgerules/addorupdate"), httpContent);

                switch (httpResponse.StatusCode)
                {
                case HttpStatusCode.Created:     // Returnes created for both updating and adding.
                    return(true);

                case HttpStatusCode.Unauthorized:
                    throw new BunnyUnauthorizedException();

                case HttpStatusCode.BadRequest:
                    ErrorMessage error = await JsonWrapper.Deserialize <ErrorMessage>(httpResponse);

                    throw new BunnyBadRequestException(error);

                default:
                    return(false);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds an edge rule
        /// </summary>
        /// <param name="zoneId">Zone identifier</param>
        /// <param name="edgeRule">Edge rule to add</param>
        /// <returns>Success, throws if failed</returns>
        public async Task <bool> AddEdgeRule(long zoneId, EdgeRule edgeRule)
        {
            if (zoneId <= 0)
            {
                throw new BunnyBadRequestException("Invalid pullzone identifier provided.");
            }

            if (edgeRule.Guid != null && edgeRule.Guid != Guid.Empty)
            {
                edgeRule.Guid = Guid.Empty;
            }

            return(await ModifyEdgeRule(zoneId, edgeRule));
        }