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.94 lib/knj/ip2location.rb
knjrbfw-0.0.93 lib/knj/ip2location.rb
knjrbfw-0.0.92 lib/knj/ip2location.rb
knjrbfw-0.0.91 lib/knj/ip2location.rb
knjrbfw-0.0.90 lib/knj/ip2location.rb
knjrbfw-0.0.89 lib/knj/ip2location.rb
knjrbfw-0.0.88 lib/knj/ip2location.rb
knjrbfw-0.0.87 lib/knj/ip2location.rb
knjrbfw-0.0.86 lib/knj/ip2location.rb
knjrbfw-0.0.85 lib/knj/ip2location.rb
knjrbfw-0.0.84 lib/knj/ip2location.rb
knjrbfw-0.0.83 lib/knj/ip2location.rb
knjrbfw-0.0.82 lib/knj/ip2location.rb
knjrbfw-0.0.81 lib/knj/ip2location.rb
knjrbfw-0.0.80 lib/knj/ip2location.rb
knjrbfw-0.0.79 lib/knj/ip2location.rb
knjrbfw-0.0.78 lib/knj/ip2location.rb
knjrbfw-0.0.77 lib/knj/ip2location.rb
knjrbfw-0.0.75 lib/knj/ip2location.rb
knjrbfw-0.0.74 lib/knj/ip2location.rb