BuildGetQueryString() public static method

Helper method builds a query string from a list of keyvaluepair(string,string) object
public static BuildGetQueryString ( string>.List qsData ) : string
qsData string>.List list of keyvaluepairs to turn into a query string
return string
Beispiel #1
0
        /// <summary>
        /// Lists AuditEntries of the account. Due to the potentially large number of audit entries, a start and end date must be provided during an index call to limit the search. The format of the dates must be YYYY/MM/DD HH:MM:SS [+/-]ZZZZ e.g. 2011/07/11 00:00:00 +0000. A maximum of 1000 records will be returned by each index call.
        /// Using the available filters, one can select or group which audit entries to retrieve.
        /// </summary>
        /// <param name="filter">Filter parameters for index query</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include.</param>
        /// <param name="limit">Limit the audit entries to this number. The limit should >= 1 and <= 1000</param>
        /// <param name="start_date">The start date for retrieving audit entries</param>
        /// <param name="end_date">The end date for retrieving audit entries (the format must be the same as start date). The time period between start and end date must be less than 3 months (93 days).</param>
        /// <returns>Collection of AuditEntry objects from the start_time defined with a limit, filter and view as specified</returns>
        public static List <AuditEntry> index(List <Filter> filter, string view, string limit, DateTime start_date, DateTime end_date)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "auditee_href", "user_email"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            int intCheck;

            if (Int32.TryParse(limit, out intCheck))
            {
                if (intCheck >= 1 && intCheck <= 1000)
                {
                    //this is a good thing... should trace this out
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Input 'limit' was out of bounds.  Limit cannot be less than 1 or greater than 1000: value = " + limit);
                }
            }
            else
            {
                throw new ArgumentException("Input 'limit' was non-numeric: {" + limit + "}");
            }

            if (end_date.Subtract(start_date).Days > 93)
            {
                throw new ArgumentException(string.Format("The difference between the start date [{0}] and the end date [{1}] must not be greater than 93 days", start_date, end_date));
            }

            string timeOffset = DateTime.Now.ToString("%K").Replace(":", "");

            string startDateString = start_date.ToString("yyyy/MM/dd HH:mm:ss ") + timeOffset;
            string endDateString   = end_date.ToString("yyyy/MM/dd HH:mm:ss ") + timeOffset;

            List <KeyValuePair <string, string> > getParams = new List <KeyValuePair <string, string> >();

            getParams.Add(new KeyValuePair <string, string>("end_date", endDateString));
            getParams.Add(new KeyValuePair <string, string>("limit", limit));
            getParams.Add(new KeyValuePair <string, string>("start_date", startDateString));
            if (!string.IsNullOrWhiteSpace(view))
            {
                getParams.Add(new KeyValuePair <string, string>("view", view));
            }

            string queryString = Utility.BuildGetQueryString(getParams);

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter);
            }

            string jsonString = Core.APIClient.Instance.Get(APIHrefs.AuditEntry, queryString);

            return(deserializeList(jsonString));
        }