Lasso Soft Inc. > Home

[LEAP_geoPlugin]

LinkLEAP_geoPlugin
AuthorJonathan Guthrie
CategoryOutput
Version9.x
LicensePublic Domain
Posted01 Apr 2010
Updated01 Apr 2010
More by this author...

Description

This Lasso 9 data type uses the JSON Webservice of http://www.geoplugin.com/ to geolocate IP addresses See http://www.geoplugin.com/webservices/ for more specific details of this free service

Sample Usage

local(x = LEAP_geoPlugin)
#x->locate('202.20.7.214')

#x->city

'
$100 CAD = ' #x->convert(100.00)+' '+#x->currencyCode

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

 type {
	
	//the geoPlugin server
	data private host::string = 'http://www.geoplugin.net/json.gp?ip={IP}&base_currency={CURRENCY}'
		
	//the default base currency
	data 
		public currency::string = 'CAD'
	
	//initiate the geoPlugin vars
	 data
		public ip::string 					= '',
		public city::string 				= '',
		public region::string 				= '',
		public areaCode::string 			= '',
		public dmaCode::string 				= '',
		public countryCode::string 			= '',
		public countryName::string 			= '',
		public continentCode::string 		= '',
		public latitute::decimal 			= 0.000000,
		public longitude::decimal 			= 0.000000,
		public currencyCode::string 		= '',
		public currencySymbol::string 		= '',
		public currencyConverter::decimal 	= 1.000000

	public locate(ip::string='') => {
		
		#ip->size == 0 ? #ip = string(client_ip)
		.ip = #ip
		
		.host->replace('{IP}',#ip)
		.host->replace('{CURRENCY}',.currency)
		
		local(data = array)
		local(response = string(include_url(.host)))
		#response->removeleading('geoPlugin(')
		#response->removetrailing(')')		
		#data = json_deserialize(#response)

//		//set the geoPlugin vars
		.city 				= string(#data->find('geoplugin_city'))
		.region 			= string(#data->find('geoplugin_region'))
		.areaCode 			= string(#data->find('geoplugin_areaCode'))
		.dmaCode 			= string(#data->find('geoplugin_dmaCode'))
		.countryCode 		= string(#data->find('geoplugin_countryCode'))
		.countryName 		= string(#data->find('geoplugin_countryName'))
		.continentCode 		= string(#data->find('geoplugin_continentCode'))
//		.latitude 			= decimal(#data->find('geoplugin_latitude'))
//		.longitude 			= decimal(#data->find('geoplugin_longitude'))
		.currencyCode 		= string(#data->find('geoplugin_currencyCode'))
		.currencySymbol 	= string(#data->find('geoplugin_currencySymbol'))
		.currencyConverter 	= decimal(#data->find('geoplugin_currencyConverter'))
		
	}
	

	public convert(amount::decimal, float::integer=2, symbol::boolean=true) => {
		
		//easily convert amounts to geolocated currency.
		local(out =  decimal(#amount * .currencyConverter)->asString(-precision=#float))
		if(#symbol == true) => {
			return (.currencySymbol + #out)
		} else {
			return #out
		}
	}
	public convert(amount::any, float::integer=2, symbol::boolean=true) => {
		return ('geoPlugin Warning: The amount passed to geoPlugin::convert is not a decimal.')
	}

	
}


?>

Comments

No comments

Please log in to comment

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft