rails_url_shortener 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6aeebf6acccb2b42410986eb0328a509bebf98a1615a60836804f8c62e525ecf
4
- data.tar.gz: 7a08775acadc07b9d0a12286056a02f496db98eebe6e87bc913c91d230f60d82
3
+ metadata.gz: 20985bb8cc91463fdc5482bd63d3cc20f4d246bd061b2a3379183ab2ef00ebc3
4
+ data.tar.gz: d84145481a224bbf71071da27a85a2a358190e487cceff531586daa6b245c8e8
5
5
  SHA512:
6
- metadata.gz: b38105a3f020cbf8304bf8a19f9db19c4ff6e1aa4b7f6364060a54d10d0d5d97094d17d39e2b96b0002325fe03816b899eb8a021f3bfa015186e93c871f1a08e
7
- data.tar.gz: 500fc4916e53ce218043ba388c9302f9010f614adf4ac90bb790b835792bb381192181eeb8beff8c8dd93825d736785cac84edf208843d1c2e67c6c712769020
6
+ metadata.gz: 9df5be0690db7d0939e18a1db2ae9aeb68f243cbc4e1a99ea908ac59099c835b09ebbe89e64c4ba237065419e2de82115519a195d723942452943a5bb58fc298
7
+ data.tar.gz: 2a2e9fc7fc7180ba824aee0080c65bf1729915171a93ade15f97dd36ade234f39750fe713ed89a83a4fcb0a21d6f7b92d0dab6b95eda4ecfe62c20e3e00de62e
@@ -11,32 +11,17 @@ module RailsUrlShortener
11
11
  # this function get the ip related data
12
12
  #
13
13
  # create or update an existing record information for an ip
14
-
15
14
  def perform(visit)
16
15
  if Ipgeo.exists?(ip: visit.ip)
17
16
  ipgeo = Ipgeo.find_by(ip: visit.ip)
18
- if Ipgeo.find_by(ip: visit.ip).updated_at <= 3.months.ago
19
- # Then update
20
- ip = HTTP.get("http://ip-api.com/json/#{visit.ip}?fields=status,message,country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,mobile,proxy,hosting,query")
21
- if ip.code == 200
22
- ipgeo.update(JSON.parse(ip.body).transform_keys { |key| key.to_s.underscore }.slice(*Ipgeo.column_names))
23
- visit.update(ipgeo: ipgeo)
24
- end
25
- else
26
- visit.update(ipgeo: ipgeo)
27
- end
17
+ # update if older than three months
18
+ ipgeo.update_from_remote if ipgeo.updated_at <= 3.months.ago
28
19
  elsif !Ipgeo.exists?(ip: visit.ip)
29
20
  # Then create a new record
30
- ip = HTTP.get("http://ip-api.com/json/#{visit.ip}?fields=status,message,country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,mobile,proxy,hosting,query")
31
- if ip.code == 200
32
- ipgeo = Ipgeo.new(JSON.parse(ip.body).transform_keys { |key| key.to_s.underscore }.slice(*Ipgeo.column_names))
33
- ipgeo.ip = JSON.parse(ip.body)['query']
34
- ipgeo.save
35
- visit.update(ipgeo: ipgeo)
36
- end
21
+ ipgeo = Ipgeo.create(ip: visit.ip)
22
+ ipgeo.update_from_remote
37
23
  end
38
- rescue StandarError => e
39
- Rails.logger.debug { "Error#{e}" }
24
+ visit.update(ipgeo: ipgeo) unless ipgeo.nil?
40
25
  end
41
26
  end
42
27
  end
@@ -3,5 +3,12 @@
3
3
  module RailsUrlShortener
4
4
  class Ipgeo < ApplicationRecord
5
5
  has_many :visits, dependent: :nullify
6
+
7
+ def update_from_remote
8
+ @ip = HTTP.get("http://ip-api.com/json/#{ip}?fields=status,message,country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,mobile,proxy,hosting,query")
9
+ return unless @ip.code == 200
10
+
11
+ update(JSON.parse(@ip.body).transform_keys { |key| key.to_s.underscore }.slice(*Ipgeo.column_names))
12
+ end
6
13
  end
7
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsUrlShortener
4
- VERSION = '0.2.5'
4
+ VERSION = '0.2.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_url_shortener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-20 00:00:00.000000000 Z
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: browser
@@ -87,9 +87,9 @@ licenses:
87
87
  - GPL-3.0
88
88
  metadata:
89
89
  bug_tracker_uri: https://www.github.com/a-chacon/rails-url-shortener/issues
90
- changelog_uri: https://www.github.com/a-chacon/rails-url-shortener/releases/tag/v0.2.5
90
+ changelog_uri: https://www.github.com/a-chacon/rails-url-shortener/releases/tag/v0.2.6
91
91
  documentation_uri: https://github.com/a-chacon/rails-url-shortener/blob/main/README.md
92
- source_code_uri: https://github.com/a-chacon/rails-url-shortener/tree/v0.2.5
92
+ source_code_uri: https://github.com/a-chacon/rails-url-shortener/tree/v0.2.6
93
93
  rubygems_mfa_required: 'true'
94
94
  post_install_message:
95
95
  rdoc_options: []