1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<?LassoScript
// ==================================
/*
@author Jonathan Guthrie (jono@treefrog.ca)
@copyright Copyright Treefrog Interactive (support@treefrog.ca)
#version 1.00
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
*/
// ==================================
define LEAP_geoPlugin => 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.')
}
}
?>
|