Convert code from PHP to Ruby on Rails -


I am trying to use GOIP's web service for Ruby applications. They do not offer any Ruby demos, but they give it to PHP. I was wondering if anyone knew how to change this to work on Ruby on Rail? I only need data from city and city. More examples can be found on their site at

  $ query = "http://geoip3.maxmind.com/b?l=". $ License_key "& Amp; i =". $ IPADDRESS; $ Url = parse_url ($ query); $ Host = $ url ["Host"]; $ Path = $ url ["path"] "?" . $ Url ["Query"]; $ Timeout = 1; $ Fp = fsockopen ($ host, $ 80, errno, $ errstr, $ timeout) or die ('Can not open connection to server'.); If ($ fp) {fputs ($ fp, "GET $ Path HTTP / 1.0 \ nhost:". $ Host. "\ N \ n"); While (! FIF ($ FP)) {$ buf = fgets ($ fp, 128); } $ Lines = split ("\ n", $ buf); $ Data = $ rows [count ($ rows) -1]; Fclose ($ FP); } And {# error handing the code here} $ echoing the data; $ Geo = Explosion (",", $ data); $ Country = $ geographical [0]; $ State = $ geographical [1]; $ City = $ geo [2]; $ Lat = $ geo [3]; $ Lane = $ geographical [4];  

I do not have a geographical license key, so it will not be fully tested But it should work:

  is required 'net / http' url = 'http://geoip3.maxmind.com/b?l=%s&i= % S '% [license_key, ip_address] Res = Net :: HTTP.get_response (URI.parse (url)) line = res.body.split ("\ n") geo = lines [-1] .split (', ') Country = Geo [0] state = Geo [1] city = geo [2] late = geo [3] law = geo [4]  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -