go_squared gem

What is it?

A Ruby gem wrapping the gosquared.com API.

Who should use it?

Any Ruby on Rails developer who wants/needs to load trends from GoSquared Statistics.

Usage

Installation

gem install go_squared

Initialization

Initialize the connection for a given site:

@gs = GoSquared.new('Your API Key', 'GSN-123456-A')

Metrics

To fetch the pageviews metric simply do:

@pageviews = @gs.trends.pageviews

All available metrics are:

Method chain

By default trends form one month ago until now are fetched. To get a custom timeframe:

@pageviews = @gs.trends.pageviews.from(14.days.ago).to(7.days.ago)

All chainable methods are:

Fetch data

Up till now no data has been fetched. To get the raw XML:

@xml = @pageviews.xml

To get an array of ruby Hashes with symbolized keys:

@stats = @pageviews.from_xml

The latter will return something like:

{:hits=>"41", :uniques=>"28", :stat_start=>"1298736000", :time_grouping=>"2011057", :display_time=>"Sat, 26 Feb 11"}
{:hits=>"126", :uniques=>"77", :stat_start=>"1298764800", :time_grouping=>"2011058", :display_time=>"Sun, 27 Feb 11"}
{:hits=>"105", :uniques=>"56", :stat_start=>"1298851200", :time_grouping=>"2011059", :display_time=>"Mon, 28 Feb 11"}
...

Important

This gem is written for Rails 3. Rails 2 might work but it’s not tested.

Note that this gem is still under development. It only covers the trends section of the gosquared.com API.

Contributing to go_squared

Copyright © 2011 Wout Fierens. See LICENSE.txt for further details.