예제 #1
0
        /// <summary>
        ///     Gets the least set of paramas required to be sent along with each request.
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, object> GetBaseParams()
        {
            var baseParams = new Dictionary <string, object>
            {
                { "app_key", _countly.Initialization.AppKey },
                { "device_id", _countly.Device.DeviceId },
                { "sdk_name", Constants.SdkName },
                { "sdk_version", Constants.SdkVersion }
            };

            foreach (var item in TimeMetricModel.GetTimeMetricModel())
            {
                baseParams.Add(item.Key, item.Value);
            }

            if (!string.IsNullOrEmpty(_countly.OptionalParameters.CountryCode))
            {
                baseParams.Add("country_code", _countly.OptionalParameters.CountryCode);
            }
            if (!string.IsNullOrEmpty(_countly.OptionalParameters.City))
            {
                baseParams.Add("city", _countly.OptionalParameters.City);
            }
            if (_countly.OptionalParameters.Location != null)
            {
                baseParams.Add("location", _countly.OptionalParameters.Location);
            }

            return(baseParams);
        }
예제 #2
0
        /// <summary>
        /// Build request URL using ServerUrl, AppKey, DeviceID and supplied queryParams parameters
        /// </summary>
        /// <param name="queryParams"></param>
        /// <returns></returns>
        public static string BuildRequest(Dictionary <string, object> queryParams)
        {
            StringBuilder request = new StringBuilder();

            //"i" added to the countly server url
            request.AppendFormat(Countly.ServerUrl[Countly.ServerUrl.Length - 1] == '/' ? "{0}i?" : "{0}/i?", Countly.ServerUrl);

            //Required information
            request.AppendFormat("app_key={0}", Countly.AppKey);
            request.AppendFormat("&device_id={0}", Countly.DeviceId);

            //Metrics added to each request
            foreach (var item in TimeMetricModel.GetTimeMetricModel())
            {
                request.AppendFormat("&{0}={1}", item.Key, item.Value);
            }

            //Query params supplied for creating request
            foreach (var item in queryParams)
            {
                if (!string.IsNullOrEmpty(item.Key) && item.Value != null)
                {
                    request.AppendFormat("&{0}={1}", item.Key, item.Value);
                }
            }

            //location information
            if (!string.IsNullOrEmpty(Countly.CountryCode))
            {
                request.AppendFormat("&country_code={0}", Countly.CountryCode);
            }
            if (!string.IsNullOrEmpty(Countly.City))
            {
                request.AppendFormat("&city={0}", Countly.City);
            }
            if (!string.IsNullOrEmpty(Countly.Location))
            {
                request.AppendFormat("&location={0}", Countly.Location);
            }

            return(request.ToString());
        }