private CountryResponse GetGeoLocationResponse(string ipAddress)
 {
     using (var client = new WebServiceClient(_userId, _licenseKey))
     {
         var countryResponse = client.Country(ipAddress);
         return countryResponse;
     }
 }
        private CountryResponse GetGeoLocationResponse(string ipAddress)
        {
            //CountryResponse C = new CountryResponse()
            //{
            //    Country = new MaxMind.GeoIP2.Model.Country() { },

            //};
            using (var client = new WebServiceClient(_userId, _licenseKey))
            {
                var countryResponse = client.Country(ipAddress);
                return(countryResponse);
            }
        }
Exemple #3
0
        public void CorrectlyFormattedCountryResponseShouldDeserializeIntoResponseObject()
        {
            var restResponse = new RestResponse
            {
                Content     = OMNI_BODY,
                ContentType = "application/json",
                ResponseUri = new Uri("http://foo.com/omni/1.2.3.4"),
                StatusCode  = (HttpStatusCode)200
            };

            restResponse.ContentLength = restResponse.Content.Length;

            var restClient = MockRepository.GenerateStub <IRestClient>();

            restClient.Stub(r => r.Execute(Arg <IRestRequest> .Is.Anything)).Return(restResponse);

            var wsc = new WebServiceClient(0, "abcdef", new List <string> {
                "en"
            });
            var result = wsc.Country("1.2.3.4", restClient);

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.InstanceOf <CountryResponse>());
        }
        public static KeyValuePair <string, string> GetCodeFromIP(string ipaddress)
        {
            var foundCountry = new KeyValuePair <string, string>();

            if (!UserId.HasValue)
            {
                return(foundCountry);
            }

            var client = new WebServiceClient(UserId.Value, Sitecore.Configuration.Settings.GetSetting(Constants.Settings.MaxMindLicenseKey));

            try
            {
                var response = client.Country(ipaddress);

                foundCountry = new KeyValuePair <string, string>(response.Continent.Code, response.Country.IsoCode);
            }
            catch (Exception error)
            {
                Log.Error(string.Format("SharedSource.RedirectModule.MaxMind.WebServiceHelper {0}", error.Message), typeof(WebServiceHelper));
            }

            return(foundCountry);
        }
        public static KeyValuePair<string, string> GetCodeFromIP(string ipaddress)
        {
            var foundCountry = new KeyValuePair<string, string>();

            if (!UserId.HasValue)
            {
                return foundCountry;
            }

            var client = new WebServiceClient(UserId.Value, Sitecore.Configuration.Settings.GetSetting(Constants.Settings.MaxMindLicenseKey));

            try
            {
                var response = client.Country(ipaddress);

                foundCountry = new KeyValuePair<string, string>(response.Continent.Code, response.Country.IsoCode);
            }
            catch (Exception error)
            {
                Log.Error(string.Format("SharedSource.RedirectModule.MaxMind.WebServiceHelper {0}", error.Message), typeof(WebServiceHelper));
            }

            return foundCountry;
        }
        public void CorrectlyFormattedCountryResponseShouldDeserializeIntoResponseObject()
        {
            var restResponse = new RestResponse
            {
                Content = OMNI_BODY,
                ContentType = "application/json",
                ResponseUri = new Uri("http://foo.com/omni/1.2.3.4"),
                StatusCode = (HttpStatusCode)200
            };

            restResponse.ContentLength = restResponse.Content.Length;

            var restClient = MockRepository.GenerateStub<IRestClient>();

            restClient.Stub(r => r.Execute(Arg<IRestRequest>.Is.Anything)).Return(restResponse);

            var wsc = new WebServiceClient(0, "abcdef", new List<string> { "en" });
            var result = wsc.Country("1.2.3.4", restClient);

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.InstanceOf<CountryResponse>());
        }