11var _ipgeolocation = function ( ) {
22 var useSessionStorage = false ;
33 var asyncCall = true ;
4+ var isHostname = false ;
5+ var isLiveHostname = false ;
6+ var isHostnameFallbackLive = false ;
7+ var isSecurity = false ;
8+ var isUserAgent = false ;
49 var ipAddress = "" ;
510 var excludes = "" ;
611 var fields = "" ;
712 var lang = "en" ;
813 var tz = "" ;
914 var latitude = "" ;
1015 var longitude = "" ;
16+ var location = "" ;
1117 var geolocationEndpoint = "ipgeo" ;
1218 var timezoneEndpoint = "timezone" ;
19+ var useragentEndpoint = "user-agent" ;
1320 var geolocationResponseName = "_ipgeolocation_geolocation" ;
1421 var timezoneResponseName = "_ipgeolocation_timezone" ;
22+ var useragentResponseName = "_ipgeolocation_useragent" ;
1523
1624 function request ( subUrl , callback , apiKey = "" ) {
1725 if ( useSessionStorage ) {
@@ -21,6 +29,9 @@ var _ipgeolocation = function() {
2129 } else if ( subUrl == timezoneEndpoint && sessionStorage . getItem ( timezoneResponseName ) && callback ) {
2230 callback ( JSON . parse ( sessionStorage . getItem ( timezoneResponseName ) ) ) ;
2331 return ;
32+ } else if ( subUrl == useragentEndpoint && sessionStorage . getItem ( useragentResponseName ) && callback ) {
33+ callback ( JSON . parse ( sessionStorage . getItem ( useragentResponseName ) ) ) ;
34+ return ;
2435 }
2536 }
2637
@@ -46,7 +57,37 @@ var _ipgeolocation = function() {
4657 if ( excludes ) {
4758 urlParameters = addUrlParameter ( urlParameters , "excludes" , excludes ) ;
4859 }
49-
60+
61+ if ( isHostname || isSecurity || isUserAgent ) {
62+ var val = "" ;
63+ var includeHost = false ;
64+ if ( isHostname ) {
65+ val = "hostname" ;
66+ includeHost = true ;
67+ } else if ( isHostnameFallbackLive ) {
68+ val = "hostnameFallbackLive" ;
69+ includeHost = true ;
70+ } else if ( isLiveHostname ) {
71+ val = "liveHostname" ;
72+ includeHost = true ;
73+ }
74+ if ( isSecurity ) {
75+ if ( includeHost ) {
76+ val = val + ",security" ;
77+ } else {
78+ val = "security" ;
79+ }
80+ }
81+ if ( isUserAgent ) {
82+ if ( includeHost || isSecurity ) {
83+ val = val + ",useragent" ;
84+ } else {
85+ val = "useragent" ;
86+ }
87+ }
88+ urlParameters = addUrlParameter ( urlParameters , "include" , val ) ;
89+ }
90+
5091 if ( lang ) {
5192 urlParameters = addUrlParameter ( urlParameters , "lang" , lang ) ;
5293 }
@@ -59,6 +100,10 @@ var _ipgeolocation = function() {
59100 urlParameters = addUrlParameter ( urlParameters , "lat" , latitude ) ;
60101 urlParameters = addUrlParameter ( urlParameters , "long" , longitude ) ;
61102 }
103+
104+ if ( location ) {
105+ urlParameters = addUrlParameter ( urlParameters , "location" , location ) ;
106+ }
62107
63108 var httpRequest ;
64109
@@ -108,10 +153,23 @@ var _ipgeolocation = function() {
108153 makeAsyncCallsToAPI : function ( a = true ) {
109154 asyncCall = a ;
110155 } ,
111- setIPAddress : function ( ip = "" ) {
112- ipAddress = ip ;
156+ includeHostname : function ( h = false ) {
157+ isHostname = h ;
158+ } ,
159+ includeHostnameFallbackLive : function ( h = false ) {
160+ isHostnameFallbackLive = h ;
161+ } ,
162+ includeLiveHostname : function ( h = false ) {
163+ isLiveHostname = h ;
164+ } ,
165+ includeSecurity : function ( s = false ) {
166+ isSecurity = s ;
167+ } ,
168+ includeUserAgent : function ( u = false ) {
169+ isUserAgent = u ;
113170 } ,
114171 setFields : function ( f = "" ) {
172+ console . log ( "set" ) ;
115173 fields = f ;
116174 } ,
117175 setExcludes : function ( e = "" ) {
@@ -120,18 +178,27 @@ var _ipgeolocation = function() {
120178 setLanguage : function ( l = "en" ) {
121179 lang = l ;
122180 } ,
181+ setIPAddress : function ( ip = "" ) {
182+ ipAddress = ip ;
183+ } ,
123184 setTimeZone : function ( t = "" ) {
124185 tz = t ;
125186 } ,
126- setCoordinates : function ( latitude = "" , longitude = "" ) {
127- latitudeParameter = latitude ;
128- longitudeParameter = longitude ;
187+ setCoordinates : function ( la = "" , lo = "" ) {
188+ latitude = la ;
189+ longitude = lo ;
190+ } ,
191+ setLocation : function ( loc = "" ) {
192+ location = loc ;
129193 } ,
130194 getGeolocation : function ( callback , apiKey = "" ) {
131195 request ( geolocationEndpoint , callback , apiKey ) ;
132196 } ,
133197 getTimezone : function ( callback , apikey = "" ) {
134198 request ( timezoneEndpoint , callback , apikey ) ;
199+ } ,
200+ getUserAgent : function ( callback , apikey = "" ) {
201+ request ( useragentEndpoint , callback , apikey ) ;
135202 }
136- }
203+ } ;
137204} ( ) ;
0 commit comments