Hi all! In my app I want to detect what country a visitor is viewing from by their IP. Although it''s by no means perfect, the simplest option I''ve found is by using this site: http://api.hostip.info/ by passing the ip address as a query, this site returns an xml file with the country as one of the tags. http://api.hostip.info/?ip=6.255.255.255 returns (amongst other things) "<countryAbbrev>US</countryAbbrev>" Could somebody suggest the best way to assert the value of this particular tag in the xml file? Thanks Gavin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Hi all! > In my app I want to detect what country a visitor is viewing from by > their IP. > > Although it''s by no means perfect, the simplest option I''ve found is > by using this site: > http://api.hostip.info/ > > by passing the ip address as a query, this site returns an xml file > with the country as one of the tags. > > http://api.hostip.info/?ip=6.255.255.255 returns (amongst other > things) > "<countryAbbrev>US</countryAbbrev>" > > Could somebody suggest the best way to assert the value of this > particular tag in the xml file?hpricot or that new one... nokugirl (or something like that). I know hpricot can parse XML easily. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
require ''rubygems'' require ''hpricot'' require ''net/http'' html = Net::HTTP.get(URI.parse("http://api.hostip.info/?ip=6.255.255.255")) doc = Hpricot(html) country_abbrev = doc.search("countryabbrev") puts country_abbrev.inner_text() On Fri, Nov 28, 2008 at 9:05 AM, Philip Hallstrom <philip-LSG90OXdqQE@public.gmane.org> wrote:> > > Hi all! > > In my app I want to detect what country a visitor is viewing from by > > their IP. > > > > Although it''s by no means perfect, the simplest option I''ve found is > > by using this site: > > http://api.hostip.info/ > > > > by passing the ip address as a query, this site returns an xml file > > with the country as one of the tags. > > > > http://api.hostip.info/?ip=6.255.255.255 returns (amongst other > > things) > > "<countryAbbrev>US</countryAbbrev>" > > > > Could somebody suggest the best way to assert the value of this > > particular tag in the xml file? > > hpricot or that new one... nokugirl (or something like that). I know > hpricot can parse XML easily. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Exactly what I was looking for! Thanks for your help :) On 28 Nov, 01:28, "Song Ginger" <jiangsong1...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> require ''rubygems'' > require ''hpricot'' > require ''net/http'' > html = Net::HTTP.get(URI.parse("http://api.hostip.info/?ip=6.255.255.255")) > doc = Hpricot(html) > country_abbrev = doc.search("countryabbrev") > puts country_abbrev.inner_text() > > On Fri, Nov 28, 2008 at 9:05 AM, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: > > > > Hi all! > > > In my app I want to detect what country a visitor is viewing from by > > > their IP. > > > > Although it''s by no means perfect, the simplest option I''ve found is > > > by using this site: > > >http://api.hostip.info/ > > > > by passing the ip address as a query, this site returns an xml file > > > with the country as one of the tags. > > > >http://api.hostip.info/?ip=6.255.255.255returns (amongst other > > > things) > > > "<countryAbbrev>US</countryAbbrev>" > > > > Could somebody suggest the best way to assert the value of this > > > particular tag in the xml file? > > > hpricot or that new one... nokugirl (or something like that). I know > > hpricot can parse XML easily.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---