/// <summary>
        /// Retrieves the number of objects having a specified tag.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="tagId">The ID of the tag you would like to filter your objects by. Either TagId or TagName is required.</param>
        /// <param name="tagName">The name of the tag you would like to filter your objects by. Either TagId or TagName is required.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="sortOptions">The sort options.</param>
        /// <param name="externs">If you have a relationship between your object and another object, you may want to include the data from a related field in your results. Each external field is listed in the format {object}//{field}.</param>
        /// <param name="listFields">A string array of the fields which should be returned in your results.</param>
        /// <returns>The number of objects matching the query.</returns>
        public async Task <int> GetCountByTagAsync(ApiObjectType objectType,
                                                   int?tagId = null, string?tagName = null,
                                                   ApiSearchOptions?searchOptions = null, ApiSortOptions?sortOptions      = null,
                                                   IEnumerable <string>?externs   = null, IEnumerable <string>?listFields = null)
        {
            var json = await SelectByTagAsync(objectType, tagId, tagName, searchOptions, sortOptions, externs, listFields, true).ConfigureAwait(false);

            return(JsonData(json)["count"]?.Value <string>()?.Convert <int>() ?? 0);
        }
        /// <summary>
        /// Retrieves a collection of objects having a specified tag.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="tagId">The ID of the tag you would like to filter your objects by. Either TagId or TagName is required.</param>
        /// <param name="tagName">The name of the tag you would like to filter your objects by. Either TagId or TagName is required.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="sortOptions">The sort options.</param>
        /// <param name="externs">If you have a relationship between your object and another object, you may want to include the data from a related field in your results. Each external field is listed in the format {object}//{field}.</param>
        /// <param name="listFields">A string array of the fields which should be returned in your results.</param>
        /// <returns>A list of objects matching the query.</returns>
        public async Task <List <Dictionary <string, string> > > SelectByTagAsync(ApiObjectType objectType,
                                                                                  int?tagId = null, string?tagName = null,
                                                                                  ApiSearchOptions?searchOptions = null, ApiSortOptions?sortOptions      = null,
                                                                                  IEnumerable <string>?externs   = null, IEnumerable <string>?listFields = null)
        {
            var json = await SelectByTagAsync(objectType, tagId, tagName, searchOptions, sortOptions, externs, listFields, false).ConfigureAwait(false);

            return(JsonData(json).ToObject <List <Dictionary <string, string> > >() !);
        }
示例#3
0
        /// <summary>
        /// Retrieves information about a collection of objects, such as the number of objects that match the given criteria.
        /// </summary>
        /// <param name="searchOptions">The search options.</param>
        /// <returns>A ResponseCollectionInfo object.</returns>
        public async Task <ResponseCollectionInfo> GetCollectionInfoAsync(ApiSearchOptions?searchOptions = null)
        {
            var query = new Dictionary <string, object?>()
                        .AddSearchOptions(searchOptions);

            var json = await ApiRequest.GetAsync <JObject>(
                $"{EndpointPlural}/getInfo", query).ConfigureAwait(false);

            return(OnParseGetCollectionInfo(json));
        }
        /// <summary>
        /// Cancels one or more tasks.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        public async Task CancelAsync(ApiObjectType objectType, ApiSearchOptions?searchOptions = null, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType }
            }
            .AddSearchOptions(searchOptions, true);

            await ApiRequest.PostAsync <object>(
                "task/cancel", query, cancellationToken).ConfigureAwait(false);
        }
示例#5
0
        /// <summary>
        /// Retrieves a collection of objects having a specified tag.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="tagId">The ID of the tag you would like to filter your objects by. Either TagId or TagName is required.</param>
        /// <param name="tagName">The name of the tag you would like to filter your objects by. Either TagId or TagName is required.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="sortOptions">The sort options.</param>
        /// <param name="externs">If you have a relationship between your object and another object, you may want to include the data from a related field in your results. Each external field is listed in the format {object}//{field}.</param>
        /// <param name="listFields">A string array of the fields which should be returned in your results.</param>
        /// <returns>A list of objects matching the query.</returns>
        public async Task <List <Dictionary <string, string> > > SelectByTagAsync(ApiObjectType objectType,
                                                                                  int?tagId = null, string?tagName = null,
                                                                                  ApiSearchOptions?searchOptions = null, ApiSortOptions?sortOptions      = null,
                                                                                  IEnumerable <string>?externs   = null, IEnumerable <string>?listFields = null, CancellationToken cancellationToken = default)
        {
            var json = await SelectByTagAsync(
                objectType, tagId, tagName, searchOptions, sortOptions, externs, listFields, false, cancellationToken).ConfigureAwait(false);

            return(await json.RunAndCatchAsync(x => x.JsonData().ToObject <List <Dictionary <string, string> > >()).ConfigureAwait(false)
                   ?? new List <Dictionary <string, string> >());
        }
示例#6
0
        /// <summary>
        /// This endpoint deletes a collection of objects. Use caution with this endpoint.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <returns>A list of objects matching the query.</returns>
        public async Task DeleteMultipleAsync(ApiObjectType objectType, ApiSearchOptions?searchOptions = null, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
            }
            .AddSearchOptions(searchOptions, true);

            await _apiRequest.DeleteAsync <object>(
                "objects", query, true, cancellationToken).ConfigureAwait(false);
        }
        /// <summary>
        /// Assigns a task to one or more contacts.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="message">Data for the task message to assign to contacts.</param>
        public async Task AssignAsync(ApiObjectType objectType, ApiSearchOptions?searchOptions = null, AssignTaskMessage?message = null, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "object_type_id", (int)objectType },
            }
            .AddSearchOptions(searchOptions, true)
            .AddIfHasValue("message", message);

            await ApiRequest.PostAsync <object>(
                "task/assign", query, cancellationToken).ConfigureAwait(false);
        }
        /// <summary>
        /// Marks one or more tasks as completed.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="data">Additional data to set, see documentation.</param>
        /// <returns></returns>
        public async Task CompleteAsync(ApiObjectType objectType, ApiSearchOptions?searchOptions = null, IDictionary <string, object?>?data = null)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType }
            }
            .AddSearchOptions(searchOptions, true)
            .AddIfHasValue("data", data);

            await ApiRequest.PostAsync <object>(
                "task/complete", query).ConfigureAwait(false);
        }
示例#9
0
        /// <summary>
        /// Retrieves the number of objects having a specified tag.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="tagId">The ID of the tag you would like to filter your objects by. Either TagId or TagName is required.</param>
        /// <param name="tagName">The name of the tag you would like to filter your objects by. Either TagId or TagName is required.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="sortOptions">The sort options.</param>
        /// <param name="externs">If you have a relationship between your object and another object, you may want to include the data from a related field in your results. Each external field is listed in the format {object}//{field}.</param>
        /// <param name="listFields">A string array of the fields which should be returned in your results.</param>
        /// <returns>The number of objects matching the query.</returns>
        public async Task <int> GetCountByTagAsync(ApiObjectType objectType,
                                                   int?tagId = null, string?tagName = null,
                                                   ApiSearchOptions?searchOptions = null, ApiSortOptions?sortOptions      = null,
                                                   IEnumerable <string>?externs   = null, IEnumerable <string>?listFields = null, CancellationToken cancellationToken = default)
        {
            var json = await SelectByTagAsync(
                objectType, tagId, tagName, searchOptions, sortOptions, externs, listFields, true, cancellationToken).ConfigureAwait(false);

            return(await json.RunStructAndCatchAsync(x => {
                var count = x.JsonData().JsonChild("count");
                return count.GetString().Convert <int>();
            }).ConfigureAwait(false));
        }
示例#10
0
        /// <summary>
        /// Adds one or more tags to one or more objects.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="tagIds">A list of the IDs of the tag(s) which should be added to objects.</param>
        public async Task AddTagAsync(ApiObjectType objectType,
                                      ApiSearchOptions?searchOptions, IEnumerable <int> tagIds, CancellationToken cancellationToken = default)
        {
            tagIds.CheckNotNullOrEmpty(nameof(tagIds));

            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "add_list", tagIds },
            }
            .AddSearchOptions(searchOptions, true);

            await _apiRequest.PutAsync <object>(
                "objects/tag", query, cancellationToken).ConfigureAwait(false);
        }
        /// <summary>
        /// Adds one or more tags to one or more objects by the tag name. This endpoint will create the tag if it doesn't exist.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="tagNames">A list of the names of the tag(s) which should be added to objects.</param>
        public async Task AddTagNamesAsync(ApiObjectType objectType,
                                           ApiSearchOptions?searchOptions, IEnumerable <string> tagNames)
        {
            tagNames.CheckNotNullOrEmpty(nameof(tagNames));

            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "add_names", tagNames },
            }
            .AddSearchOptions(searchOptions, true);

            await _apiRequest.PutAsync <object>(
                "objects/tagByName", query).ConfigureAwait(false);
        }
示例#12
0
        /// <summary>
        /// Removes one or more tags from one or more objects by the tag name.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="tagNames">A list of the names of the tag(s) which should be removed from objects.</param>
        public async Task RemoveTagNamesAsync(ApiObjectType objectType,
                                              ApiSearchOptions?searchOptions, IEnumerable <string> tagNames, CancellationToken cancellationToken = default)
        {
            tagNames.CheckNotNullOrEmpty(nameof(tagNames));

            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "remove_names", tagNames },
            }
            .AddSearchOptions(searchOptions);

            await _apiRequest.DeleteAsync <object>(
                "objects/tagByName", query, true, cancellationToken).ConfigureAwait(false);
        }
示例#13
0
        /// <summary>
        /// Retrieves a collection of objects based on a set of parameters.
        /// </summary>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="sortOptions">The sort options.</param>
        /// <param name="externs">If you have a relationship between your object and another object, you may want to include the data from a related field in your results. Each external field is listed in the format {object}//{field}.</param>
        /// <param name="listFields">A string array of the fields which should be returned in your results.</param>
        /// <returns>A list of objects matching the query.</returns>
        public async Task <IList <T> > SelectAsync(
            ApiSearchOptions?searchOptions = null, ApiSortOptions?sortOptions      = null,
            IEnumerable <string>?externs   = null, IEnumerable <string>?listFields = null)
        {
            var query = new Dictionary <string, object?>()
                        .AddSearchOptions(searchOptions)
                        .AddSortOptions(sortOptions)
                        .AddIfHasValue("externs", externs)
                        .AddIfHasValue("listFields", externs);

            var json = await ApiRequest.GetAsync <JObject>(
                $"{EndpointPlural}", query).ConfigureAwait(false);

            return(await OnParseSelectMultipleAsync(json).ConfigureAwait(false));
        }
示例#14
0
        /// <summary>
        /// Removes one or more objects from one or more campaigns.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="campaignIds">A list of the campaign(s) from which objects should be removed.</param>
        public async Task RemoveFromCampaignAsync(ApiObjectType objectType,
                                                  ApiSearchOptions?searchOptions, IEnumerable <int> campaignIds, CancellationToken cancellationToken = default)
        {
            campaignIds.CheckNotNullOrEmpty(nameof(campaignIds));

            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "remove_list", campaignIds }
            }
            .AddSearchOptions(searchOptions);

            await _apiRequest.DeleteAsync <object>(
                "objects/subscribe", query, true, cancellationToken).ConfigureAwait(false);
        }
        /// <summary>
        /// Removes one or more tags from one or more objects.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="tagIds">A list of the IDs of the tag(s) which should be removed from objects.</param>
        public async Task RemoveTagAsync(ApiObjectType objectType,
                                         ApiSearchOptions?searchOptions, IEnumerable <int> tagIds)
        {
            tagIds.CheckNotNullOrEmpty(nameof(tagIds));

            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "remove_list", tagIds },
            }
            .AddSearchOptions(searchOptions);

            await _apiRequest.DeleteAsync <object>(
                "objects/tag", query).ConfigureAwait(false);
        }
        /// <summary>
        /// Adds one or more objects to one or more campaigns.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="campaignIds">A list of the campaign(s) to which objects should be added.</param>
        public async Task AddToCampaignAsync(ApiObjectType objectType,
                                             ApiSearchOptions?searchOptions, IEnumerable <int> campaignIds)
        {
            campaignIds.CheckNotNullOrEmpty(nameof(campaignIds));

            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "add_list", campaignIds },
            }
            .AddSearchOptions(searchOptions, true);

            await _apiRequest.PutAsync <object>(
                "objects/subscribe", query).ConfigureAwait(false);
        }
示例#17
0
        /// <summary>
        /// Unpauses rules, sequences, and sequence subscribers.
        /// </summary>
        /// <param name="objectType">The object type: Rule, Sequence or Sequence Subscriber.</param>
        /// <param name="searchOptions">The search options.</param>
        public async Task UnpauseRuleOrSequenceAsync(ApiObjectType objectType, ApiSearchOptions?searchOptions, CancellationToken cancellationToken = default)
        {
            if (objectType != ApiObjectType.Rule && objectType != ApiObjectType.Sequence && objectType != ApiObjectType.SequenceSubscriber)
            {
                throw new ArgumentException(Properties.Resources.ObjectTypeMustBeSequence);
            }

            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
            }
            .AddSearchOptions(searchOptions);

            await _apiRequest.PostAsync <object>(
                "objects/unpause", query, cancellationToken).ConfigureAwait(false);
        }
        /// <summary>
        /// Retrieves a collection of objects based on a set of parameters.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <param name="sortOptions">The sort options.</param>
        /// <param name="externs">If you have a relationship between your object and another object, you may want to include the data from a related field in your results. Each external field is listed in the format {object}//{field}.</param>
        /// <param name="listFields">A string array of the fields which should be returned in your results.</param>
        /// <returns>A list of objects matching the query.</returns>
        public async Task <List <Dictionary <string, string> > > SelectAsync(ApiObjectType objectType,
                                                                             ApiSearchOptions?searchOptions = null, ApiSortOptions?sortOptions      = null,
                                                                             IEnumerable <string>?externs   = null, IEnumerable <string>?listFields = null)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType }
            }
            .AddSearchOptions(searchOptions)
            .AddSortOptions(sortOptions)
            .AddIfHasValue("externs", externs)
            .AddIfHasValue("listFields", listFields);

            return(await _apiRequest.GetAsync <List <Dictionary <string, string> > >(
                       "objects", query).ConfigureAwait(false));
        }
示例#19
0
        private async Task <JsonElement?> SelectByTagAsync(ApiObjectType objectType,
                                                           int?tagId = null, string?tagName = null,
                                                           ApiSearchOptions?searchOptions = null, ApiSortOptions?sortOptions      = null,
                                                           IEnumerable <string>?externs   = null, IEnumerable <string>?listFields = null, bool count = false, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { tagId.HasValue ? "tag_id" : "tag_name", (object?)tagId ?? tagName },
                { "count", count ? "true" : "false" },
            }
            .AddSearchOptions(searchOptions)
            .AddSortOptions(sortOptions)
            .AddIfHasValue("externs", externs)
            .AddIfHasValue("listFields", listFields);

            return(await _apiRequest.GetJsonAsync(
                       "objects/tag", query, true, cancellationToken).ConfigureAwait(false));
        }
 /// <summary>
 /// Adds search options to the query parameters.
 /// </summary>
 /// <param name="list">The dictionary of query parameters.</param>
 /// <param name="options">An ApiSearchOptions object containing search options.</param>
 /// <param name="performsAction">Whether the query performs an action other than selecting data.</param>
 /// <returns></returns>
 internal static Dictionary <string, object?> AddSearchOptions(this Dictionary <string, object?> list, ApiSearchOptions?options, bool performsAction = false)
 {
     if (options != null)
     {
         var condition = options.GetCondition();
         list.AddIfHasValue("ids", options.Ids)
         .AddIfHasValue("group_ids", options.GroupIds)
         .AddIfHasValue("start", options.Start)
         .AddIfHasValue("range", options.Range)
         .AddIfHasValue("condition", condition)
         .AddIfHasValue("search", options.Search);
         if (!string.IsNullOrEmpty(options.Search) && options.SearchNotes)
         {
             list.Add("searchNotes", options.SearchNotes);
         }
         if (performsAction && !options.Ids.Any())
         {
             list.Add("performAll", "1");
         }
     }
     else
     {
         // list.Add("performAll", "1");
     }
     return(list);
 }
示例#21
0
 /// <summary>
 /// Adds search options to the query parameters.
 /// </summary>
 /// <param name="list">The dictionary of query parameters.</param>
 /// <param name="options">An ApiSearchOptions object containing search options.</param>
 /// <param name="performsAction">Whether the query performs an action other than selecting data.</param>
 /// <returns></returns>
 internal static Dictionary <string, object?> AddSearchOptions(this Dictionary <string, object?> list, ApiSearchOptions?options, bool performsAction = false)
 {
     if (options != null)
     {
         // OntraportHttpClient.SerializerOptions.Converters.Add(new ApiSearchConditionConverter());
         var condition = options.GetCondition();
         if (options.Ids.Any())
         {
             list.Add("ids", string.Join(",", options.Ids));
         }
         list.AddIfHasValue("group_id", options.GroupId)
         .AddIfHasValue("start", options.Start)
         .AddIfHasValue("range", options.Range)
         .AddIfHasValue("condition", condition)
         .AddIfHasValue("search", options.Search);
         if (!string.IsNullOrEmpty(options.Search) && options.SearchNotes)
         {
             list.Add("searchNotes", options.SearchNotes);
         }
         if (performsAction && !options.Ids.Any())
         {
             list.Add("performAll", "1");
         }
     }
     else
     {
         // list.Add("performAll", "1");
     }
     return(list);
 }
 /// <summary>
 /// Adds Conditions, Search and SearchNotes query parameters.
 /// </summary>
 /// <param name="list">The dictionary of query parameters.</param>
 /// <param name="condition">Sets more specific criterias for which objects to bring back.</param>
 /// <param name="search">A string to search your objects for.</param>
 /// <param name="searchNotes">Used in conjunction with the search parameter to indicate whether or not object notes should be searched for the specified string in addition to other object fields.</param>
 /// <returns>The query dictionary.</returns>
 internal static Dictionary <string, object?> AddConditions(this Dictionary <string, object?> list, ApiSearchOptions?condition = null, string?search = null, bool searchNotes = false)
 {
     if (condition != null)
     {
         list.Add("condition", condition.ToString());
     }
     if (!string.IsNullOrEmpty(search))
     {
         list.Add("search", search !);
         if (searchNotes)
         {
             list.Add("searchNotes", searchNotes);
         }
     }
     return(list);
 }
示例#23
0
        /// <summary>
        /// Retrieves information about a collection of objects, such as the number of objects that match the given criteria.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="searchOptions">The search options.</param>
        /// <returns>A ResponseCollectionInfo object.</returns>
        public async Task <ResponseCollectionInfo?> GetCollectionInfoAsync(ApiObjectType objectType, ApiSearchOptions?searchOptions = null, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
            }
            .AddSearchOptions(searchOptions);

            return(await _apiRequest.GetAsync <ResponseCollectionInfo>(
                       "objects/getInfo", query, true, cancellationToken).ConfigureAwait(false));
        }