twelve 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.md +220 -0
- data/Rakefile +8 -0
- data/lib/twelve.rb +32 -0
- data/lib/twelve/api/clients.rb +55 -0
- data/lib/twelve/api/gauges.rb +67 -0
- data/lib/twelve/api/gauges/content.rb +36 -0
- data/lib/twelve/api/gauges/engines.rb +32 -0
- data/lib/twelve/api/gauges/locations.rb +32 -0
- data/lib/twelve/api/gauges/referrers.rb +36 -0
- data/lib/twelve/api/gauges/resolutions.rb +32 -0
- data/lib/twelve/api/gauges/shares.rb +45 -0
- data/lib/twelve/api/gauges/technology.rb +32 -0
- data/lib/twelve/api/gauges/terms.rb +36 -0
- data/lib/twelve/api/gauges/traffic.rb +32 -0
- data/lib/twelve/api/me.rb +28 -0
- data/lib/twelve/connection.rb +26 -0
- data/lib/twelve/resource_proxy.rb +46 -0
- data/lib/twelve/version.rb +4 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/twelve/api/clients_spec.rb +43 -0
- data/spec/twelve/api/gauges/content_spec.rb +54 -0
- data/spec/twelve/api/gauges/engines_spec.rb +32 -0
- data/spec/twelve/api/gauges/locations_spec.rb +32 -0
- data/spec/twelve/api/gauges/referrers_spec.rb +54 -0
- data/spec/twelve/api/gauges/resolutions_spec.rb +36 -0
- data/spec/twelve/api/gauges/shares_spec.rb +74 -0
- data/spec/twelve/api/gauges/technology_spec.rb +36 -0
- data/spec/twelve/api/gauges/terms_spec.rb +52 -0
- data/spec/twelve/api/gauges/traffic_spec.rb +34 -0
- data/spec/twelve/api/gauges_spec.rb +119 -0
- data/spec/twelve/api/me_spec.rb +34 -0
- data/spec/twelve/connection_spec.rb +11 -0
- data/spec/twelve/resource_proxy_spec.rb +34 -0
- data/spec/twelve_spec.rb +16 -0
- data/twelve.gemspec +29 -0
- metadata +230 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Gauges module handles Gauges on Gauges
|
8
|
+
#
|
9
|
+
module Gauges
|
10
|
+
|
11
|
+
# The Engines module handles accessing search engines
|
12
|
+
#
|
13
|
+
module Engines
|
14
|
+
|
15
|
+
# Returns monthly engines for a gauge
|
16
|
+
#
|
17
|
+
# date - String of date
|
18
|
+
#
|
19
|
+
# Returns json
|
20
|
+
#
|
21
|
+
def engines(date=nil)
|
22
|
+
attributes = {}
|
23
|
+
|
24
|
+
connection.get do |request|
|
25
|
+
request.url "#{path_prefix}/engines"
|
26
|
+
request.params['date'] = date if date && date.is_a?(String)
|
27
|
+
end.body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Gauges module handles Gauges on Gauges
|
8
|
+
#
|
9
|
+
module Gauges
|
10
|
+
|
11
|
+
# The Locations module handles accessing locations
|
12
|
+
#
|
13
|
+
module Locations
|
14
|
+
|
15
|
+
# Returns monthly locations for a gauge
|
16
|
+
#
|
17
|
+
# date - String of date
|
18
|
+
#
|
19
|
+
# Returns json
|
20
|
+
#
|
21
|
+
def locations(date=nil)
|
22
|
+
attributes = {}
|
23
|
+
|
24
|
+
connection.get do |request|
|
25
|
+
request.url "#{path_prefix}/locations"
|
26
|
+
request.params['date'] = date if date && date.is_a?(String)
|
27
|
+
end.body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Gauges module handles Gauges on Gauges
|
8
|
+
#
|
9
|
+
module Gauges
|
10
|
+
|
11
|
+
# The Referrers module handles referrers
|
12
|
+
#
|
13
|
+
module Referrers
|
14
|
+
|
15
|
+
# Returns top content for a gauge
|
16
|
+
#
|
17
|
+
# *args - Date string & options hash
|
18
|
+
#
|
19
|
+
# Returns json
|
20
|
+
#
|
21
|
+
def referrers(*args)
|
22
|
+
attributes = {}
|
23
|
+
|
24
|
+
connection.get do |request|
|
25
|
+
request.url "#{path_prefix}/referrers"
|
26
|
+
|
27
|
+
args.each do |arg|
|
28
|
+
request.params['page'] = arg[:page].to_s if arg.is_a?(Hash) && arg.has_key?(:page)
|
29
|
+
request.params['date'] = arg if arg.is_a?(String)
|
30
|
+
end
|
31
|
+
end.body
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Gauges module handles Gauges on Gauges
|
8
|
+
#
|
9
|
+
module Gauges
|
10
|
+
|
11
|
+
# The Resolutions module handles accessing screen resolutions
|
12
|
+
#
|
13
|
+
module Resolutions
|
14
|
+
|
15
|
+
# Returns monthly screen sizes for a gauge
|
16
|
+
#
|
17
|
+
# date - String of date
|
18
|
+
#
|
19
|
+
# Returns json
|
20
|
+
#
|
21
|
+
def resolutions(date=nil)
|
22
|
+
attributes = {}
|
23
|
+
|
24
|
+
connection.get do |request|
|
25
|
+
request.url "#{path_prefix}/resolutions"
|
26
|
+
request.params['date'] = date if date && date.is_a?(String)
|
27
|
+
end.body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Gauges module handles Gauges on Gauges
|
8
|
+
#
|
9
|
+
module Gauges
|
10
|
+
|
11
|
+
# The Shares module handles sharing gauges
|
12
|
+
#
|
13
|
+
module Shares
|
14
|
+
|
15
|
+
# Get a list of users gauge is shared with
|
16
|
+
#
|
17
|
+
# Returns json
|
18
|
+
#
|
19
|
+
def shares
|
20
|
+
connection.get("#{path_prefix}/shares").body['shares']
|
21
|
+
end
|
22
|
+
|
23
|
+
# Shares a gauge with a person by their email
|
24
|
+
#
|
25
|
+
# email - String of email address
|
26
|
+
#
|
27
|
+
# Returns json
|
28
|
+
#
|
29
|
+
def share(email)
|
30
|
+
connection.post("#{path_prefix}/shares", email).body['share']
|
31
|
+
end
|
32
|
+
|
33
|
+
# Un-shares a gauge with a person by their email
|
34
|
+
#
|
35
|
+
# id - String of user id
|
36
|
+
#
|
37
|
+
# Returns json
|
38
|
+
#
|
39
|
+
def unshare(id)
|
40
|
+
connection.delete("#{path_prefix}/shares/#{id}").body['share']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Gauges module handles Gauges on Gauges
|
8
|
+
#
|
9
|
+
module Gauges
|
10
|
+
|
11
|
+
# The Technology module handles accessing browsers and platforms
|
12
|
+
#
|
13
|
+
module Technology
|
14
|
+
|
15
|
+
# Returns monthly browsers and platforms for a gauge
|
16
|
+
#
|
17
|
+
# date - String of date
|
18
|
+
#
|
19
|
+
# Returns json
|
20
|
+
#
|
21
|
+
def technology(date=nil)
|
22
|
+
attributes = {}
|
23
|
+
|
24
|
+
connection.get do |request|
|
25
|
+
request.url "#{path_prefix}/technology"
|
26
|
+
request.params['date'] = date if date && date.is_a?(String)
|
27
|
+
end.body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Gauges module handles Gauges on Gauges
|
8
|
+
#
|
9
|
+
module Gauges
|
10
|
+
|
11
|
+
# The Terms module handles search terms
|
12
|
+
#
|
13
|
+
module Terms
|
14
|
+
|
15
|
+
# Returns search terms for a gauge
|
16
|
+
#
|
17
|
+
# *args - Date string & options hash
|
18
|
+
#
|
19
|
+
# Returns json
|
20
|
+
#
|
21
|
+
def terms(*args)
|
22
|
+
attributes = {}
|
23
|
+
|
24
|
+
connection.get do |request|
|
25
|
+
request.url "#{path_prefix}/terms"
|
26
|
+
|
27
|
+
args.each do |arg|
|
28
|
+
request.params['page'] = arg[:page].to_s if arg.is_a?(Hash) && arg.has_key?(:page)
|
29
|
+
request.params['date'] = arg if arg.is_a?(String)
|
30
|
+
end
|
31
|
+
end.body
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Gauges module handles Gauges on Gauges
|
8
|
+
#
|
9
|
+
module Gauges
|
10
|
+
|
11
|
+
# The Traffic module handles accessing traffic
|
12
|
+
#
|
13
|
+
module Traffic
|
14
|
+
|
15
|
+
# Returns monthly traffic for a gauge
|
16
|
+
#
|
17
|
+
# date - String of date
|
18
|
+
#
|
19
|
+
# Returns json
|
20
|
+
#
|
21
|
+
def traffic(date=nil)
|
22
|
+
attributes = {}
|
23
|
+
|
24
|
+
connection.get do |request|
|
25
|
+
request.url "#{path_prefix}/traffic"
|
26
|
+
request.params['date'] = date if date && date.is_a?(String)
|
27
|
+
end.body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# API module encapsulates all of the API endpoints
|
4
|
+
#
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The Me module handles your information on Gauges
|
8
|
+
#
|
9
|
+
module Me
|
10
|
+
|
11
|
+
# Get and Update your information, accepts attributes
|
12
|
+
#
|
13
|
+
# attributes - Hash of attributes to update
|
14
|
+
#
|
15
|
+
# Returns json
|
16
|
+
#
|
17
|
+
def me(attributes=nil)
|
18
|
+
response = if attributes
|
19
|
+
connection.put('/me', attributes)
|
20
|
+
else
|
21
|
+
connection.get('/me')
|
22
|
+
end
|
23
|
+
|
24
|
+
response.body['user']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
class Twelve
|
6
|
+
class Connection < Faraday::Connection
|
7
|
+
attr_reader :access_token
|
8
|
+
|
9
|
+
# Instantiates connection, requires an access_token
|
10
|
+
#
|
11
|
+
# access_token - String of the access token
|
12
|
+
#
|
13
|
+
def initialize(access_token=nil)
|
14
|
+
@access_token = access_token
|
15
|
+
|
16
|
+
super('https://secure.gaug.es') do |builder|
|
17
|
+
builder.request :url_encoded
|
18
|
+
builder.use Faraday::Response::ParseJson
|
19
|
+
builder.adapter Faraday.default_adapter
|
20
|
+
end
|
21
|
+
|
22
|
+
self.headers["X-Gauges-Token"] = "#{access_token}" if access_token
|
23
|
+
self.headers["Accept"] = 'application/json'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Twelve
|
2
|
+
|
3
|
+
# ResourceProxy lets us create a virtual
|
4
|
+
# proxy for any API resource, utilizing
|
5
|
+
# method_missing to handle passing
|
6
|
+
# messages to the real object
|
7
|
+
#
|
8
|
+
class ResourceProxy
|
9
|
+
|
10
|
+
# Undefine methods that might get in the way
|
11
|
+
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval|instance_variable_get|object_id/ }
|
12
|
+
|
13
|
+
# Make connection and path_prefix readable
|
14
|
+
attr_reader :connection, :path_prefix, :attributes
|
15
|
+
|
16
|
+
# Instantiates proxy with the connection
|
17
|
+
# and path_prefix
|
18
|
+
#
|
19
|
+
# connection - Twelve::Connection object
|
20
|
+
# path_prefix - String
|
21
|
+
#
|
22
|
+
def initialize(connection, path_prefix, attributes=nil)
|
23
|
+
@connection, @path_prefix, @attributes = connection, path_prefix, attributes
|
24
|
+
end
|
25
|
+
|
26
|
+
# Method_missing takes any message passed
|
27
|
+
# to the ResourceProxy and sends it to the
|
28
|
+
# real object
|
29
|
+
#
|
30
|
+
# message - Message object
|
31
|
+
# args* - Arguements passed
|
32
|
+
#
|
33
|
+
def method_missing(message, *args)
|
34
|
+
subject.send(message, *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Subject is the response body parsed
|
38
|
+
# as json
|
39
|
+
#
|
40
|
+
# Returns json
|
41
|
+
#
|
42
|
+
def subject
|
43
|
+
raise "Implement in Proxy class for resource"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require :default, :test
|
4
|
+
require 'webmock/rspec'
|
5
|
+
require 'vcr'
|
6
|
+
require 'twelve'
|
7
|
+
|
8
|
+
VCR.config do |c|
|
9
|
+
c.cassette_library_dir = File.expand_path('../responses', __FILE__)
|
10
|
+
c.stub_with :webmock
|
11
|
+
c.default_cassette_options = {:record => :once}
|
12
|
+
end
|
13
|
+
|
14
|
+
token_file = File.expand_path('../.access_token', __FILE__)
|
15
|
+
ACCESS_TOKEN = File.exists?(token_file) ? File.read(token_file).strip : 'faketoken'
|
16
|
+
gauge_file = File.expand_path('../.gauge_id', __FILE__)
|
17
|
+
GAUGE_ID = File.exists?(gauge_file) ? File.read(gauge_file).strip : 'fakegaugeid'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Twelve::API::Clients do
|
4
|
+
subject { Twelve.new(ACCESS_TOKEN) }
|
5
|
+
|
6
|
+
def should_be_a_client(client)
|
7
|
+
client['created_at'].should_not be_nil
|
8
|
+
client['urls']['self'].should == "https://secure.gaug.es/clients/#{client['key']}"
|
9
|
+
client.should have_key('description')
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#clients" do
|
13
|
+
it "returns a list of your API clients" do
|
14
|
+
VCR.use_cassette('clients') do
|
15
|
+
clients = subject.clients
|
16
|
+
clients.should be_instance_of(Array)
|
17
|
+
clients.size.should > 0
|
18
|
+
should_be_a_client(clients.first)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#create" do
|
23
|
+
it "returns created client" do
|
24
|
+
VCR.use_cassette('clients_create') do
|
25
|
+
client = subject.clients.create(:description => "12 Gauge")
|
26
|
+
should_be_a_client(client)
|
27
|
+
# cleanup
|
28
|
+
subject.clients(client['key']).destroy
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#destroy" do
|
34
|
+
it "returns deleted client" do
|
35
|
+
VCR.use_cassette('clients_delete') do
|
36
|
+
delete = subject.clients.create(:description => "Testing Twelve")
|
37
|
+
client = subject.clients(delete['key']).destroy
|
38
|
+
should_be_a_client(client)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|