simple_analytics 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,4 +3,4 @@
3
3
  vendor/bundle
4
4
  bin
5
5
  pkg/*
6
-
6
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
data/Gemfile CHANGED
@@ -1,8 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  group :test do
4
- gem "rake", "~> 0.9.2.2"
4
+ gem 'rake'
5
5
  end
6
6
 
7
- # Specify your gem's dependencies in simple_analytics.gemspec
8
7
  gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Andrew Djoga
1
+ Copyright (c) 2012-2013 Andrew Djoga
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # SimpleAnalytics
2
+ [![Build Status](https://secure.travis-ci.org/Djo/simple_analytics.png "Build Status")](http://travis-ci.org/Djo/simple_analytics)
3
+
4
+ *SimpleAnalytics* gem provides accessing Google Analytics Export Api. It uses Version 3.0 of the Google Core Reporting API with JSON. You can find the google documentation [here](http://code.google.com/apis/analytics/docs/gdata/v3/gdataGettingStarted.html).
5
+
6
+ ## Getting Started
7
+
8
+ You can add it to your Gemfile with:
9
+
10
+ ```ruby
11
+ gem 'simple_analytics'
12
+ ```
13
+
14
+ Authentication using the *ClientLogin*:
15
+
16
+ ```ruby
17
+ analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')
18
+ ```
19
+
20
+ The `authenticate` method sets an `auth_token` in the analytics service object. Then you can fetch the report data:
21
+
22
+ ```ruby
23
+ analytics.fetch(
24
+ 'ids' => 'ga:id',
25
+ 'metrics' => 'ga:visitors',
26
+ 'dimensions' => 'ga:country',
27
+ 'start-date' => '2012-01-01',
28
+ 'end-date' => '2012-01-10'
29
+ )
30
+ # => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]]
31
+ ```
32
+
33
+ The `fetch` method sets and returns rows. Required query parameters are used to configure which data to return from the Google Analytics:
34
+
35
+ * **ids** — The profile IDs from which to access data.
36
+ * **start-date** — The beginning of the date range.
37
+ * **end-date** — The end of the date range.
38
+ * **metrics** — The numeric values to return.
39
+
40
+ For more detailed information about the parameters see [google REST docs](http://code.google.com/apis/analytics/docs/gdata/v3/exportRest.html).
41
+
42
+ ## Authentication
43
+
44
+ For the authentication it uses gem [google_client_login](https://github.com/fortuity/google_client_login) based on the *ClientLogin*. You can also pass extra parameters which allows the gem (see the gem's [README](https://github.com/fortuity/google_client_login)):
45
+
46
+ ```ruby
47
+ options = { :accountType => 'GOOGLE', :source => 'company-app-version' }
48
+ analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password', options)
49
+ ```
50
+
51
+ ### Authentication Token
52
+
53
+ You can set yourself the `auth_token` to use it in the fetching:
54
+
55
+ ```ruby
56
+ analytics.auth_token = 'your-token-from-oauth'
57
+ ```
58
+
59
+ ## Example
60
+
61
+ All parameters are escaped before a request. For date format you can use the next tip: `Date.today.strftime("%Y-%m-%d")`.
62
+
63
+ ```ruby
64
+ analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')
65
+
66
+ analytics.fetch(
67
+ 'ids' => 'ga:id',
68
+ 'metrics' => 'ga:visitors',
69
+ 'dimensions' => 'ga:country',
70
+ 'start-date' => '2012-01-01',
71
+ 'end-date' => '2012-01-10'
72
+ )
73
+ # => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]]
74
+
75
+ analytics.rows
76
+ # => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]]
77
+
78
+ analytics.body
79
+ # => returns the parsed response body (hash), where you can get other info, see google docs.
80
+
81
+ analytics.fetch(
82
+ 'ids' => 'ga:another-id',
83
+ 'metrics' => 'ga:visitors,ga:newVisits',
84
+ 'dimensions' => 'ga:pagePath',
85
+ 'filters' => 'ga:pagepath=~/articles/[\w-]+\z'
86
+ 'start-date' => '2012-01-01',
87
+ 'end-date' => '2012-01-10'
88
+ )
89
+ # => [["/articles/first-post","12", "2"], ["/articles/second-post","2", "1"]]
90
+
91
+ analytics.rows
92
+ # => [["/articles/first-post","12", "2"], ["/articles/second-post","2", "1"]]
93
+ ```
94
+
95
+
96
+ ## Dependencies
97
+
98
+ * Ruby 1.8.7 or later
@@ -1,3 +1,3 @@
1
1
  module SimpleAnalytics
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,22 +5,21 @@ require 'google_client_login'
5
5
  module SimpleAnalytics
6
6
  # Required query parameters are used to configure which data to return from Google Analytics.
7
7
  REQUIRED_PROPERTIES = ['ids', 'start-date', 'end-date', 'metrics']
8
+ API_URL = 'https://www.googleapis.com/analytics/v3/data/ga'
8
9
 
9
10
  class NotSuccessfulResponseError < RuntimeError; end
10
11
 
11
12
  class Api
12
- # An authentication token for the Google Analytics Api.
13
13
  attr_accessor :auth_token
14
14
 
15
15
  # +rows+ is a 2-dimensional array of strings, each string represents a value in the table.
16
16
  # +body+ is the data in response body.
17
17
  attr_reader :rows, :body
18
18
 
19
- # Authentication using ClientLogin, returns an analytics service object.
20
19
  def self.authenticate(username, password, options = {})
21
- new(username, password, options).tap do |analytics|
22
- analytics.authenticate
23
- end
20
+ analytics = new(username, password, options)
21
+ analytics.authenticate
22
+ analytics
24
23
  end
25
24
 
26
25
  def initialize(username, password, options = {})
@@ -29,24 +28,24 @@ module SimpleAnalytics
29
28
  @options = options
30
29
  end
31
30
 
32
- # Authenticates using ClientLogin.
33
31
  def authenticate
34
32
  login_service = ::GoogleClientLogin::GoogleAuth.new(client_options)
35
33
  login_service.authenticate(@username, @password, @options[:captcha_response])
36
34
  @auth_token = login_service.auth
37
35
  end
38
36
 
39
- # Fetches the report data, the following query parameters are required: 'ids', 'start-date', 'end-date', 'metrics'.
40
37
  def fetch(properties)
41
38
  check_properties(properties)
42
39
 
43
- uri = URI.parse("https://www.googleapis.com/analytics/v3/data/ga")
40
+ uri = URI.parse(API_URL)
44
41
  http = Net::HTTP.new(uri.host, uri.port)
45
42
  http.use_ssl = true
46
43
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
47
44
 
48
- response = http.get("#{uri.path}?#{query_string(properties)}", { 'Authorization' => "GoogleLogin auth=#{@auth_token}", 'GData-Version' => '3' })
45
+ headers = { 'Authorization' => "GoogleLogin auth=#{@auth_token}", 'GData-Version' => '3' }
46
+ response = http.get("#{uri.path}?#{query_string(properties)}", headers)
49
47
  raise NotSuccessfulResponseError.new, response.body if response.code_type != Net::HTTPOK
48
+
50
49
  @body = JSON.parse(response.body)
51
50
  @rows = @body['rows']
52
51
  end
@@ -54,9 +53,11 @@ module SimpleAnalytics
54
53
  private
55
54
 
56
55
  def client_options
57
- { :service => 'analytics',
56
+ {
57
+ :service => 'analytics',
58
58
  :accountType => (@options[:accountType] || 'GOOGLE'),
59
- :source => (@options[:source] || 'djo-simple_analytics-001') }
59
+ :source => (@options[:source] || 'djo-simple_analytics-001')
60
+ }
60
61
  end
61
62
 
62
63
  def check_properties(properties)
@@ -67,7 +68,7 @@ module SimpleAnalytics
67
68
  end
68
69
 
69
70
  def query_string(properties)
70
- properties.map{ |k, v| "#{k}=#{escape v}" }.sort.join('&')
71
+ properties.map { |k, v| "#{k}=#{escape v}" }.sort.join('&')
71
72
  end
72
73
 
73
74
  def escape(property)
@@ -16,8 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.version = SimpleAnalytics::VERSION
17
17
 
18
18
  gem.add_dependency "json"
19
- gem.add_dependency "google_client_login", "~> 0.3.1"
20
- gem.add_development_dependency "rspec", "~> 2.8"
21
- gem.add_development_dependency "fuubar", "~> 0.0.6"
22
- gem.add_development_dependency "webmock", "~> 1.7.10"
19
+ gem.add_dependency "google_client_login", "~> 0.3"
20
+ gem.add_development_dependency "rspec"
21
+ gem.add_development_dependency "fuubar"
22
+ gem.add_development_dependency "webmock"
23
23
  end
@@ -1,53 +1,67 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SimpleAnalytics::Api do
4
+ STUB_URL = "https://www.googleapis.com/analytics/v3/data/ga?dimensions=ga:country&end-date=2012-01-10&ids=ga:id&metrics=ga:visitors&start-date=2012-01-01"
5
+
6
+ REQUEST_BODY = {
7
+ 'accountType' => 'GOOGLE',
8
+ 'source' => 'djo-simple_analytics-001',
9
+ 'service' => 'analytics',
10
+ 'Email' => 'user@gmail.com',
11
+ 'Passwd' => 'password'
12
+ }
13
+
14
+ PROPERTIES = {
15
+ 'ids' => 'ga:id',
16
+ 'metrics' => 'ga:visitors',
17
+ 'dimensions' => 'ga:country',
18
+ 'start-date' => '2012-01-01',
19
+ 'end-date' => '2012-01-10'
20
+ }
21
+
4
22
  before do
5
- @auth_request = stub_request(:post, "https://www.google.com/accounts/ClientLogin").
6
- with(:body => { "accountType" => "GOOGLE", "source" => "djo-simple_analytics-001", "service" => "analytics", "Email"=>"user@gmail.com", "Passwd" => "password" }).
23
+ @auth_request = stub_request(:post, 'https://www.google.com/accounts/ClientLogin').
24
+ with(:body => REQUEST_BODY).
7
25
  to_return(:status => 200, :body => "AUTH=secret\n")
8
26
  end
9
27
 
10
- describe ".authenticate" do
28
+ describe '.authenticate' do
11
29
  it "requests authentication" do
12
30
  SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')
13
31
  @auth_request.should have_been_requested
14
32
  end
15
33
 
16
- it "fetches an auth token" do
34
+ it 'fetches an auth token' do
17
35
  analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')
18
36
  analytics.auth_token.should eq('secret')
19
37
  end
20
38
  end
21
39
 
22
- describe "#fetch" do
40
+ describe '#fetch' do
23
41
  before { stub_analytics_request }
24
42
 
25
43
  let(:analytics) { SimpleAnalytics::Api.authenticate('user@gmail.com', 'password') }
26
- let(:properties) { { 'ids' => 'ga:id',
27
- 'metrics' => 'ga:visitors',
28
- 'dimensions' => 'ga:country',
29
- 'start-date' => '2012-01-01',
30
- 'end-date' => '2012-01-10' } }
44
+ let(:properties) { PROPERTIES }
31
45
 
32
- it "raises an argument error without requried properties" do
46
+ it 'raises an argument error without requried properties' do
33
47
  expect {
34
48
  analytics.fetch('ids' => 'ga:xxx')
35
49
  }.to raise_error(ArgumentError)
36
50
  end
37
51
 
38
- it "fetches rows" do
52
+ it 'fetches rows' do
39
53
  rows = analytics.fetch(properties)
40
54
  rows.should eq([[ "United States", "73834"], ["Ukraine", "15726"]])
41
55
  analytics.rows.should eq([[ "United States", "73834"], ["Ukraine", "15726"]])
42
56
  end
43
57
 
44
- it "sets column headers" do
58
+ it 'sets column headers' do
45
59
  rows = analytics.fetch(properties)
46
60
  rows.should eq([[ "United States", "73834"], ["Ukraine", "15726"]])
47
61
  analytics.rows.should eq([[ "United States", "73834"], ["Ukraine", "15726"]])
48
62
  end
49
63
 
50
- it "raises not successful response error" do
64
+ it 'raises not successful response error' do
51
65
  stub_analytics_request(:status => 403, :code_type => Net::HTTPForbidden)
52
66
 
53
67
  expect {
@@ -56,13 +70,15 @@ describe SimpleAnalytics::Api do
56
70
  end
57
71
 
58
72
  def stub_analytics_request(response = {})
59
- data = { :body => { :rows => [[ "United States", "73834"], ["Ukraine", "15726"]] }.to_json,
60
- :status => 200,
61
- :code_type => Net::HTTPOK }.merge(response)
73
+ data = {
74
+ :body => { :rows => [[ "United States", "73834"], ["Ukraine", "15726"]] }.to_json,
75
+ :status => 200,
76
+ :code_type => Net::HTTPOK
77
+ }
62
78
 
63
- stub_request(:get, "https://www.googleapis.com/analytics/v3/data/ga?dimensions=ga:country&end-date=2012-01-10&ids=ga:id&metrics=ga:visitors&start-date=2012-01-01").
79
+ stub_request(:get, STUB_URL).
64
80
  with(:headers => { 'Authorization'=>'GoogleLogin auth=secret', 'Gdata-Version'=>'3' }).
65
- to_return(data)
81
+ to_return(data.merge(response))
66
82
  end
67
83
  end
68
84
  end
metadata CHANGED
@@ -1,83 +1,108 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: simple_analytics
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Andrew Djoga
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-02-01 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-01-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: json
16
- requirement: &70098909002660 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
23
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
22
31
  type: :runtime
32
+ requirement: *id001
23
33
  prerelease: false
24
- version_requirements: *70098909002660
25
- - !ruby/object:Gem::Dependency
34
+ - !ruby/object:Gem::Dependency
26
35
  name: google_client_login
27
- requirement: &70098908994280 !ruby/object:Gem::Requirement
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
28
37
  none: false
29
- requirements:
38
+ requirements:
30
39
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: 0.3.1
40
+ - !ruby/object:Gem::Version
41
+ hash: 13
42
+ segments:
43
+ - 0
44
+ - 3
45
+ version: "0.3"
33
46
  type: :runtime
47
+ requirement: *id002
34
48
  prerelease: false
35
- version_requirements: *70098908994280
36
- - !ruby/object:Gem::Dependency
49
+ - !ruby/object:Gem::Dependency
37
50
  name: rspec
38
- requirement: &70098908993300 !ruby/object:Gem::Requirement
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
39
52
  none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: '2.8'
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
44
60
  type: :development
61
+ requirement: *id003
45
62
  prerelease: false
46
- version_requirements: *70098908993300
47
- - !ruby/object:Gem::Dependency
63
+ - !ruby/object:Gem::Dependency
48
64
  name: fuubar
49
- requirement: &70098908992220 !ruby/object:Gem::Requirement
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
50
66
  none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 0.0.6
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
55
74
  type: :development
75
+ requirement: *id004
56
76
  prerelease: false
57
- version_requirements: *70098908992220
58
- - !ruby/object:Gem::Dependency
77
+ - !ruby/object:Gem::Dependency
59
78
  name: webmock
60
- requirement: &70098908990640 !ruby/object:Gem::Requirement
79
+ version_requirements: &id005 !ruby/object:Gem::Requirement
61
80
  none: false
62
- requirements:
63
- - - ~>
64
- - !ruby/object:Gem::Version
65
- version: 1.7.10
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
66
88
  type: :development
89
+ requirement: *id005
67
90
  prerelease: false
68
- version_requirements: *70098908990640
69
91
  description: The Simple Analytics allows to access Google Analytics report data
70
- email:
92
+ email:
71
93
  - andrew.djoga@gmail.com
72
94
  executables: []
95
+
73
96
  extensions: []
97
+
74
98
  extra_rdoc_files: []
75
- files:
99
+
100
+ files:
76
101
  - .gitignore
102
+ - .travis.yml
77
103
  - Gemfile
78
- - Gemfile.lock
79
104
  - LICENSE
80
- - README.rdoc
105
+ - README.md
81
106
  - Rakefile
82
107
  - lib/simple_analytics.rb
83
108
  - lib/simple_analytics/version.rb
@@ -86,34 +111,37 @@ files:
86
111
  - spec/spec_helper.rb
87
112
  homepage: https://github.com/Djo/simple_analytics
88
113
  licenses: []
114
+
89
115
  post_install_message:
90
116
  rdoc_options: []
91
- require_paths:
117
+
118
+ require_paths:
92
119
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
120
+ required_ruby_version: !ruby/object:Gem::Requirement
94
121
  none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- segments:
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
100
127
  - 0
101
- hash: -2303643778759929262
102
- required_rubygems_version: !ruby/object:Gem::Requirement
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
130
  none: false
104
- requirements:
105
- - - ! '>='
106
- - !ruby/object:Gem::Version
107
- version: '0'
108
- segments:
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
109
136
  - 0
110
- hash: -2303643778759929262
137
+ version: "0"
111
138
  requirements: []
139
+
112
140
  rubyforge_project:
113
- rubygems_version: 1.8.10
141
+ rubygems_version: 1.8.24
114
142
  signing_key:
115
143
  specification_version: 3
116
144
  summary: Google Analytics Export API Ruby Wrapper
117
- test_files:
145
+ test_files:
118
146
  - spec/simple_analytics_spec.rb
119
147
  - spec/spec_helper.rb
data/Gemfile.lock DELETED
@@ -1,43 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- simple_analytics (0.0.1)
5
- google_client_login (~> 0.3.1)
6
- json
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- addressable (2.2.6)
12
- crack (0.3.1)
13
- diff-lcs (1.1.3)
14
- fuubar (0.0.6)
15
- rspec (~> 2.0)
16
- rspec-instafail (~> 0.1.8)
17
- ruby-progressbar (~> 0.0.10)
18
- google_client_login (0.3.1)
19
- json (1.6.5)
20
- rake (0.9.2.2)
21
- rspec (2.8.0)
22
- rspec-core (~> 2.8.0)
23
- rspec-expectations (~> 2.8.0)
24
- rspec-mocks (~> 2.8.0)
25
- rspec-core (2.8.0)
26
- rspec-expectations (2.8.0)
27
- diff-lcs (~> 1.1.2)
28
- rspec-instafail (0.1.9)
29
- rspec-mocks (2.8.0)
30
- ruby-progressbar (0.0.10)
31
- webmock (1.7.10)
32
- addressable (~> 2.2, > 2.2.5)
33
- crack (>= 0.1.7)
34
-
35
- PLATFORMS
36
- ruby
37
-
38
- DEPENDENCIES
39
- fuubar (~> 0.0.6)
40
- rake (~> 0.9.2.2)
41
- rspec (~> 2.8)
42
- simple_analytics!
43
- webmock (~> 1.7.10)
data/README.rdoc DELETED
@@ -1,75 +0,0 @@
1
- = SimpleAnalytics
2
-
3
- SimpleAnalytics gem provides accessing Google Analytics Export Api. It uses Version 3.0 of the Google Core Reporting API with JSON. You can find the google documentation {here}[http://code.google.com/apis/analytics/docs/gdata/v3/gdataGettingStarted.html].
4
-
5
- == Installation
6
-
7
- Install as a gem from rubygems:
8
-
9
- gem install simple_analytics
10
-
11
- == Getting Started
12
-
13
- Authentication:
14
-
15
- analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')
16
-
17
- The <tt>authenticate</tt> method sets an <tt>auth_token</tt> in the analytics service object. Then you can fetch data:
18
-
19
- analytics.fetch('ids' => 'ga:id',
20
- 'metrics' => 'ga:visitors',
21
- 'dimensions' => 'ga:country',
22
- 'start-date' => '2012-01-01',
23
- 'end-date' => '2012-01-10')
24
- # => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]
25
-
26
- The <tt>fetch</tt> method sets and returns rows. Required query parameters are used to configure which data to return from Google Analytics:
27
- * ids — The profile IDs from which to access data.
28
- * start-date — The beginning of the date range.
29
- * end-date — The end of the date range.
30
- * metrics — The numeric values to return.
31
-
32
- For more detailed information about the parameters see {google REST docs}[http://code.google.com/apis/analytics/docs/gdata/v3/exportRest.html].
33
-
34
- == Authentication
35
-
36
- For the authentication it uses gem {google_client_login}[https://github.com/fortuity/google_client_login] based on the ClientLogin. You can also pass extra parameters which allows the gem (see the gem's {README}[https://github.com/fortuity/google_client_login]):
37
-
38
- analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password', { :accountType => 'GOOGLE',
39
- :source => 'company-app-version' })
40
-
41
- ==== Authentication Token
42
-
43
- You can set yourself the <tt>auth_token</tt> to use it in the fetching:
44
-
45
- analytics.auth_token = 'your-token-from-oauth'
46
-
47
- == An example
48
-
49
- All parameters are escaped before a request. For date you can use the next tip: <tt>your_date.strftime("%Y-%m-%d")</tt>.
50
-
51
- analytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')
52
-
53
- analytics.fetch('ids' => 'ga:id',
54
- 'metrics' => 'ga:visitors',
55
- 'dimensions' => 'ga:country',
56
- 'start-date' => '2012-01-01',
57
- 'end-date' => '2012-01-10')
58
- # => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]
59
-
60
- analytics.rows
61
- # => [["United States","24451"], ["Brazil","15616"], ["Spain","3966"]
62
-
63
- analytics.body
64
- # => returns the parsed response body (hash), where you can get other info, see google docs
65
-
66
- analytics.fetch('ids' => 'ga:another-id',
67
- 'metrics' => 'ga:visitors,ga:newVisits',
68
- 'dimensions' => 'ga:pagePath',
69
- 'filters' => 'ga:pagepath=~/articles/[\w-]+\z'
70
- 'start-date' => '2012-01-01',
71
- 'end-date' => '2012-01-10')
72
- # => [["/article/first-post","12", "2"], ["/article/second-post","2", "1"]]
73
-
74
- analytics.rows
75
- # => [["/article/first-post","12", "2"], ["/article/second-post","2", "1"]]