A Developer with a Pencil

RubygemsCounter.js - Show Your Gem Total Downloads From Rubygems

In past couple of weeks we @ ShinobiDevs were super busy building a couple of gems. Today, after releasing TheCart we thought it would be nice to have a little bit of statistics from RubyGems.org on the relevant gem blog posts.

So, here is a RubyGems Javascript widget that simply queries the RubyGems.org API and shows the number of downloads that gem has.

How to use it.

Simply add the following line into your HTML head section:

1
  <script src="http://rubygemscounter.herokuapp.com/rubygems.js"></script>

and use the following script to grab the gem details:

1
2
3
4
  <div id="gem_info"></div>
  <script type="text/javascript">
    Rubygems.fetch("gem_info", "the_cart-0.0.1");
  </script>

This will fill in the container (gem_info element) the following HTML element:

1
2
3
<div id='rubygems_total_downloads'>
  The <a href='https://rubygems.org/gems/the_cart' target='_blank'>the_cart</a> gem has xxx downloads.
</div>

kind of like this:

Contribute

Code is available right here

Comments