Esempio n. 1
0
        private String BuildGeolocationUrlParams(GeolocationParams geolocationParams)
        {
            StringBuilder urlParams = new StringBuilder(80);

            urlParams.Append("apiKey=");
            urlParams.Append(apiKey);

            if (geolocationParams != null)
            {
                if (!Strings.IsNullOrEmpty(geolocationParams.GetIPAddress()))
                {
                    urlParams.Append("&ip=");
                    urlParams.Append(geolocationParams.GetIPAddress());
                }

                if (!Strings.IsNullOrEmpty(geolocationParams.GetFields()))
                {
                    urlParams.Append("&fields=");
                    urlParams.Append(geolocationParams.GetFields());
                }

                if (!Strings.IsNullOrEmpty(geolocationParams.GetLang()))
                {
                    urlParams.Append("&lang=");
                    urlParams.Append(geolocationParams.GetLang());
                }
            }
            return(urlParams.ToString());
        }
Esempio n. 2
0
        public Dictionary <String, Object> GetBulkGeolocation(GeolocationParams geolocationParams)
        {
            Dictionary <String, Object> json = new Dictionary <String, Object>();

            json.Add("ips", geolocationParams.GetIPAddresses());

            String         jsonStr     = JsonConvert.SerializeObject(json);
            String         urlParams   = BuildGeolocationUrlParams(geolocationParams);
            String         url         = "https://api.ipgeolocation.io/ipgeo-bulk" + "?" + urlParams;
            List <JObject> apiResponse = GetBulkApiResponse(jsonStr, url);

            return(prepareBulkResponseForUser(apiResponse, "geolocation"));
        }
Esempio n. 3
0
        public List <Geolocation> GetBulkGeolocation(GeolocationParams geolocationParams)
        {
            Dictionary <string, Object> json = new Dictionary <string, Object>();

            json.Add("ips", geolocationParams.GetIps());
            string             jsonStr      = JsonConvert.SerializeObject(json);
            String             urlParams    = BuildGeolocationUrlParams(geolocationParams);
            List <JObject>     apiResponse  = GetBulkApiResponse(jsonStr, urlParams);
            List <Geolocation> geolocations = new List <Geolocation>();

            foreach (JObject response in apiResponse)
            {
                geolocations.Add(new Geolocation(response));
            }
            return(geolocations);
        }
Esempio n. 4
0
        private String BuildGeolocationUrlParams(GeolocationParams geolocationParams)
        {
            String urlParams = "apiKey=" + apiKey;

            if (geolocationParams != null)
            {
                String ip = geolocationParams.GetIp();
                if (ip != null && !ip.Equals(""))
                {
                    urlParams = urlParams + "&ip=" + ip;
                }
                String fields = geolocationParams.GetFields();
                if (fields != null && !fields.Equals(""))
                {
                    urlParams = urlParams + "&fields=" + fields;
                }
            }
            return(urlParams);
        }
Esempio n. 5
0
        private String BuildGeolocationUrlParams(GeolocationParams geolocationParams)
        {
            StringBuilder urlParams = new StringBuilder(80);

            urlParams.Append("apiKey=");
            urlParams.Append(apiKey);

            if (geolocationParams != null)
            {
                if (!Strings.IsNullOrEmpty(geolocationParams.GetIPAddress()))
                {
                    urlParams.Append("&ip=");
                    urlParams.Append(geolocationParams.GetIPAddress());
                }

                if (!Strings.IsNullOrEmpty(geolocationParams.GetFields()))
                {
                    urlParams.Append("&fields=");
                    urlParams.Append(geolocationParams.GetFields());
                }

                bool includeHost = false;

                if (geolocationParams.IsIncludeHostname())
                {
                    urlParams.Append("&include=hostname");
                    includeHost = true;
                }
                else if (geolocationParams.IsIncludeHostnameFallbackLive())
                {
                    urlParams.Append("&include=hostnameFallbackLive");
                    includeHost = true;
                }
                else if (geolocationParams.IsIncludeLiveHostname())
                {
                    urlParams.Append("&include=liveHostname");
                    includeHost = true;
                }

                if (geolocationParams.IsIncludeSecurity())
                {
                    if (includeHost)
                    {
                        urlParams.Append(",security");
                    }
                    else
                    {
                        urlParams.Append("&include=security");
                    }
                }

                if (geolocationParams.IsIncludeUserAgentDetail())
                {
                    if (includeHost || geolocationParams.IsIncludeSecurity())
                    {
                        urlParams.Append(",useragent");
                    }
                    else
                    {
                        urlParams.Append("&include=useragent");
                    }
                }

                if (!Strings.IsNullOrEmpty(geolocationParams.GetLang()))
                {
                    urlParams.Append("&lang=");
                    urlParams.Append(geolocationParams.GetLang());
                }

                if (!Strings.IsNullOrEmpty(geolocationParams.GetExcludes()))
                {
                    urlParams.Append("&excludes=");
                    urlParams.Append(geolocationParams.GetExcludes());
                }
            }

            return(urlParams.ToString());
        }
Esempio n. 6
0
        public Dictionary <String, Object> GetGeolocation(GeolocationParams geolocationParams)
        {
            JObject apiResponse = GetGeolocationResponse(geolocationParams);

            return(prepareResponseForUser(apiResponse, "geolocation"));
        }
Esempio n. 7
0
        private JObject GetGeolocationResponse(GeolocationParams geolocationParams)
        {
            String urlParams = BuildGeolocationUrlParams(geolocationParams);

            return(GetApiResponse("ipgeo", urlParams));
        }
Esempio n. 8
0
        public Geolocation GetGeolocation(GeolocationParams geolocationParams)
        {
            JObject apiResponse = GetGeolocationResponse(geolocationParams);

            return(new Geolocation(apiResponse));
        }