Exemplo n.º 1
0
        protected virtual async Task <TResponse> ExecuteAsync <TResponse>(IRestRequest request, CancellationToken cancellationToken)
            where TResponse : DripResponse, new()
        {
            var resp = await Client.ExecuteTaskAsync <TResponse>(request, cancellationToken);

            return(DripResponse.FromRequestResponse <TResponse>(request, resp));
        }
Exemplo n.º 2
0
        protected virtual TResponse Execute <TResponse>(IRestRequest request)
            where TResponse : DripResponse, new()
        {
            var resp = Client.Execute <TResponse>(request);

            return(DripResponse.FromRequestResponse <TResponse>(request, resp));
        }
        /// <summary>
        /// Apply a tag to a subscriber.
        /// See: https://www.getdrip.com/docs/rest-api#apply_tag
        /// </summary>
        /// <param name="email">The subscriber's email address.</param>
        /// <param name="tag">The tag to apply. E.g. "Customer"</param>
        /// <param name="cancellationToken">The CancellationToken to be used to cancel the request.</param>
        /// <returns>A Task that, when completed successfully, will contain a StatusCode of NoContent.</returns>
        public async Task <DripResponse> ApplyTagToSubscriberAsync(string email, string tag, CancellationToken cancellationToken = default(CancellationToken))
        {
            //This doesn't use a PostResource overload because specifying a return type causes an error
            var req = CreatePostRequest(ApplyTagToSubscriberResource, TagsRequestBodyKey, new DripTag[] { new DripTag {
                                                                                                              Email = email, Tag = tag
                                                                                                          } });
            var resp = await Client.ExecuteTaskAsync(req, cancellationToken);

            return(DripResponse.FromRequestResponse(req, resp));
        }
        /// <summary>
        /// Apply a tag to a subscriber.
        /// See: https://www.getdrip.com/docs/rest-api#apply_tag
        /// </summary>
        /// <param name="email">The subscriber's email address.</param>
        /// <param name="tag">The tag to apply. E.g. "Customer"</param>
        /// <returns>On success, a DripResponse with StatusCode of Created.</returns>
        public DripResponse ApplyTagToSubscriber(string email, string tag)
        {
            //This doesn't use a PostResource overload because specifying a return type causes an error
            var req = CreatePostRequest(ApplyTagToSubscriberResource, TagsRequestBodyKey, new DripTag[] { new DripTag {
                                                                                                              Email = email, Tag = tag
                                                                                                          } });
            var resp = Client.Execute(req);

            return(DripResponse.FromRequestResponse(req, resp));
        }
Exemplo n.º 5
0
        internal protected static DripResponse FromRequestResponse(IRestRequest restRequest, IRestResponse restResponse)
        {
            var result = new DripResponse();

            result.OriginalRequest  = restRequest;
            result.OriginalResponse = restResponse;
            result.StatusCode       = restResponse.StatusCode;

            return(result);
        }
Exemplo n.º 6
0
        protected async virtual Task <DripResponse> PostBatchResourceAsync <TData>(string resourceUrl, string key, TData data, CancellationToken cancellationToken)
        {
            var body = new Dictionary <string, TData>[] { new Dictionary <string, TData> {
                                                              { key, data }
                                                          } };
            var req  = CreatePostRequest(resourceUrl, BatchRequestBodyKey, body);
            var resp = await Client.ExecuteTaskAsync(req, cancellationToken);

            return(DripResponse.FromRequestResponse(req, resp));
        }
Exemplo n.º 7
0
        protected virtual DripResponse PostBatchResource <TData>(string resourceUrl, string key, TData data)
        {
            var body = new Dictionary <string, TData>[] { new Dictionary <string, TData> {
                                                              { key, data }
                                                          } };
            var req  = CreatePostRequest(resourceUrl, BatchRequestBodyKey, body);
            var resp = Client.Execute(req);

            return(DripResponse.FromRequestResponse(req, resp));
        }