Example #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="Webhook{T}"/> object and registers a webhook with Trello.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="description"></param>
        /// <param name="callBackUrl"></param>
        /// <param name="auth">(Optional) Custom authorization parameters. When not provided, <see cref="TrelloAuthorization.Default"/> will be used.</param>
        /// <param name="ct">(Optional) A cancellation token for async processing.</param>
        public static async Task <Webhook <T> > Create(T target, string callBackUrl, string description = null,
                                                       TrelloAuthorization auth = null,
                                                       CancellationToken ct     = default)
        {
            var context = new WebhookContext <T>(auth);
            var id      = await context.Create(target, description, callBackUrl, ct);

            return(new Webhook <T>(id, context));
        }
Example #2
0
        private Webhook(string id, WebhookContext <T> context)
        {
            Id       = id;
            _context = context;
            _context.Synchronized.Add(this);

            _callBackUrl = new Field <string>(_context, nameof(CallBackUrl));
            _callBackUrl.AddRule(UriRule.Instance);
            _description = new Field <string>(_context, nameof(Description));
            _isActive    = new Field <bool?>(_context, nameof(IsActive));
            _isActive.AddRule(NullableHasValueRule <bool> .Instance);
            _target = new Field <T>(_context, nameof(Target));
            _target.AddRule(NotNullRule <T> .Instance);

            TrelloConfiguration.Cache.Add(this);
        }
Example #3
0
        /// <summary>
        /// Creates a new instance of the <see cref="Webhook{T}"/> object for a webhook which has already been registered with Trello.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="auth">(Optional) Custom authorization parameters. When not provided, <see cref="TrelloAuthorization.Default"/> will be used.</param>
        public Webhook(string id, TrelloAuthorization auth = null)
        {
            Id       = id;
            _context = new WebhookContext <T>(Id, auth);
            _context.Synchronized += Synchronized;

            _callBackUrl = new Field <string>(_context, nameof(CallBackUrl));
            _callBackUrl.AddRule(UriRule.Instance);
            _description = new Field <string>(_context, nameof(Description));
            _isActive    = new Field <bool?>(_context, nameof(IsActive));
            _isActive.AddRule(NullableHasValueRule <bool> .Instance);
            _target = new Field <T>(_context, nameof(Target));
            _target.AddRule(NotNullRule <T> .Instance);

            TrelloConfiguration.Cache.Add(this);
        }