Пример #1
0
        /// <summary>
        ///     Create a new pixelation graph definition.
        /// </summary>
        /// <param name="id">ID for identifying the pixelation graph, format ^[a-z][a-z0-9-]{1, 16}$</param>
        /// <param name="name">name of the pixelation graph.</param>
        /// <param name="unit">unit of the quantity</param>
        /// <param name="type">type of quantity</param>
        /// <param name="color">display color of the pixel</param>
        /// <param name="timezone">timezone for handling this graph, default UTC</param>
        /// <param name="selfSufficient">
        ///     when SVG graph referenced, pixel of this graph itself will be increment or decrement,
        ///     default none
        /// </param>
        /// <returns></returns>
        public async Task <ApiResponse> CreateAsync(string id, string name, string unit, GraphType type, GraphColor color, string timezone = null, SufficientType?selfSufficient = null)
        {
            var parameters = new Dictionary <string, object>
            {
                ["id"]    = id,
                ["name"]  = name,
                ["unit"]  = unit,
                ["type"]  = type.AsString(),
                ["color"] = color.AsString()
            };

            if (!string.IsNullOrWhiteSpace(timezone))
            {
                parameters.Add("timezone", timezone);
            }
            if (selfSufficient.HasValue)
            {
                parameters.Add("selfSufficient", selfSufficient.Value.AsString());
            }

            return(await Client.SendAsync <ApiResponse>(HttpMethod.Post, $"/v1/users/{Client.Username}/graphs", parameters).Stay());
        }