コード例 #1
0
        /// <summary>
        /// Creates a connection type
        /// </summary>
        /// <param name="apiObjectType">The node object type</param>
        /// <param name="provider">The api provider</param>
        /// <param name="typesCreated">The list of types created to fill</param>
        /// <param name="typedArgumentNames">The list of field arguments received from type</param>
        /// <returns>The connection type</returns>
        private static MergedType CreateConnectionType(
            ApiObjectType apiObjectType,
            ApiProvider provider,
            Dictionary <string, MergedType> typesCreated,
            List <string> typedArgumentNames = null)
        {
            MergedType createdType;
            var        nodeType =
                (MergedObjectType)
                CreateMergedType(
                    provider,
                    apiObjectType.CreateField("node"),
                    null,
                    new List <string>(),
                    false,
                    typesCreated);

            var connectionType = new MergedConnectionType(nodeType.OriginalTypeName, provider, nodeType);

            if (typedArgumentNames != null)
            {
                connectionType.TypedArgumentNames = typedArgumentNames;
            }

            if (typesCreated.TryGetValue(connectionType.ComplexTypeName, out createdType))
            {
                return(createdType);
            }

            typesCreated[connectionType.ComplexTypeName]             = connectionType;
            typesCreated[connectionType.EdgeType.ComplexTypeName]    = connectionType.EdgeType;
            typesCreated[connectionType.ElementType.ComplexTypeName] = connectionType.ElementType;
            return(connectionType);
        }
コード例 #2
0
        public static string MapType(ApiObjectType type)
        {
            switch (type)
            {
            case ApiObjectType.Integer:
                return("int?");

            case ApiObjectType.String:
                return("string");

            case ApiObjectType.Boolean:
                return("bool?");

            case ApiObjectType.Number:
                return("double?");

            case ApiObjectType.Object:
                return("object");

            case ApiObjectType.Undefined:
                return("string");

            default:
                return("type_parse_error");
            }
        }
コード例 #3
0
        /// <summary>
        /// Retrieves the first ID of contact object or custom object by their email fields.
        /// </summary>
        /// <param name="objectType">The object type id.</param>
        /// <param name="email">The email of the object you would like to retrieve.</param>
        /// <returns>The object ID.</returns>
        public async Task <int?> GetObjectIdByEmailAsync(ApiObjectType objectType, string email)
        {
            var json = await GetObjectIdByEmailAsync(objectType, email, false);

            var result = json["data"]["id"].Value <string>();

            return(result != null?result.Convert <int>() : (int?)null);
        }
コード例 #4
0
        /// <summary>
        /// Retrieves the first ID of contact object or custom object by their email fields.
        /// </summary>
        /// <param name="objectType">The object type id.</param>
        /// <param name="email">The email of the object you would like to retrieve.</param>
        /// <returns>The object ID.</returns>
        public async Task <int?> GetObjectIdByEmailAsync(ApiObjectType objectType, string email)
        {
            var json = await GetObjectIdByEmailAsync(objectType, email, false).ConfigureAwait(false);

            var result = JsonData(json)["id"]?.Value <string>();

            return(result != null?result.Convert <int>() : (int?)null);
        }
コード例 #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)
        {
            var json = await SelectByTagAsync(objectType, tagId, tagName, searchOptions, sortOptions, externs, listFields, false);

            return(json["data"].ToObject <List <Dictionary <string, string> > >());
        }
コード例 #6
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)
        {
            var json = await SelectByTagAsync(objectType, tagId, tagName, searchOptions, sortOptions, externs, listFields, true);

            return(json["data"]["count"].Value <string>().Convert <int>());
        }
コード例 #7
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> > >() !);
        }
コード例 #8
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)
        {
            var json = await SelectByTagAsync(objectType, tagId, tagName, searchOptions, sortOptions, externs, listFields, true).ConfigureAwait(false);

            return(JsonData(json)["count"]?.Value <string>()?.Convert <int>() ?? 0);
        }
コード例 #9
0
        /// <summary>
        /// This endpoint will add a new object to your database. It can be used for any object type as long as the correct parameters are supplied. This endpoint allows duplication; if you want to avoid duplicates you should merge instead.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="values">Fields to set on the object.</param>
        /// <returns>The created object.</returns>
        public async Task <Dictionary <string, string> > CreateAsync(ApiObjectType objectType, object values = null)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType }
            };

            return(await _apiRequest.PostAsync <Dictionary <string, string> >(
                       "objects", query.AddObject(values)));
        }
コード例 #10
0
        /// <summary>
        /// Retrieves all IDs of contact objects or custom objects by their email fields.
        /// </summary>
        /// <param name="objectType">The object type id.</param>
        /// <param name="email">The email of the object you would like to retrieve.</param>
        /// <param name="all">A binary integer flag indicating whether you would like to retrieve an array of all IDs for objects with a matching email. If false, only the first object will be returned.</param>
        /// <returns>A list of object IDs.</returns>
        public async Task <IEnumerable <int> > GetObjectIdByEmailAllAsync(ApiObjectType objectType, string email, CancellationToken cancellationToken = default)
        {
            email.CheckNotNull(nameof(email));

            var json = await GetObjectIdByEmailAsync(
                objectType, email, true, cancellationToken).ConfigureAwait(false);

            return(await json.RunAndCatchAsync(x => x.JsonData().JsonChild("ids").EnumerateArray().Select(x => x.GetString().Convert <int>())).ConfigureAwait(false)
                   ?? Enumerable.Empty <int>());
        }
コード例 #11
0
        /// <summary>
        /// This endpoint will add a new object to your database. It can be used for any object type as long as the correct parameters are supplied. This endpoint allows duplication; if you want to avoid duplicates you should merge instead.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="values">Fields to set on the object.</param>
        /// <returns>The created object.</returns>
        public async Task <Dictionary <string, string> > CreateAsync(ApiObjectType objectType, object?values = null, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType }
            };

            return(await _apiRequest.PostAsync <Dictionary <string, string> >(
                       "objects", query.AddObject(values), cancellationToken).ConfigureAwait(false));
        }
コード例 #12
0
        /// <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)
        {
            var query = new Dictionary<string, object>
            {
                { "objectID", (int)objectType }
            }
                .AddSearchOptions(searchOptions, true);

            await ApiRequest.PostAsync<object>(
                "task/cancel", query);
        }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        /// <summary>
        /// Deletes a section in an object record. If attempting to delete a section, the section MUST be empty.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="sectionName">The name of the section.</param>
        public async Task DeleteSectionAsync(ApiObjectType objectType, string sectionName)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "section", sectionName }
            };

            await _apiRequest.DeleteAsync <string>(
                "objects/fieldeditor", query).ConfigureAwait(false);
        }
コード例 #15
0
        /// <summary>
        /// Retrieves all the information for an existing object of the specified object type.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The ID of the specific object.</param>
        /// <returns>The selected object.</returns>
        public async Task <Dictionary <string, string>?> SelectAsync(ApiObjectType objectType, int objectId, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "id", objectId }
            };

            return(await _apiRequest.GetAsync <Dictionary <string, string> >(
                       "object", query, true, cancellationToken).ConfigureAwait(false));
        }
コード例 #16
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);
        }
コード例 #17
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)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType },
            }
            .AddSearchOptions(searchOptions);

            return(await _apiRequest.GetAsync <ResponseCollectionInfo>(
                       "objects/getInfo", query));
        }
コード例 #18
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));
        }
コード例 #19
0
        /// <summary>
        /// Deletes an existing object of the specified object type.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The ID of the specific object.</param>
        public async Task DeleteAsync(ApiObjectType objectType, int objectId, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "id", objectId }
            };

            await _apiRequest.DeleteAsync <object>(
                "object", query, false, cancellationToken).ConfigureAwait(false);
        }
コード例 #20
0
        /// <summary>
        /// Retrieves all the information for an existing object of the specified object type.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The ID of the specific object.</param>
        /// <returns>The selected object.</returns>
        public async Task <Dictionary <string, string> > SelectAsync(ApiObjectType objectType, int objectId)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType },
                { "id", objectId }
            };

            return(await _apiRequest.GetAsync <Dictionary <string, string> >(
                       "object", query));
        }
コード例 #21
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> >());
        }
コード例 #22
0
        /// <summary>
        /// Deletes a field in an object record.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="fieldName">The name of the field e.g f1234.</param>
        public async Task DeleteFieldAsync(ApiObjectType objectType, string fieldName)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType },
                { "field", fieldName }
            };

            await _apiRequest.DeleteAsync <string>(
                "objects/fieldeditor", query);
        }
コード例 #23
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)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType },
            }
            .AddSearchOptions(searchOptions, true);

            await _apiRequest.DeleteAsync <object>(
                "objects", query);
        }
コード例 #24
0
        /// <summary>
        /// Deletes an existing object of the specified object type.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The ID of the specific object.</param>
        public async Task DeleteAsync(ApiObjectType objectType, int objectId)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType },
                { "id", objectId }
            };

            await _apiRequest.DeleteAsync <object>(
                "object", query, encodeJson : false);
        }
コード例 #25
0
        /// <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);
        }
コード例 #26
0
        private async Task <JsonElement?> GetObjectIdByEmailAsync(ApiObjectType objectType, string email, bool all = false, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "email", email },
                { "all", all ? 1 : 0 }
            };

            return(await _apiRequest.GetJsonAsync(
                       "object/getByEmail", query, true, cancellationToken).ConfigureAwait(false));
        }
コード例 #27
0
        /// <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)
        {
            var query = new Dictionary<string, object>
            {
                { "object_type_id", (int)objectType },
            }
                .AddSearchOptions(searchOptions, true)
                .AddIfHasValue("message", message);

            await ApiRequest.PostAsync<object>(
                "task/assign", query);
        }
コード例 #28
0
        /// <summary>
        /// Retrieves the first ID of contact object or custom object by their email fields.
        /// </summary>
        /// <param name="objectType">The object type id.</param>
        /// <param name="email">The email of the object you would like to retrieve.</param>
        /// <returns>The object ID.</returns>
        public async Task <int?> GetObjectIdByEmailAsync(ApiObjectType objectType, string email, CancellationToken cancellationToken = default)
        {
            email.CheckNotNullOrEmpty(nameof(email));

            var json = await GetObjectIdByEmailAsync(
                objectType, email, false, cancellationToken).ConfigureAwait(false);

            return(await json.RunStructAndCatchAsync(x => {
                var id = x.JsonData().JsonChild("id");
                return id.GetString().Convert <int?>();
            }).ConfigureAwait(false));
        }
コード例 #29
0
        /// <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);
        }
コード例 #30
0
        private async Task <JObject> GetObjectIdByEmailAsync(ApiObjectType objectType, string email, bool all = false)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType },
                { "email", email },
                { "all", all ? 1 : 0 }
            };

            return(await _apiRequest.GetAsync <JObject>(
                       "object/getByEmail", query));
        }