rails_url_shortener 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 20985bb8cc91463fdc5482bd63d3cc20f4d246bd061b2a3379183ab2ef00ebc3
         | 
| 4 | 
            +
              data.tar.gz: d84145481a224bbf71071da27a85a2a358190e487cceff531586daa6b245c8e8
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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  | 
| 19 | 
            -
             | 
| 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 | 
            -
                     | 
| 31 | 
            -
                     | 
| 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 | 
            -
             | 
| 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
         | 
    
        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. | 
| 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- | 
| 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. | 
| 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. | 
| 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: []
         |