Beispiel #1
0
        /// <summary>
        /// On success, responseData will be a List<T> of all entities
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="TParser"></param>
        /// <returns></returns>
        public ApigeeResponse GetEntities <T>(string collection, Func <JToken, T> TParser)
        {
            var rawResults = PerformRequest <string>("/" + collection);

            //parse response
            var response = new ApigeeResponse(rawResults, true);

            if (response.success)
            {
                try
                {
                    List <T> results = new List <T>();
                    foreach (var entity in (JToken)response.ResponseData)
                    {
                        results.Add(TParser(entity));
                    }
                    // put users List as response data
                    response.ResponseData = results;
                }
                catch (Exception)
                {
                    response.success = false;
                    response.Error   = new ApigeeResponseError("Error parsing " + collection + " entities");
                }
            }
            return(response);
        }
Beispiel #2
0
        public ApigeeResponse GetRoles()
        {
            var rawResults = PerformRequest <string>("/roles");
            var response   = new ApigeeResponse(rawResults, true);

            if (response.success)
            {
                try
                {
                    var results = new List <ApigeeRole>();
                    foreach (var role in (JToken)response.ResponseData)
                    {
                        results.Add(ApigeeRole.Parse(role));
                    }
                    // put roles list as response data
                    response.ResponseData = results;
                }
                catch (Exception)
                {
                    response.success = false;
                    response.Error   = new ApigeeResponseError("Error parsing Roles entities");
                }
            }
            return(response);
        }
Beispiel #3
0
        public ApigeeResponse GetUsers()
        {
            var rawResults = PerformRequest <string>("/users");
            //parse response
            var response = new ApigeeResponse(rawResults, true);

            if (response.success)
            {
                try
                {
                    List <ApigeeUser> results = new List <ApigeeUser>();
                    foreach (var usr in (JToken)response.ResponseData)
                    {
                        results.Add(ApigeeUser.Parse(usr));
                    }
                    // put users List as response data
                    response.ResponseData = results;
                }
                catch (Exception)
                {
                    response.success = false;
                    response.Error   = new ApigeeResponseError("Error parsing users entities");
                }
            }
            return(response);
        }
Beispiel #4
0
        public ApigeeResponse CreateAppUser(ApigeeUser accountModel)
        {
            var rawResults = PerformRequest <string>("/users", HttpTools.RequestTypes.Post, accountModel);
            var response   = new ApigeeResponse(rawResults, true);

            if (response.success)
            {
                response.ResponseData = ((JToken)response.ResponseData)[0];
            }
            return(response);
        }
Beispiel #5
0
        public ApigeeResponse PreformConnectionRequest(string entity1, string item, string verb, string entity2, string item2, HttpTools.RequestTypes request)
        {
            var path = "/" + entity1 + "/" + item + "/" + verb + "/" + entity2 + "/" + item2;

            var rawResults = PerformRequest <string>(path, request, null);

            //parse response
            var response = new ApigeeResponse(rawResults, true);

            return(response);
        }
Beispiel #6
0
        public ApigeeResponse GetUser(string username)
        {
            var rawResults = PerformRequest <string>("/users/" + username);
            //parse response
            var response = new ApigeeResponse(rawResults, true);

            if (response.success)
            {
                try
                {
                    var usr = ((JToken)response.ResponseData)[0];

                    // put user as response data
                    response.ResponseData = ApigeeUser.Parse(usr);
                }
                catch (Exception)
                {
                    response.success = false;
                    response.Error   = new ApigeeResponseError("Error parsing users entities");
                }
            }
            return(response);
        }
Beispiel #7
0
        /// <summary>
        ///  On success, responseData will be a List<T> of all Entity2 items
        ///  which are connected to Item from Entity1 in the verb connection
        ///  For example GetConnections("users","jhon","like") will return Pictures jhon likes.
        /// </summary>
        /// <typeparam name="Entity2Type">Type of Entity2 in the verb connection</typeparam>
        /// <param name="entity1">Collection of entity1 in the verb connection</param>
        /// <param name="item">The specific item in Entity1</param>
        /// <param name="verb">The connection vers. for example: "like", "attending", etc.</param>
        /// <param name="direction">Which side of the verb you want? True for "Connections", False for "Connecting"</param>
        /// <param name="TParser">Parser for Entity2 Type (Return Type)</param>
        /// <returns></returns>
        public ApigeeResponse GetConnections <Entity2Type>(string entity1, string item, string verb, bool direction, Func <JToken, Entity2Type> TParser)
        {
            var path = "/" + entity1 + "/" + item + "/";

            path += direction ? "Connection" : "Connecting";

            var rawResults = PerformRequest <string>(path);

            //parse response
            var response = new ApigeeResponse(rawResults, true);

            if (response.success)
            {
                try
                {
                    List <Entity2Type> results = new List <Entity2Type>();
                    foreach (var entity in (JToken)response.ResponseData)
                    {
                        //filer: take only specific Verb
                        var connection = entity["metadata"]["connection"];
                        if (connection != null && connection.ToString() == verb)
                        {
                            results.Add(TParser(entity));
                        }
                    }
                    // put users List as response data
                    response.ResponseData = results;
                }
                catch (Exception)
                {
                    response.success = false;
                    response.Error   = new ApigeeResponseError("Error parsing connections: " + path);
                }
            }
            return(response);
        }