google_api 1.0.0.beta → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- Google Analytics
1
+ Google Analytics [![Build Status](https://secure.travis-ci.org/ondra-m/google_api.png)](http://travis-ci.org/ondra-m/google_api)
2
2
  ================
3
3
 
4
+ <a href="#examples">examples</a>
5
+
4
6
  News
5
7
  ----
6
8
 
@@ -50,36 +52,36 @@ GoogleApi.config.ga.client_id = "5"
50
52
 
51
53
  <tbody>
52
54
  <tr>
53
- <td><b>client_id</b></td>
55
+ <td>client_id</td>
54
56
  <td><i>123456.apps.googleusercontent.com</i></td>
55
57
  <td rowspan="3">required for oauth 2</td>
56
58
  </tr>
57
59
  <tr>
58
- <td><b>client_secret</b></td>
60
+ <td>client_secret</td>
59
61
  <td><i>123456123456123456</i></td>
60
62
  </tr>
61
63
  <tr>
62
- <td><b>redirect_uri</b></td>
64
+ <td>redirect_uri</td>
63
65
  <td><i>http://localhost/oauth2callback</i></td>
64
66
  </tr>
65
67
  <tr>
66
- <td><b>client_developer_email</b></td>
68
+ <td>client_developer_email</td>
67
69
  <td><i>123456@developer.gserviceaccount.com</i></td>
68
70
  <td rowspan="3">required for login by cert</td>
69
71
  </tr>
70
72
  <tr>
71
- <td><b>client_cert_file</b></td>
73
+ <td>client_cert_file</td>
72
74
  <td><i>/home/user/app/123456-privatekey.p12</i></td>
73
75
  </tr>
74
76
  <tr>
75
- <td><b>key_secret</b></td>
77
+ <td>key_secret</td>
76
78
  <td><i>notasecret</i></td>
77
79
  </tr>
78
80
  <tr>
79
81
  <td colspan="3">only for ga</td>
80
82
  </tr>
81
83
  <tr>
82
- <td><b>cache</b></td>
84
+ <td>cache</td>
83
85
  <td><i>default: </i><b>GoogleApi::Cache.new</b></td>
84
86
  <td>more information <a href="#Cache">Cache</a></td>
85
87
  </tr>
@@ -107,12 +109,12 @@ There is a 3 way for starting sesssion.
107
109
  `First you must add your developer email to google analytics profile.`
108
110
 
109
111
  ```ruby
112
+ # try login once
110
113
  GoogleApi::Ga::Session.login_by_cert
111
- ```
112
114
 
113
- If login return false, trying login again.
115
+ # ----- OR -----
114
116
 
115
- ```ruby
117
+ # trying login in loop
116
118
  GoogleApi::Ga::Session.login_by_cert!
117
119
  ```
118
120
 
@@ -180,7 +182,6 @@ Management
180
182
  ```ruby
181
183
  # Variables: id, name, created, updated
182
184
  # Methods: webproperties
183
-
184
185
  GoogleApi::Ga::Account
185
186
  ```
186
187
 
@@ -189,7 +190,6 @@ GoogleApi::Ga::Account
189
190
  ```ruby
190
191
  # Variables: id, name, created, updated, accountId, websiteUrl
191
192
  # Methods: account, profiles
192
-
193
193
  GoogleApi::Ga::Webproperty
194
194
  ```
195
195
 
@@ -198,7 +198,6 @@ GoogleApi::Ga::Webproperty
198
198
  ```ruby
199
199
  # Variables: id, name, created, updated, accountId, websiteUrl, currency, timezone
200
200
  # Methods: webproperty, goals
201
-
202
201
  GoogleApi::Ga::Profile
203
202
  ```
204
203
 
@@ -207,7 +206,6 @@ GoogleApi::Ga::Profile
207
206
  ```ruby
208
207
  # Variables: accountId, webPropertyId, profileId, value, active, type, goal
209
208
  # Methods: profile
210
-
211
209
  GoogleApi::Ga::Goal
212
210
  ```
213
211
 
@@ -215,7 +213,6 @@ GoogleApi::Ga::Goal
215
213
 
216
214
  ```ruby
217
215
  # Variables: segmentId, definition
218
-
219
216
  GoogleApi::Ga::Segment
220
217
  ```
221
218
 
@@ -234,7 +231,7 @@ First you can play on the playground: http://ga-dev-tools.appspot.com/explorer/.
234
231
  ```ruby
235
232
  GoogleApi::Ga::Data
236
233
  ```
237
- <br><br><br>
234
+ <br>
238
235
  > ## ids
239
236
  >
240
237
  > <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/reference#ids" target="_blank" style="float:right">doc</a>
@@ -279,6 +276,8 @@ GoogleApi::Ga::Data
279
276
  >
280
277
  > **alias:** select
281
278
  >
279
+ > you can also add or sub parameters with `.metrics_add` or `.metrics_sub`
280
+ >
282
281
  > **parameters:** Array with String or Symbol, String (not compiled, <i>"ga:visitors"</i>) or Symbol (compiled, <i>:visitors</i>)
283
282
 
284
283
  <br>
@@ -289,6 +288,8 @@ GoogleApi::Ga::Data
289
288
  >
290
289
  > **alias:** with
291
290
  >
291
+ > you can also add or sub parameters with `.dimensions_add` or `.dimensions_sub`
292
+ >
292
293
  > **parameters:** Array with String or Symbol, String (not compiled, <i>"ga:visitors"</i>) or Symbol (compiled, <i>:visitors</i>)
293
294
 
294
295
  <br>
@@ -296,6 +297,7 @@ GoogleApi::Ga::Data
296
297
  > ## sort
297
298
  >
298
299
  > <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/reference#sort" target="_blank" style="float:right">doc</a>
300
+ > you can also add or sub parameters with `.sort_add` or `.sort_sub`
299
301
  >
300
302
  > **parameters:** Array with String or Symbol, String (not compiled, <i>"ga:visitors"</i>) or Symbol (compiled, <i>:visitors</i>)
301
303
 
@@ -309,6 +311,10 @@ GoogleApi::Ga::Data
309
311
  >
310
312
  > **parameters:**<br>
311
313
  > {(attribute operator value) & (attribute operator value) | (attribute operator value)} or String (not compiled)
314
+ >
315
+ > **operators:** ==, !=, >, <, >=, <=, =~, !~<br>
316
+ > % &nbsp;&nbsp;&nbsp; _is &nbsp;=@_<br>
317
+ > ** &nbsp;&nbsp;&nbsp; _is &nbsp;&nbsp;!@_
312
318
 
313
319
  <br>
314
320
 
@@ -319,6 +325,10 @@ GoogleApi::Ga::Data
319
325
  > **parameters:**<br>
320
326
  > {(attribute operator value) & (attribute operator value) | (attribute operator value)} or String (not compiled) <br>
321
327
  > with {} automaticly add "dynamic::"
328
+ >
329
+ > **operators:** ==, !=, >, <, >=, <=, =~, !~<br>
330
+ > % &nbsp;&nbsp;&nbsp; _is &nbsp;=@_<br>
331
+ > ** &nbsp;&nbsp;&nbsp; _is &nbsp;&nbsp;!@_
322
332
 
323
333
  <br>
324
334
 
@@ -356,98 +366,124 @@ GoogleApi::Ga::Data
356
366
 
357
367
  You can use one of these. Data is stored in the class.
358
368
 
359
- <b>`all`</b> - `[header, rows]`<br>
360
- <b>`rows`</b> - rows returned by google analytics<br>
361
- <b>`header`</b> - header of data, (`["ga:day", "ga:month", "ga:visitis"]`)<br>
362
- <b>`count`</b> - number of rows<br>
363
- <b>`each`</b> - each as you expected, (`|data|` or `|index, data|`)
369
+ `.all` - `[header, rows]`<br>
370
+ `.rows` - rows returned by google analytics<br>
371
+ `.header` - header of data, (`["ga:day", "ga:month", "ga:visitis"]`)<br>
372
+ `.count` - number of rows<br>
373
+ `.each` - each as you expected, (`|data|` or `|index, data|`)
364
374
 
365
375
  ### Clear stored data and fetch again
366
376
 
367
- clear:<br>
368
- <b>`clear`</b><br>
377
+ If you add some parameters clear is called automaticlly.
369
378
 
370
- clear and fetch new:<br>
371
- <b>`all!`</b>, <b>`rows!`</b>, <b>`header!`</b>, <b>`count!`</b>, <b>`each!`</b><br><br>
379
+ clear: `.clear`<br>
372
380
 
373
- If you add some parameters clear is called automaticlly.
381
+ clear and fetch new:<br>
382
+ `.all!`, `.rows!`, `.header!`, `.count!`, `.each!`<br>
374
383
 
375
384
  Examples
376
385
  --------
377
386
 
378
- **Start session:**
387
+
379
388
  ```ruby
380
- # set configuration
381
- GoogleApi.config.ga.client_cert_file = "privatekey.p12"
382
- GoogleApi.config.ga.client_developer_email = "123456@developer.gserviceaccount.com"
389
+ # Start session
390
+ # =============
383
391
 
384
- # start session
385
- GoogleApi::Ga::Session.login_by_cert!
392
+ # set configuration
393
+ GoogleApi.config.ga.client_cert_file = "privatekey.p12"
394
+ GoogleApi.config.ga.client_developer_email = "123456@developer.gserviceaccount.com"
386
395
 
387
- # get profile id
388
- id = GoogleApi::Ga::Profile.all.first.id
396
+ # start session
397
+ GoogleApi::Ga::Session.login_by_cert!
389
398
 
390
- # set default id
391
- GoogleApi::Ga.id(id)
392
- ```
393
- <br>
394
- **Starting session by line:**<br>
395
399
 
396
- First install launchy:<br>
397
- `gem install launchy`
398
- ```ruby
399
- # callback_uri and port can be blank - auto start server at localhost
400
- GoogleApi::Ga::Session.login_by_line(callback_uri, port)
401
400
 
402
- # 1) create server
403
- # 2) launch browser and redirect to google api
404
- # 3) confirm and google api redirect to localhost
405
- # 4) server get code and start session
406
- # 5) close server
401
+ # Get profile id
402
+ # ==============
407
403
 
408
- # Error if not login
409
- GoogleApi::Ga::Session.check_session!
410
- ```
411
- <br>
412
- **Management of accounts:**
413
- ```ruby
414
- accounts = GoogleApi::Ga::Account.all # all accounts
404
+ # get profile id
405
+ id = GoogleApi::Ga::Profile.all.first.id
415
406
 
416
- accounts.first.webproperties # webproperties for account
407
+ # set default id
408
+ GoogleApi::Ga.id(id)
417
409
 
418
- GoogleApi::Ga::Webproperty.all # all webproperties
419
410
 
420
- GoogleApi::Ga::Profile.all # all profiles
421
411
 
422
- GoogleApi::Ga::Goal.all # all goal
412
+ # Starting session by line
413
+ # ========================
423
414
 
424
- GoogleApi::Ga::Segment.all # all segment
425
- ```
426
- <br>
427
- **Count of visitors between previous month and today.**
428
- ```ruby
429
- GoogleApi::Ga::Data.from(-30).select(:visits).rows
430
- ```
431
- <br>
432
- **Count of visitors between previous month and today - 2, and cache it for 30 minutes.**
433
- ```ruby
434
- GoogleApi::Ga::Data.from(-30).to(DateTime.now - 2).select(:visits).cache(30).rows
435
- ```
436
- <br>
437
- **Visitors by day, month, year from Czech Republic. Browser is Firefox and Opera or Chrome**
438
- ```ruby
439
- GoogleApi::Ga::Data.from(-30)
440
- .select(:visits)
441
- .with(:day, :month, :year)
442
- .where{(country == "Czech Republic") & (browser == "Firefox") &
443
- (browser == "Opera") | (browser == "Chrome")}
444
- .sort(:year, :month, :day)
445
- .rows
446
- # OR
447
- GoogleApi::Ga::Data.from(-30)
448
- .select(:visits)
449
- .with(:day, :month, :year)
450
- .where("ga:country==Czech Republic;ga:browser==Firefox;ga:browser==Opera,ga:browser==Chrome")
451
- .sort(:year, :month, :day)
452
- .rows
415
+ # First install launchy:
416
+ # gem install launchy
417
+
418
+ # callback_uri and port are optional - auto start server at localhost
419
+ GoogleApi::Ga::Session.login_by_line(callback_uri, port)
420
+
421
+ # This will do
422
+ # 1) create server
423
+ # 2) launch browser and redirect to google api
424
+ # 3) confirm and google api redirect to localhost
425
+ # 4) server get code and start session
426
+ # 5) close server - you are login
427
+
428
+
429
+
430
+ # Check session, error if not login
431
+ # =================================
432
+
433
+ GoogleApi::Ga::Session.check_session!
434
+
435
+
436
+
437
+ # Management of accounts
438
+ # ======================
439
+
440
+ # all accounts
441
+ accounts = GoogleApi::Ga::Account.all
442
+
443
+ # webproperties for account
444
+ accounts.first.webproperties
445
+
446
+ # all webproperties
447
+ GoogleApi::Ga::Webproperty.all
448
+
449
+ # all profiles
450
+ GoogleApi::Ga::Profile.all
451
+
452
+ # all goal
453
+ GoogleApi::Ga::Goal.all
454
+
455
+ # all segment
456
+ GoogleApi::Ga::Segment.all
457
+
458
+
459
+
460
+ # Count of visitors between previous month and today
461
+ # ==================================================
462
+
463
+ GoogleApi::Ga::Data.from(-30).select(:visits).rows
464
+
465
+
466
+
467
+ # Count of visitors between previous month and today - 2, and cache it for 30 minutes
468
+ # ===================================================================================
469
+
470
+ GoogleApi::Ga::Data.from(-30).to(-2).select(:visits).cache(30).rows
471
+
472
+
473
+
474
+ # Visitors by day, month, year from Czech Republic. Browser is Firefox and Opera or Chrome
475
+ # ========================================================================================
476
+
477
+ GoogleApi::Ga::Data.from(-30).select(:visits).with(:day, :month, :year)
478
+ .sort(:year, :month, :day)
479
+ .where{(country == "Czech Republic") &
480
+ (browser == "Firefox") &
481
+ (browser == "Opera") |
482
+ (browser == "Chrome")}
483
+ .rows
484
+ # ----- OR -----
485
+ GoogleApi::Ga::Data.from(-30).select(:visits).with(:day, :month, :year)
486
+ .sort(:year, :month, :day)
487
+ .where("ga:country==Czech Republic;ga:browser==Firefox;ga:browser==Opera,ga:browser==Chrome")
488
+ .rows
453
489
  ```
data/Rakefile CHANGED
@@ -5,5 +5,5 @@ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new
7
7
 
8
- task :default => :spec
9
- task :test => :spec
8
+ task default: :spec
9
+ task test: :spec
@@ -10,10 +10,11 @@ module GoogleApi
10
10
 
11
11
  autoload :Ga, 'google_api/ga'
12
12
 
13
- class SessionError < StandardError; end
14
- class GaError < StandardError; end
15
- class DateError < StandardError; end
16
- class TypeError < StandardError; end
13
+ class SessionError < StandardError; end
14
+ class GaError < StandardError; end
15
+ class DateError < StandardError; end
16
+ class TypeError < StandardError; end
17
+ class CanBeNilError < StandardError; end
17
18
 
18
19
  CONFIGURATION = {
19
20
  client_id: nil,
@@ -14,7 +14,6 @@ module GoogleApi
14
14
  date = Date.parse(date)
15
15
  end
16
16
 
17
-
18
17
  date.to_date
19
18
  end
20
19
 
@@ -18,28 +18,16 @@ module GoogleApi
18
18
  GoogleApi.config
19
19
  end
20
20
 
21
- def self.client_id
22
- _config.ga.client_id ? _config.ga.client_id : _config.client_id
23
- end
24
-
25
- def self.client_secret
26
- _config.ga.client_secret ? _config.ga.client_secret : _config.client_secret
27
- end
28
-
29
- def self.redirect_uri
30
- _config.ga.redirect_uri ? _config.ga.redirect_uri : _config.redirect_uri
31
- end
32
-
33
- def self.client_cert_file
34
- _config.ga.client_cert_file ? _config.ga.client_cert_file : _config.client_cert_file
35
- end
36
-
37
- def self.client_developer_email
38
- _config.ga.client_developer_email ? _config.ga.client_developer_email : _config.client_developer_email
39
- end
40
-
41
- def self.key_secret
42
- _config.ga.key_secret ? _config.ga.key_secret : _config.key_secret
21
+ [:client_id, :client_secret, :redirect_uri, :client_cert_file, :client_developer_email, :key_secret].each do |key|
22
+ eval <<-METHOD
23
+ def self.#{key}
24
+ to_return = _config.ga.#{key} ? _config.ga.#{key} : _config.#{key}
25
+
26
+ if to_return.nil?
27
+ raise GoogleApi::CanBeNilError, "#{key} can be nil."
28
+ end
29
+ end
30
+ METHOD
43
31
  end
44
32
 
45
33
  # ---------------------------------------------------------------------------------------
@@ -1,3 +1,3 @@
1
1
  module GoogleApi
2
- VERSION = "1.0.0.beta"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,83 @@
1
+ require "spec_helper"
2
+
3
+ describe "GoogleApi::Cache" do
4
+ before(:each) do
5
+ @cache = GoogleApi::Cache.new
6
+
7
+ @cache.write("key_1", "key_1_value", 0)
8
+ @cache.write("key_2", "key_2_value", 60)
9
+ @cache.write("key_3", "key_3_value", 1000)
10
+ end
11
+
12
+ it "data read" do
13
+ @cache.read("key_1").should eql("key_1_value")
14
+ @cache.read("key_2").should eql("key_2_value")
15
+ @cache.read("key_3").should eql("key_3_value")
16
+
17
+ @cache.read("key_4").should eql(nil)
18
+ @cache.read("key_5").should eql(nil)
19
+ end
20
+
21
+ it "data exists" do
22
+ @cache.exists?("key_1").should eql(true)
23
+ @cache.exists?("key_2").should eql(true)
24
+ @cache.exists?("key_3").should eql(true)
25
+
26
+ @cache.exists?("key_4").should eql(false)
27
+ @cache.exists?("key_5").should eql(false)
28
+ end
29
+
30
+ it "data delete" do
31
+ @cache.exists?("key_1").should eql(true)
32
+ @cache.delete("key_1")
33
+ @cache.exists?("key_1").should eql(false)
34
+
35
+ @cache.exists?("key_2").should eql(true)
36
+ @cache.delete("key_2")
37
+ @cache.exists?("key_2").should eql(false)
38
+
39
+ @cache.exists?("key_3").should eql(true)
40
+ @cache.delete("key_3")
41
+ @cache.exists?("key_3").should eql(false)
42
+
43
+ @cache.exists?("key_4").should eql(false)
44
+ @cache.delete("key_4").should eql(nil)
45
+ @cache.exists?("key_4").should eql(false)
46
+
47
+ @cache.exists?("key_5").should eql(false)
48
+ @cache.delete("key_5").should eql(nil)
49
+ @cache.exists?("key_5").should eql(false)
50
+ end
51
+
52
+ it "delete and write again" do
53
+ @cache.exists?("key_1").should eql(true)
54
+ @cache.delete("key_1")
55
+ @cache.exists?("key_1").should eql(false)
56
+
57
+ @cache.write("key_1", "key_1_value", 0)
58
+
59
+ @cache.read("key_1").should eql("key_1_value")
60
+
61
+ @cache.exists?("key_1").should eql(true)
62
+ end
63
+
64
+ it "data overwrite" do
65
+ @cache.write("key_1", "key_1_value2")
66
+
67
+ @cache.read("key_1").should eql("key_1_value2")
68
+ end
69
+
70
+ it "expire data" do
71
+ @cache.write("key_1", "key_1_value", 0.0000001)
72
+
73
+ sleep(0.0000001)
74
+
75
+ @cache.exists?("key_1").should eql(false)
76
+ end
77
+
78
+ it "negative expires number" do
79
+ @cache.write("key_1", "key_1_value", -1000)
80
+
81
+ @cache.exists?("key_1").should eql(false)
82
+ end
83
+ end
@@ -0,0 +1,164 @@
1
+ require "spec_helper"
2
+
3
+ describe "GoogleApi::Ga::Data" do
4
+ before(:each) do
5
+ @data = GoogleApi::Ga::Data
6
+ end
7
+
8
+
9
+
10
+ # Rows
11
+ # -------------------------------------------------------------------------------------------------
12
+ it "rows" do
13
+ lambda { @data.new.rows }.should raise_error(GoogleApi::SessionError)
14
+ end
15
+
16
+
17
+
18
+ # Default values
19
+ # -------------------------------------------------------------------------------------------------
20
+ it "default values" do
21
+ @data.ids.should eql(nil)
22
+ @data.cache.should eql(nil)
23
+ @data.filters.should eql(nil)
24
+ @data.segment.should eql(nil)
25
+ @data.start_index.should eql(nil)
26
+ @data.max_results.should eql(nil)
27
+
28
+ @data.metrics.should eql([])
29
+ @data.dimensions.should eql([])
30
+ @data.sort.should eql([])
31
+
32
+ @data.start_date.should eql(Date.today)
33
+ @data.end_date.should eql(Date.today)
34
+ end
35
+
36
+
37
+
38
+ # Check date
39
+ # -------------------------------------------------------------------------------------------------
40
+ it "date" do
41
+ @data.to_date("2012-08-20").should be_a_kind_of(Date)
42
+ @data.to_date(DateTime.now).should be_a_kind_of(Date)
43
+ lambda { @data.to_date("2012/08/20") }.should raise_error(GoogleApi::DateError)
44
+ end
45
+
46
+
47
+
48
+ # Check build_param
49
+ # -------------------------------------------------------------------------------------------------
50
+ it "build param" do
51
+ lambda { @data.build_param("attr") }.should raise_error(GoogleApi::TypeError)
52
+
53
+ @data.build_param([:key_1, "ga:key_2", [:key_3, [:key_4]], "ga:key_5", "ga:key_6"]).join(',').should eql("ga:key_1,ga:key_2,ga:key_3,ga:key_4,ga:key_5,ga:key_6")
54
+ end
55
+
56
+
57
+
58
+ # Type error
59
+ # -------------------------------------------------------------------------------------------------
60
+ it "type error" do
61
+ lambda { @data.type?(1, String ) }.should raise_error(GoogleApi::TypeError)
62
+ lambda { @data.type?(1, Integer ) }.should_not raise_error(GoogleApi::TypeError)
63
+ lambda { @data.type?("google_api", String ) }.should_not raise_error(GoogleApi::TypeError)
64
+ end
65
+
66
+
67
+
68
+ # Save parameters
69
+ # -------------------------------------------------------------------------------------------------
70
+ it "save parameters" do
71
+ @data = @data.ids(1)
72
+ .cache(1)
73
+ .start_date(Date.today)
74
+ .end_date(Date.today)
75
+ .metrics(:visits)
76
+ .dimensions(:day, :month, "ga:year")
77
+ .sort("ga:year", :month, :day)
78
+ .filters("country==Czech Republic")
79
+ .segment("gaid::-1")
80
+ .start_index(1)
81
+ .max_results(1)
82
+
83
+ @data.ids.should eql(1)
84
+ @data.cache.should eql(1)
85
+ @data.start_date.should eql(Date.today)
86
+ @data.end_date.should eql(Date.today)
87
+ @data.metrics.should eql(["ga:visits"])
88
+ @data.dimensions.should eql(["ga:day", "ga:month", "ga:year"])
89
+ @data.sort.should eql(["ga:year", "ga:month", "ga:day"])
90
+ @data.filters.should eql("country==Czech Republic")
91
+ @data.segment.should eql("gaid::-1")
92
+ @data.start_index.should eql(1)
93
+ @data.max_results.should eql(1)
94
+ end
95
+
96
+
97
+
98
+ # Date add and sub
99
+ # -------------------------------------------------------------------------------------------------
100
+ it "date add and sub" do
101
+ @data = @data.start_date(+30).end_date(+30)
102
+
103
+ @data.start_date.should eql(Date.today + 30)
104
+ @data.end_date.should eql(Date.today + 30)
105
+
106
+ @data = @data.start_date(Date.today).end_date(Date.today)
107
+ @data = @data.start_date(-30).end_date(-30)
108
+
109
+ @data.start_date.should eql(Date.today - 30)
110
+ @data.end_date.should eql(Date.today - 30)
111
+ end
112
+
113
+
114
+
115
+ # Metrics, dimensions and sort add and sub
116
+ # -------------------------------------------------------------------------------------------------
117
+ it "metrics, dimensions and sort add and sub" do
118
+ @data = @data.metrics(:visits)
119
+ .dimensions(:browser)
120
+ .sort(:javascript)
121
+
122
+ @data.metrics.should eql(["ga:visits"])
123
+ @data.dimensions.should eql(["ga:browser"])
124
+ @data.sort.should eql(["ga:javascript"])
125
+
126
+ @data.metrics_add(:newVisits)
127
+ .dimensions_add(:javaVersion)
128
+ .sort_add(:resolution)
129
+
130
+ @data.metrics.should eql(["ga:visits", "ga:newVisits"])
131
+ @data.dimensions.should eql(["ga:browser", "ga:javaVersion"])
132
+ @data.sort.should eql(["ga:javascript", "ga:resolution"])
133
+
134
+ @data.metrics_sub(:newVisits)
135
+ .dimensions_sub(:javaVersion)
136
+ .sort_sub(:resolution)
137
+
138
+ @data.metrics.should eql(["ga:visits"])
139
+ @data.dimensions.should eql(["ga:browser"])
140
+ @data.sort.should eql(["ga:javascript"])
141
+ end
142
+
143
+
144
+
145
+ # Filters
146
+ # -------------------------------------------------------------------------------------------------
147
+ it "filters" do
148
+ @data = @data.filters{(country == "Czech Republic") & (browser != "Internet Explorer") | (visitors > 1000) | (resolution < 1000) &
149
+ (day >= 1) & (month <= 1) & (year =~ 1) | (operatingSystem !~ "Linux") | (javaVersion % 1) & (newVisits ** 1)}
150
+
151
+ @data.filters.should eql("ga:country==Czech Republic;ga:browser!=Internet Explorer,ga:visitors>1000,ga:resolution<1000;ga:day>=1;ga:month<=1;ga:year=~1,ga:operatingSystem!~Linux,ga:javaVersion=@1;ga:newVisits!@1")
152
+ end
153
+
154
+
155
+
156
+ # Segment
157
+ # -------------------------------------------------------------------------------------------------
158
+ it "segment" do
159
+ @data = @data.segment{(country == "Czech Republic") & (browser != "Internet Explorer") | (visitors > 1000) | (resolution < 1000) &
160
+ (day >= 1) & (month <= 1) & (year =~ 1) | (operatingSystem !~ "Linux") | (javaVersion % 1) & (newVisits ** 1)}
161
+
162
+ @data.segment.should eql("dynamic::ga:country==Czech Republic;ga:browser!=Internet Explorer,ga:visitors>1000,ga:resolution<1000;ga:day>=1;ga:month<=1;ga:year=~1,ga:operatingSystem!~Linux,ga:javaVersion=@1;ga:newVisits!@1")
163
+ end
164
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe "GoogleApi::Ga" do
4
+ it "set default profile id" do
5
+ GoogleApi::Ga.id.should eql(0)
6
+
7
+ GoogleApi::Ga.id(1)
8
+
9
+ GoogleApi::Ga.id.should eql(1)
10
+ end
11
+ end
@@ -1,7 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "GoogleApi config" do
4
-
3
+ describe "GoogleApi::Configuration" do
5
4
  it "Setting is right." do
6
5
  GoogleApi.configure do
7
6
  client_id "1"
@@ -15,13 +14,13 @@ describe "GoogleApi config" do
15
14
  end
16
15
  end
17
16
 
18
- GoogleApi.config.client_id.should match("1")
19
- GoogleApi.config.client_secret.should match("2")
20
- GoogleApi.config.client_developer_email.should match("3")
17
+ GoogleApi.config.client_id.should eq("1")
18
+ GoogleApi.config.client_secret.should eq("2")
19
+ GoogleApi.config.client_developer_email.should eq("3")
21
20
 
22
- GoogleApi.config.ga.client_id.should match("4")
23
- GoogleApi.config.ga.client_secret.should match("5")
24
- GoogleApi.config.ga.client_developer_email.should match("6")
21
+ GoogleApi.config.ga.client_id.should eq("4")
22
+ GoogleApi.config.ga.client_secret.should eq("5")
23
+ GoogleApi.config.ga.client_developer_email.should eq("6")
25
24
 
26
25
  GoogleApi.configure do |config|
27
26
  config.client_id "7"
@@ -35,13 +34,13 @@ describe "GoogleApi config" do
35
34
  end
36
35
  end
37
36
 
38
- GoogleApi.config.client_id.should match("7")
39
- GoogleApi.config.client_secret.should match("8")
40
- GoogleApi.config.client_developer_email.should match("9")
37
+ GoogleApi.config.client_id.should eq("7")
38
+ GoogleApi.config.client_secret.should eq("8")
39
+ GoogleApi.config.client_developer_email.should eq("9")
41
40
 
42
- GoogleApi.config.ga.client_id.should match("10")
43
- GoogleApi.config.ga.client_secret.should match("11")
44
- GoogleApi.config.ga.client_developer_email.should match("12")
41
+ GoogleApi.config.ga.client_id.should eq("10")
42
+ GoogleApi.config.ga.client_secret.should eq("11")
43
+ GoogleApi.config.ga.client_developer_email.should eq("12")
45
44
 
46
45
  GoogleApi.config.client_id = "13"
47
46
  GoogleApi.config.client_secret = "14"
@@ -51,13 +50,12 @@ describe "GoogleApi config" do
51
50
  GoogleApi.config.ga.client_secret = "17"
52
51
  GoogleApi.config.ga.client_developer_email = "18"
53
52
 
54
- GoogleApi.config.client_id.should match("13")
55
- GoogleApi.config.client_secret.should match("14")
56
- GoogleApi.config.client_developer_email.should match("15")
53
+ GoogleApi.config.client_id.should eq("13")
54
+ GoogleApi.config.client_secret.should eq("14")
55
+ GoogleApi.config.client_developer_email.should eq("15")
57
56
 
58
- GoogleApi.config.ga.client_id.should match("16")
59
- GoogleApi.config.ga.client_secret.should match("17")
60
- GoogleApi.config.ga.client_developer_email.should match("18")
57
+ GoogleApi.config.ga.client_id.should eq("16")
58
+ GoogleApi.config.ga.client_secret.should eq("17")
59
+ GoogleApi.config.ga.client_developer_email.should eq("18")
61
60
  end
62
-
63
61
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta
5
- prerelease: 6
4
+ version: 1.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ondřej Moravčík
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-19 00:00:00.000000000 Z
12
+ date: 2012-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-api-client
@@ -68,6 +68,7 @@ extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
70
  - .rspec
71
+ - .travis.yml
71
72
  - Gemfile
72
73
  - LICENSE
73
74
  - README.md
@@ -93,6 +94,9 @@ files:
93
94
  - lib/google_api/ga/management/webproperty.rb
94
95
  - lib/google_api/ga/session.rb
95
96
  - lib/google_api/version.rb
97
+ - spec/lib/google_api_cache_spec.rb
98
+ - spec/lib/google_api_ga_data_spec.rb
99
+ - spec/lib/google_api_ga_spec.rb
96
100
  - spec/lib/google_api_spec.rb
97
101
  - spec/spec_helper.rb
98
102
  homepage: https://github.com/ondra-m/google_api
@@ -110,9 +114,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
114
  required_rubygems_version: !ruby/object:Gem::Requirement
111
115
  none: false
112
116
  requirements:
113
- - - ! '>'
117
+ - - ! '>='
114
118
  - !ruby/object:Gem::Version
115
- version: 1.3.1
119
+ version: '0'
116
120
  requirements: []
117
121
  rubyforge_project:
118
122
  rubygems_version: 1.8.23
@@ -120,6 +124,9 @@ signing_key:
120
124
  specification_version: 3
121
125
  summary: Simple Google Api. Include google analytics.
122
126
  test_files:
127
+ - spec/lib/google_api_cache_spec.rb
128
+ - spec/lib/google_api_ga_data_spec.rb
129
+ - spec/lib/google_api_ga_spec.rb
123
130
  - spec/lib/google_api_spec.rb
124
131
  - spec/spec_helper.rb
125
132
  has_rdoc: