-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Twelve | ||
|
||
# API module encapsulates all of the API endpoints | ||
# | ||
module API | ||
|
||
# The Gauges module handles Gauges on Gauges | ||
# | ||
module Gauges | ||
|
||
# The Referrers module handles referrers | ||
# | ||
module Referrers | ||
|
||
# Returns top content for a gauge | ||
# | ||
# *args - Date string & options hash | ||
# | ||
# Returns json | ||
# | ||
def referrers(*args) | ||
attributes = {} | ||
|
||
connection.get do |request| | ||
request.url "#{path_prefix}/referrers" | ||
|
||
args.each do |arg| | ||
request.params['page'] = arg[:page].to_s if arg.is_a?(Hash) && arg.has_key?(:page) | ||
request.params['date'] = arg if arg.is_a?(String) | ||
end | ||
end.body | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'spec_helper' | ||
|
||
describe Twelve::API::Gauges::Referrers do | ||
subject { Twelve.new(ACCESS_TOKEN) } | ||
|
||
describe "#referrers" do | ||
context "with no args" do | ||
it "should return todays referrers" do | ||
VCR.use_cassette('referrers') do | ||
response = subject.gauges(GAUGE_ID).referrers | ||
response['date'].should_not be_nil | ||
response['page'].should == 1 | ||
response['per_page'].should == 50 | ||
response.should have_key('urls') | ||
|
||
referrers = response['referrers'] | ||
referrers.size.should > 0 | ||
referrers.first['url'].should_not be_nil | ||
referrers.first['views'].should be_instance_of(Fixnum) | ||
referrers.first['path'].should_not be_nil | ||
referrers.first['host'].should_not be_nil | ||
end | ||
end | ||
end | ||
|
||
context "with page number" do | ||
it "should return content for page" do | ||
VCR.use_cassette('referrers(:page => 2)') do | ||
response = subject.gauges(GAUGE_ID).referrers(:page => 2) | ||
response['page'].should == 2 | ||
end | ||
end | ||
end | ||
|
||
context "with a date" do | ||
it "should return content for that date" do | ||
VCR.use_cassette('referrers("2011-12-8")') do | ||
response = subject.gauges(GAUGE_ID).referrers('2011-12-8') | ||
response['date'].should == '2011-12-08' | ||
end | ||
end | ||
end | ||
|
||
context "with a date and page" do | ||
it "should return content for that date" do | ||
VCR.use_cassette('referrers("2011-12-8", :page => 2)') do | ||
response = subject.gauges(GAUGE_ID).referrers('2011-12-8', :page => 2) | ||
response['date'].should == '2011-12-08' | ||
response['page'].should == 2 | ||
end | ||
end | ||
end | ||
end | ||
end |