Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get locations for a gauge.

  • Loading branch information...
commit ad8c0687cb8378f1e4f54b9e33582b76ec24d0f0 1 parent ba492a8
@jonmagic authored
View
10 README.md
@@ -176,6 +176,16 @@ Get a specific month's search engines:
bfg.gauges('abcd1234').engines('2011-10-1')
+### Locations
+
+Get this month's locations for a gauge:
+
+ bfg.gauges('abcd1234').locations
+
+Get a specific month's locations:
+
+ bfg.gauges('abcd1234').locations('2011-10-1')
+
Testing
-------
View
1  lib/twelve.rb
@@ -12,6 +12,7 @@
require 'twelve/api/gauges/technology'
require 'twelve/api/gauges/terms'
require 'twelve/api/gauges/engines'
+require 'twelve/api/gauges/locations'
require 'twelve/api/gauges'
class Twelve
View
1  lib/twelve/api/gauges.rb
@@ -20,6 +20,7 @@ class Proxy < ::Twelve::ResourceProxy
include Twelve::API::Gauges::Technology
include Twelve::API::Gauges::Terms
include Twelve::API::Gauges::Engines
+ include Twelve::API::Gauges::Locations
# Creates a gauge
#
View
32 lib/twelve/api/gauges/locations.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 Locations module handles accessing locations
+ #
+ module Locations
+
+ # Returns monthly locations for a gauge
+ #
+ # date - String of date
+ #
+ # Returns json
+ #
+ def locations(date=nil)
+ attributes = {}
+
+ connection.get do |request|
+ request.url "#{path_prefix}/locations"
+ request.params['date'] = date if date && date.is_a?(String)
+ end.body
+ end
+ end
+ end
+ end
+end
View
32 spec/twelve/api/gauges/locations_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe Twelve::API::Gauges::Locations do
+ subject { Twelve.new(ACCESS_TOKEN) }
+
+ describe "#locations" do
+ context "with no args" do
+ it "should return locations" do
+ VCR.use_cassette('locations') do
+ response = subject.gauges(GAUGE_ID).locations
+ response['date'].should_not be_nil
+ response.should have_key('urls')
+
+ locations = response['locations']
+ locations.size.should > 0
+ locations.first['title'].should_not be_nil
+ locations.first['views'].should be_instance_of(Fixnum)
+ locations.first['key'].should_not be_nil
+ end
+ end
+ end
+
+ context "with a date" do
+ it "should return locations for that date" do
+ VCR.use_cassette('locations("2011-12-8")') do
+ response = subject.gauges(GAUGE_ID).locations('2011-12-8')
+ response['date'].should == '2011-12-08'
+ end
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.