0.0
There's a lot of open issues
A long-lived project that still receives updates
Why roast this chestnut by that open fire, you ask? Cause thousands and thousands of Internet vets are still using the one we wrote in PHP eons ago and we don't want to be squandering any incidental Google juice, that's why.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

HitCounter

Build status Code Climate Coveralls CII Best Practices OpenSSF Scorecard Gem Version

Self-hosted Ruby version of that old 90s chestnut, <BLINK>the web-site hit counter</BLINK>.

Installation

  1. Install the gem and supporting files.

    Gemfile

      gem 'hit_counter'

    Run:

      bundle
      rake hit_counter:install

    Security note

    HitCounter is cryptographically signed. To insure the gem you install hasn’t been tampered with, add my public key as a trusted certificate and then install:

    gem cert --add <(curl -Ls https://raw.github.com/FoveaCentral/hit_counter/master/certs/ivanoblomov.pem)
    gem install hit_counter -P HighSecurity
  2. Add a controller action to your app.

    application_controller.rb

      def hit_counter
        return if params[:url].blank?
    
        # find or create a hit counter for this URL
        hc = HitCounter.get params[:url]
    
        # increase the tally by one
        hc.increment
    
        # get the image as a blob and stream it to the browser
        send_data hc.image(params[:style]).to_blob,
                  disposition: 'inline',
                  filename: "#{hc.hits}.png",
                  type: :png
     end

    routes.rb

     get 'hit-counter' => 'application#hit_counter'
     # technically should be POST/PUT, but GET makes integration simpler
  3. Add the hit-counter image tag to your site's HTML:

      <img alt="Hit Counter" border="0" src="/hit-counter?url=https://cnn.com&style=1" />

Or try it out in irb with:

require './spec/spec_helper'
hc = HitCounter.get('cnn.com')

Customizing the Hit-Counter Image

Use an Existing Style

Name Style number
Celtic image of 3 in celtic style
Odometer image of 1 in odometer style
Scout image of 2 in scout style

You can use one of the three included styles by specifying a different style param in the HTML:

  <img alt="Hit Counter" border="0" src="/hit-counter?url=cnn.com&style=1" />

Create Your Own Style

  1. To add your own style, create a PNG for each of the digits, 0.png through 9.png. Save the images in a folder named after your new style in public/images/digits.

  2. In your controller, declare a new STYLES constant and add the folder name to it:

      HitCounter::STYLES = %w(odometer scout celtic folder_name)
  3. In your HTML, specify the new style with a style param equal to its index in the array plus one (unlike arrays, the style param's index is one-based):

      <img alt="Hit Counter" border="0" src="/hit-counter?url=cnn.com&style=4" />

Documentation

Complete RDoc documentation is available at RubyDoc.info.

Cheers!

Buy Me A Coffee

Copyright

Copyright © 2011-2024 Roderick Monje. See LICENSE.txt for further details.