/// <summary>
 /// Clone
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static CallbackModel Clone(this CallbackModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new CallbackModel {
         AuthenticationHeader = model.AuthenticationHeader,
         Method = model.Method,
         Uri = model.Uri
     });
 }
        /// <summary>
        /// Internal callback helper
        /// </summary>
        /// <param name="client"></param>
        /// <param name="payload"></param>
        /// <param name="query"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        internal static Task CallAsync(IHttpClient client, JToken payload,
                                       string query, CallbackModel model)
        {
            var builder = new UriBuilder(model.Uri);

            if (!string.IsNullOrEmpty(query))
            {
                if (string.IsNullOrEmpty(builder.Query))
                {
                    builder.Query = "?";
                }
                else
                {
                    builder.Query += "&";
                }
                builder.Query += query;
            }
            var request = client.NewRequest(builder.Uri);

            if (!string.IsNullOrWhiteSpace(model.AuthenticationHeader))
            {
                request.AddHeader("Authentication", model.AuthenticationHeader);
            }
            switch (model.Method)
            {
            case CallbackMethodType.Put:
                if (payload != null)
                {
                    request.SetContent(payload);
                }
                return(client.PutAsync(request));

            case CallbackMethodType.Delete:
                return(client.DeleteAsync(request));

            case CallbackMethodType.Get:
                return(client.GetAsync(request));

            case CallbackMethodType.Post:
                if (payload != null)
                {
                    request.SetContent(payload);
                }
                return(client.PostAsync(request));

            default:
                return(Task.FromException(new ArgumentException("bad method value",
                                                                nameof(model.Method))));
            }
        }
 /// <summary>
 /// Equality comparison
 /// </summary>
 /// <param name="model"></param>
 /// <param name="that"></param>
 /// <returns></returns>
 public static bool IsSameAs(this CallbackModel model, CallbackModel that)
 {
     if (model == that)
     {
         return(true);
     }
     if (model == null || that == null)
     {
         return(false);
     }
     return
         (that.Uri == model.Uri &&
          that.AuthenticationHeader == model.AuthenticationHeader &&
          (that.Method ?? CallbackMethodType.Get) ==
          (model.Method ?? CallbackMethodType.Get));
 }