ankane / authtrail

Track Devise login activity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Geocoder job not storing lat/lng

rdlugosz opened this issue · comments

Hi - I'm seeing an issue where the IP geocoding job isn't storing the lat/lng for my AuthTrail records, but it is storing the city/state/country. I've added a latitude/longitude field to my login_activities table, and verified that the Geocoder I'm using responds to the necessary methods:

[4] pry(main)> r = Geocoder.search("4.4.4.4").first
=> #<Geocoder::Result::IpinfoIo:0x00007ffeac90e748
 @cache_hit=true,
 @data=
  {"ip"=>"4.4.4.4",
   "city"=>"Broomfield",
   "region"=>"Colorado",
   "country"=>"US",
   "loc"=>"39.8854,-105.1139",
   "postal"=>"80021",
   "timezone"=>"America/Denver"}>
[5] pry(main)> r.try(:latitude)
=> 39.8854

[11] pry(main)> LoginActivity.new
=> #<LoginActivity:0x00007ffeb03058c0
 id: nil,
 scope: nil,
 strategy: nil,
 identity: nil,
 success: nil,
 failure_reason: nil,
 user_id: nil,
 user_type: nil,
 context: nil,
 ip: nil,
 user_agent: nil,
 referrer: nil,
 city: nil,
 region: nil,
 country: nil,
 created_at: nil,
 latitude: nil,
 longitude: nil>

That seems to be all the geocoding job would need in order to store the lat/lng, but I'm only seeing city, etc. I can poke around further, but any thoughts as to what I'm missing here?

Here's an example with real data:

irb(main):009:0> ap LoginActivity.last
#<LoginActivity:0x00007f402cd62b80> {
                :id => 4356,
             :scope => "user",
          :strategy => "rememberable",
          :identity => "user@foo.com",
           :success => true,
    :failure_reason => nil,
           :user_id => 7346438,
         :user_type => "User",
           :context => "foo#home",
                :ip => "75.67.123.138",
        :user_agent => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36",
          :referrer => nil,
              :city => "Plymouth",
            :region => "Massachusetts",
           :country => "US",
        :created_at => Wed, 22 Apr 2020 23:22:19 UTC +00:00,
          :latitude => nil,
         :longitude => nil
}
=> nil

irb(main):014:0> ap Geocoder.search("75.67.123.138").first.data
{
          "ip" => "75.67.123.138",
        "city" => "Plymouth",
      "region" => "Massachusetts",
     "country" => "US",
         "loc" => "41.9584,-70.6673",
      "postal" => "02362",
    "timezone" => "America/New_York"
}
=> nil
irb(main):016:0> Geocoder.search("75.67.123.138").first.latitude
=> 41.9584

Hey @rdlugosz, I'd confirm you're on version 0.2.0.

ha! yep, that's the problem alright. Stuck at 0.1.3 until I get the Rails 5 upgrade done, I guess.

Thanks for looking!