Sha256: 25883f4d4c193bb18384408182b705a0f4d8ce84239677d8bc50cc2dd9b90c9e

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module ReTrack
  module SessionData
    ATTRIBUTES = [
      :referer_url, :first_url, :user_agent, :first_visited_at, :ip,
      :accept_language, :forwarded_ip
    ]

    def to_hash(request)
      @request = request
      Hash[ATTRIBUTES.map { |k, v| [k, send(k)] }]
    end

    private

      def referer_url
        @request.headers['HTTP_REFERER'].presence || 'none'
      end

      def first_url
        @request.url
      end

      def user_agent
        @request.env['HTTP_USER_AGENT']
      end

      def first_visited_at
        Time.now
      end

      def ip
        Digest::SHA1.hexdigest(@request.remote_ip + ip_secret)
      end

      def accept_language
        @request.env['HTTP_ACCEPT_LANGUAGE']
      end

      def forwarded_ip
        forwarded_ip = @request.env['HTTP_X_FORWARDED_FOR'] ||
          @request.env['HTTP_CLIENT_IP']
        Digest::SHA1.hexdigest(forwarded_ip + ip_secret)
      end

      def ip_secret
        ENV['ENCRYPT_IP_SECRET'] || ''
      end

    extend self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
re_track-0.7.0 lib/re_track/session_data.rb