Sha256: 947e343053a5fbbc415d09e725280fb29b992ef53824dc011ccaa8d16272c61c

Contents?: true

Size: 490 Bytes

Versions: 101

Compression:

Stored size: 490 Bytes

Contents

class Knj::Ip2location
  def initialize(args = {})
    @args = args
    @http = Knj::Http.new(
      "host" => "www.ip2location.com",
      "port" => 80
    )
  end
  
  def lookup(ip)
    raise "Invalid IP: #{ip}." if !ip.to_s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
    
    html = @http.get("/#{ip}")["data"]
    ret = {}
    
    html.scan(/<span id="dgLookup__ctl2_lblI(.+?)">(.+?)<\/span>/) do |match|
      ret[match[0]] = match[1]
    end
    
    return ret
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
knjrbfw-0.0.116 lib/knj/ip2location.rb
knjrbfw-0.0.115 lib/knj/ip2location.rb
knjrbfw-0.0.114 lib/knj/ip2location.rb
knjrbfw-0.0.113 lib/knj/ip2location.rb
knjrbfw-0.0.111 lib/knj/ip2location.rb
knjrbfw-0.0.110 lib/knj/ip2location.rb
knjrbfw-0.0.109 lib/knj/ip2location.rb
knjrbfw-0.0.108 lib/knj/ip2location.rb
knjrbfw-0.0.107 lib/knj/ip2location.rb
knjrbfw-0.0.105 lib/knj/ip2location.rb
knjrbfw-0.0.104 lib/knj/ip2location.rb
knjrbfw-0.0.103 lib/knj/ip2location.rb
knjrbfw-0.0.102 lib/knj/ip2location.rb
knjrbfw-0.0.101 lib/knj/ip2location.rb
knjrbfw-0.0.100 lib/knj/ip2location.rb
knjrbfw-0.0.99 lib/knj/ip2location.rb
knjrbfw-0.0.98 lib/knj/ip2location.rb
knjrbfw-0.0.97 lib/knj/ip2location.rb
knjrbfw-0.0.96 lib/knj/ip2location.rb
knjrbfw-0.0.95 lib/knj/ip2location.rb