Skip to content

Commit

Permalink
Get browsers and platforms for a gauge.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmagic committed Dec 9, 2011
1 parent a4d1784 commit 6ab01ce
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -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
-------

Expand Down
1 change: 1 addition & 0 deletions lib/twelve.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/twelve/api/gauges.rb
Expand Up @@ -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
#
Expand Down
32 changes: 32 additions & 0 deletions 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
36 changes: 36 additions & 0 deletions 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

0 comments on commit 6ab01ce

Please sign in to comment.