jeremyf-gattica 0.3.4 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/History.txt +7 -0
- data/VERSION.yml +2 -2
- data/gattica.gemspec +65 -0
- data/lib/gattica/auth.rb +1 -1
- data/lib/gattica.rb +26 -11
- data/test/test_gattica.rb +16 -0
- metadata +10 -5
data/.gitignore
ADDED
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.3.6
|
2
|
+
* Updated gem to pass tests under 1.9.1
|
3
|
+
|
4
|
+
== 0.3.5
|
5
|
+
* Added ability to parse addition query strings
|
6
|
+
* Added test to verify behavior
|
7
|
+
|
1
8
|
== 0.3.4
|
2
9
|
* Removed Hash#to_query as this directly conflicts with Rails Hash#to_query method.
|
3
10
|
* Removed Hash#stringify_keys as it was not used in the code base.
|
data/VERSION.yml
CHANGED
data/gattica.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{gattica}
|
5
|
+
s.version = "0.3.6"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Rob Cameron"]
|
9
|
+
s.date = %q{2009-08-07}
|
10
|
+
s.description = %q{Gattica is a Ruby library for extracting data from the Google Analytics API.}
|
11
|
+
s.email = %q{cannikinn@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"LICENSE",
|
14
|
+
"README.rdoc"
|
15
|
+
]
|
16
|
+
s.files = [
|
17
|
+
".gitignore",
|
18
|
+
"History.txt",
|
19
|
+
"LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION.yml",
|
23
|
+
"examples/example.rb",
|
24
|
+
"gattica.gemspec",
|
25
|
+
"lib/gattica.rb",
|
26
|
+
"lib/gattica/account.rb",
|
27
|
+
"lib/gattica/auth.rb",
|
28
|
+
"lib/gattica/convertible.rb",
|
29
|
+
"lib/gattica/core_extensions.rb",
|
30
|
+
"lib/gattica/data_point.rb",
|
31
|
+
"lib/gattica/data_set.rb",
|
32
|
+
"lib/gattica/exceptions.rb",
|
33
|
+
"lib/gattica/user.rb",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/suite.rb",
|
36
|
+
"test/test_auth.rb",
|
37
|
+
"test/test_engine.rb",
|
38
|
+
"test/test_gattica.rb",
|
39
|
+
"test/test_user.rb"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/cannikin/gattica}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.4}
|
45
|
+
s.summary = %q{Gattica is a Ruby library for extracting data from the Google Analytics API.}
|
46
|
+
s.test_files = [
|
47
|
+
"test/helper.rb",
|
48
|
+
"test/suite.rb",
|
49
|
+
"test/test_auth.rb",
|
50
|
+
"test/test_engine.rb",
|
51
|
+
"test/test_gattica.rb",
|
52
|
+
"test/test_user.rb",
|
53
|
+
"examples/example.rb"
|
54
|
+
]
|
55
|
+
|
56
|
+
if s.respond_to? :specification_version then
|
57
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
58
|
+
s.specification_version = 3
|
59
|
+
|
60
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
61
|
+
else
|
62
|
+
end
|
63
|
+
else
|
64
|
+
end
|
65
|
+
end
|
data/lib/gattica/auth.rb
CHANGED
@@ -11,7 +11,7 @@ module Gattica
|
|
11
11
|
|
12
12
|
SCRIPT_NAME = '/accounts/ClientLogin'
|
13
13
|
HEADERS = { 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Ruby Net::HTTP' } # Google asks that you be nice and provide a user-agent string
|
14
|
-
OPTIONS = { :source =>
|
14
|
+
OPTIONS = { :source => "gattica-#{Gattica::VERSION}", :service => 'analytics' } # Google asks that you provide the name of your app as a 'source' parameter in your POST
|
15
15
|
|
16
16
|
attr_reader :tokens
|
17
17
|
|
data/lib/gattica.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__) # for use/testing when no gem is installed
|
2
2
|
|
3
|
+
|
4
|
+
module Gattica
|
5
|
+
VERSION = '0.3.6'
|
6
|
+
end
|
7
|
+
|
3
8
|
# external
|
4
9
|
require 'net/http'
|
5
10
|
require 'net/https'
|
@@ -26,8 +31,6 @@ require 'gattica/data_point'
|
|
26
31
|
|
27
32
|
module Gattica
|
28
33
|
|
29
|
-
VERSION = '0.3.1'
|
30
|
-
|
31
34
|
# Creates a new instance of Gattica::Engine and gets us going. Please see the README for usage docs.
|
32
35
|
#
|
33
36
|
# ga = Gattica.new({:email => 'anonymous@anon.com', :password => 'password, :profile_id => 123456 })
|
@@ -206,26 +209,34 @@ module Gattica
|
|
206
209
|
|
207
210
|
# Creates a valid query string for GA
|
208
211
|
def build_query_string(args,profile)
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
+
query_params = args.clone
|
213
|
+
ga_start_date = query_params.delete(:start_date)
|
214
|
+
ga_end_date = query_params.delete(:end_date)
|
215
|
+
ga_dimensions = query_params.delete(:dimensions)
|
216
|
+
ga_metrics = query_params.delete(:metrics)
|
217
|
+
ga_sort = query_params.delete(:sort)
|
218
|
+
ga_filters = query_params.delete(:filters)
|
219
|
+
|
220
|
+
output = "ids=ga:#{profile}&start-date=#{ga_start_date}&end-date=#{ga_end_date}"
|
221
|
+
unless ga_dimensions.nil? || ga_dimensions.empty?
|
222
|
+
output += '&dimensions=' + ga_dimensions.collect do |dimension|
|
212
223
|
"ga:#{dimension}"
|
213
224
|
end.join(',')
|
214
225
|
end
|
215
|
-
unless
|
216
|
-
output += '&metrics=' +
|
226
|
+
unless ga_metrics.nil? || ga_metrics.empty?
|
227
|
+
output += '&metrics=' + ga_metrics.collect do |metric|
|
217
228
|
"ga:#{metric}"
|
218
229
|
end.join(',')
|
219
230
|
end
|
220
|
-
unless
|
221
|
-
output += '&sort=' +
|
231
|
+
unless ga_sort.nil? || ga_sort.empty?
|
232
|
+
output += '&sort=' + Array(ga_sort).collect do |sort|
|
222
233
|
sort[0..0] == '-' ? "-ga:#{sort[1..-1]}" : "ga:#{sort}" # if the first character is a dash, move it before the ga:
|
223
234
|
end.join(',')
|
224
235
|
end
|
225
236
|
|
226
237
|
# TODO: update so that in regular expression filters (=~ and !~), any initial special characters in the regular expression aren't also picked up as part of the operator (doesn't cause a problem, but just feels dirty)
|
227
|
-
unless
|
228
|
-
output += '&filters=' +
|
238
|
+
unless ga_filters.nil? || ga_filters.empty? # filters are a little more complicated because they can have all kinds of modifiers
|
239
|
+
output += '&filters=' + ga_filters.collect do |filter|
|
229
240
|
match, name, operator, expression = *filter.match(/^(\w*)(\W*)(.*)$/) # splat the resulting Match object to pull out the parts automatically
|
230
241
|
unless name.empty? || operator.empty? || expression.empty? # make sure they all contain something
|
231
242
|
"ga:#{name}#{CGI::escape(operator.gsub(/ /,''))}#{CGI::escape(expression)}" # remove any whitespace from the operator before output
|
@@ -234,8 +245,12 @@ module Gattica
|
|
234
245
|
end
|
235
246
|
end.join(';')
|
236
247
|
end
|
248
|
+
|
249
|
+
query_params.inject(output) {|m,(key,value)| m << "&#{key}=#{value}"}
|
250
|
+
|
237
251
|
return output
|
238
252
|
end
|
253
|
+
|
239
254
|
|
240
255
|
|
241
256
|
# Validates that the args passed to +get+ are valid
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestUser < Test::Unit::TestCase
|
4
|
+
def test_build_query_string
|
5
|
+
@gattica = Gattica.new(:token => 'ga-token', :profile_id => 'ga-profile_id')
|
6
|
+
expected = "ids=ga:ga-profile_id&start-date=2008-01-02&end-date=2008-01-03&dimensions=ga:pageTitle,ga:pagePath&metrics=ga:pageviews&sort=-ga:pageviews&max-results=3"
|
7
|
+
result = @gattica.send(:build_query_string, {
|
8
|
+
:start_date => Date.civil(2008,1,2),
|
9
|
+
:end_date => Date.civil(2008,1,3),
|
10
|
+
:dimensions => ['pageTitle','pagePath'],
|
11
|
+
:metrics => ['pageviews'],
|
12
|
+
:sort => '-pageviews',
|
13
|
+
'max-results' => '3'}, 'ga-profile_id')
|
14
|
+
assert_equal expected, result
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeremyf-gattica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Cameron
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-07 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,12 +23,14 @@ extra_rdoc_files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.rdoc
|
25
25
|
files:
|
26
|
+
- .gitignore
|
26
27
|
- History.txt
|
27
28
|
- LICENSE
|
28
29
|
- README.rdoc
|
29
30
|
- Rakefile
|
30
31
|
- VERSION.yml
|
31
32
|
- examples/example.rb
|
33
|
+
- gattica.gemspec
|
32
34
|
- lib/gattica.rb
|
33
35
|
- lib/gattica/account.rb
|
34
36
|
- lib/gattica/auth.rb
|
@@ -42,9 +44,11 @@ files:
|
|
42
44
|
- test/suite.rb
|
43
45
|
- test/test_auth.rb
|
44
46
|
- test/test_engine.rb
|
47
|
+
- test/test_gattica.rb
|
45
48
|
- test/test_user.rb
|
46
|
-
has_rdoc:
|
49
|
+
has_rdoc: false
|
47
50
|
homepage: http://github.com/cannikin/gattica
|
51
|
+
licenses:
|
48
52
|
post_install_message:
|
49
53
|
rdoc_options:
|
50
54
|
- --charset=UTF-8
|
@@ -65,14 +69,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
69
|
requirements: []
|
66
70
|
|
67
71
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.3.5
|
69
73
|
signing_key:
|
70
|
-
specification_version:
|
74
|
+
specification_version: 3
|
71
75
|
summary: Gattica is a Ruby library for extracting data from the Google Analytics API.
|
72
76
|
test_files:
|
73
77
|
- test/helper.rb
|
74
78
|
- test/suite.rb
|
75
79
|
- test/test_auth.rb
|
76
80
|
- test/test_engine.rb
|
81
|
+
- test/test_gattica.rb
|
77
82
|
- test/test_user.rb
|
78
83
|
- examples/example.rb
|