diff --git a/README.md b/README.md index ce622ae..bb156f7 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,16 @@ Get a specific month's screen sizes: bfg.gauges('abcd1234').traffic('2011-10-1') +### Technology + +Get browsers and platforms for a gauge: + + bfg.gauges('abcd1234').technology + +Get a specific month's technology: + + bfg.gauges('abcd1234').technology('2011-10-1') + Testing ------- diff --git a/lib/twelve.rb b/lib/twelve.rb index 83e0f48..f21a97e 100644 --- a/lib/twelve.rb +++ b/lib/twelve.rb @@ -9,6 +9,7 @@ require 'twelve/api/gauges/referrers' require 'twelve/api/gauges/traffic' require 'twelve/api/gauges/resolutions' +require 'twelve/api/gauges/technology' require 'twelve/api/gauges' class Twelve diff --git a/lib/twelve/api/gauges.rb b/lib/twelve/api/gauges.rb index 5fd0c8b..d81e581 100644 --- a/lib/twelve/api/gauges.rb +++ b/lib/twelve/api/gauges.rb @@ -17,6 +17,7 @@ class Proxy < ::Twelve::ResourceProxy include Twelve::API::Gauges::Referrers include Twelve::API::Gauges::Traffic include Twelve::API::Gauges::Resolutions + include Twelve::API::Gauges::Technology # Creates a gauge # diff --git a/lib/twelve/api/gauges/technology.rb b/lib/twelve/api/gauges/technology.rb new file mode 100644 index 0000000..7e365bc --- /dev/null +++ b/lib/twelve/api/gauges/technology.rb @@ -0,0 +1,32 @@ +class Twelve + + # API module encapsulates all of the API endpoints + # + module API + + # The Gauges module handles Gauges on Gauges + # + module Gauges + + # The Technology module handles accessing browsers and platforms + # + module Technology + + # Returns monthly browsers and platforms for a gauge + # + # date - String of date + # + # Returns json + # + def technology(date=nil) + attributes = {} + + connection.get do |request| + request.url "#{path_prefix}/technology" + request.params['date'] = date if date && date.is_a?(String) + end.body + end + end + end + end +end diff --git a/spec/twelve/api/gauges/technology_spec.rb b/spec/twelve/api/gauges/technology_spec.rb new file mode 100644 index 0000000..115fff7 --- /dev/null +++ b/spec/twelve/api/gauges/technology_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Twelve::API::Gauges::Technology do + subject { Twelve.new(ACCESS_TOKEN) } + + describe "#technology" do + context "with no args" do + it "should return top technology" do + VCR.use_cassette('technology') do + response = subject.gauges(GAUGE_ID).technology + response['date'].should_not be_nil + response.should have_key('urls') + + browsers = response['browsers'] + browsers.first['title'].should_not be_nil + browsers.first['views'].should be_instance_of(Fixnum) + browsers.first['versions'].size.should > 0 + browsers.first['key'].should_not be_nil + platforms = response['platforms'] + platforms.first['title'].should_not be_nil + platforms.first['views'].should be_instance_of(Fixnum) + platforms.first['key'].should_not be_nil + end + end + end + + context "with a date" do + it "should return technology for that date" do + VCR.use_cassette('technology("2011-12-8")') do + response = subject.gauges(GAUGE_ID).technology('2011-12-8') + response['date'].should == '2011-12-08' + end + end + end + end +end