trackablaze 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -132,8 +132,8 @@ are made of up of a **YAML config file** and a **ruby code file**.
132
132
 
133
133
 
134
134
  A tracker must implement get_metrics() method. This method takes
135
- in an array of configurations. Your tracker may choose to query
136
- for each configuration one by one or use any available optimized
135
+ in an array of tracker items (i.e. configurations). Your tracker may choose to query
136
+ for each tracker item one by one or use any available optimized
137
137
  API calls. For example, the above code queries Twitter API once
138
138
  for each user handle, but can be optimized by using the
139
139
  ::Twitter.users API call that takes an array of user handles.
@@ -152,5 +152,5 @@ please see the wiki.
152
152
 
153
153
  Trackablaze and its recipes are distributed under the MIT License.
154
154
 
155
- [1]:http://railswizard.org/
155
+ [1]:http://trackablaze.com
156
156
  [2]:https://github.com/aflatune/trackablaze-gem/tree/master/trackers
@@ -1,5 +1,7 @@
1
1
  require 'trackablaze/utils'
2
2
  require 'trackablaze/command'
3
+ require 'trackablaze/param'
4
+ require 'trackablaze/metric'
3
5
  require 'trackablaze/tracker_item'
4
6
  require 'trackablaze/tracker'
5
7
 
@@ -0,0 +1,16 @@
1
+ module Trackablaze
2
+ class Metric
3
+ attr_accessor :name, :title, :config
4
+
5
+ def initialize(name, config)
6
+ @name = name
7
+ @title = config['title']
8
+ @default = config['default']
9
+ @config = config
10
+ end
11
+
12
+ def default?
13
+ @default == true
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Trackablaze
2
+ class Param
3
+ attr_accessor :name, :title, :description, :config
4
+
5
+ def initialize(name, config)
6
+ @name = name
7
+ @title = config['title']
8
+ @description = config['description']
9
+ @config = config
10
+ end
11
+ end
12
+ end
@@ -1,58 +1,68 @@
1
1
  module Trackablaze
2
- class Tracker
3
-
4
- # A string that uniquely identifies this instance of the tracker
5
- # This is to optimize multiple instances that are exactly the same
6
- # e.g. if 100 people want to track amolk's twitter account, the tracker can
7
- # be run only once, optimizing calls to Twitter API.
8
- def self.key(config)
9
- # By default we use all params and metrics
10
- sb = []
11
- sb.push(self.handle)
12
- sb.push(config['params'].flatten) if config['params']
13
- sb.push((config['metrics'] || default_metrics).flatten)
14
- sb.flatten.join('_')
15
- end
16
-
17
- # A string that uniquely identifies this instance of the tracker, without the metrics list
18
- # This is used in the csv output
19
- def self.key2(config)
20
- # By default we use all params and metrics
21
- sb = []
22
- sb.push(self.handle)
23
- sb.push(config['params'].flatten) if config['params']
24
- sb.flatten.join('_')
25
- end
26
-
2
+ class Tracker
27
3
  class << self
28
- attr_accessor :trackers
29
-
4
+ attr_accessor :trackers, :info, :handle, :params, :metrics, :title, :default_metrics
5
+
6
+ def load
7
+ @info = YAML::load( File.open( File.dirname(__FILE__) + "/../../trackers/#{self.handle}.yml" ) )
8
+ @title = @info['title']
9
+ @params = {}
10
+
11
+ self.info['params'].each do |param_name, param_config|
12
+ @params[param_name] = Param.new(param_name, param_config)
13
+ end
14
+
15
+ @metrics = {}
16
+ self.info['metrics'].each do |metric_name, metric_config|
17
+ @metrics[metric_name] = Metric.new(metric_name, metric_config)
18
+ end
19
+
20
+ @default_metrics = self.info['metrics'].collect{|k, v| k if v && v['default']}.compact
21
+ end
22
+
23
+ def handle
24
+ @handle ||= self.name.split('::')[1].underscore
25
+ end
26
+
30
27
  def load_trackers
31
28
  @trackers = {}
32
29
  Trackablaze::Tracker.subclasses.each do |t|
30
+ t.load
33
31
  @trackers[t.handle] = t
34
32
  end
35
- end
36
- end
37
-
38
- def self.handle
39
- @handle ||= self.name.split('::')[1].underscore
40
- end
41
-
42
- def self.info
43
- @info ||= YAML::load( File.open( File.dirname(__FILE__) + "/../../trackers/#{self.handle}.yml" ) )
44
- end
45
-
46
- def self.title
47
- self.info['title']
48
- end
49
-
50
- def self.default_metrics
51
- @default_metrics ||= self.info['metrics'].collect{|k, v| k if v && v['default']}.compact
52
- end
53
-
54
- def get_metrics(params, metrics)
55
- {}
33
+ end
34
+
35
+ # A string that uniquely identifies this instance of the tracker
36
+ # This is to optimize multiple instances that are exactly the same
37
+ # e.g. if 100 people want to track amolk's twitter account, the tracker can
38
+ # be run only once, optimizing calls to Twitter API.
39
+ def key(config)
40
+ # By default we use all params and metrics
41
+ sb = []
42
+ sb.push(self.handle)
43
+ sb.push(config['params'].flatten) if config['params']
44
+ sb.push((config['metrics'] || default_metrics).flatten)
45
+ sb.flatten.join('_')
46
+ end
47
+
48
+ # A string that uniquely identifies this instance of the tracker, without the metrics list
49
+ # This is used in the csv output
50
+ def key2(config)
51
+ # By default we use all params and metrics
52
+ sb = []
53
+ sb.push(self.handle)
54
+ sb.push(config['params'].flatten) if config['params']
55
+ sb.flatten.join('_')
56
+ end
57
+
58
+
59
+ def param_title(param_name)
60
+ (params[param_name].title if params[param_name]) || param_name
61
+ end
62
+
63
+ def metric_title(metric_name)
64
+ (metrics[metric_name].title if metrics[metric_name]) || metric_name
65
+ end
56
66
  end
57
67
 
58
68
  def add_error(metrics, error, field = nil)
@@ -60,22 +70,5 @@ module Trackablaze
60
70
  metrics['errors'].push({:error => error, :field => field})
61
71
  end
62
72
 
63
- def self.param_title(param_name)
64
- param_info = info['params'][param_name]
65
- if param_info
66
- param_info['name']
67
- else
68
- param_name
69
- end
70
- end
71
-
72
- def self.metric_title(metric_name)
73
- metric_info = info['metrics'][metric_name]
74
- if metric_info
75
- metric_info['name']
76
- else
77
- metric_name
78
- end
79
- end
80
73
  end
81
74
  end
@@ -7,5 +7,5 @@ Dir[File.dirname(__FILE__) + '/support/*'].each{|path| require path}
7
7
  require 'trackablaze'
8
8
 
9
9
  RSpec.configure do |config|
10
-
10
+ Trackablaze::Tracker.load_trackers
11
11
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ # This is a simple set of tests to make sure that
4
+ # all trackers conform to basic requirements.
5
+
6
+ Trackablaze::Tracker.trackers.each do |tracker_handle, tracker_class|
7
+ describe tracker_class do
8
+ describe 'basics' do
9
+ it("should have a handle"){ tracker_class.handle.should be_kind_of(String); tracker_class.handle.should_not be_empty }
10
+ end
11
+
12
+ describe 'tracker configuration yml' do
13
+ it("should exist (#{tracker_class.handle}.yml)") { tracker_class.info.should_not be_nil; }
14
+ it("should be a hash"){ tracker_class.info.should be_kind_of(Hash); }
15
+ end
16
+
17
+ describe 'tracker configuration' do
18
+ it("should have params"){ tracker_class.params.should be_kind_of(Hash); }
19
+ it("should have metrics"){ tracker_class.metrics.should be_kind_of(Hash); }
20
+ end
21
+
22
+ describe 'tracker params' do
23
+ tracker_class.params.each do |param_name, param|
24
+ describe "param #{param_name}" do
25
+ it("should have a name"){ param.name.should be_kind_of(String); param.name.should_not be_empty }
26
+ it("should have a title"){ param.title.should be_kind_of(String); param.title.should_not be_empty }
27
+ it("should have a description"){ param.description.should be_kind_of(String); param.description.should_not be_empty }
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'tracker metrics' do
33
+ tracker_class.metrics.each do |metric_name, metric|
34
+ describe "metric #{metric_name}" do
35
+ it("should have a name"){ metric.name.should be_kind_of(String); metric.name.should_not be_empty }
36
+ end
37
+ end
38
+ end
39
+
40
+ describe 'tracker interface' do
41
+ ['get_metrics'].each do |method_name|
42
+ it("should have method #{method_name}"){ tracker_class.new.should respond_to(method_name) }
43
+ end
44
+
45
+ it("get_metrics should return empty array when given an empty array"){ tracker_class.new.get_metrics([]).should == [] }
46
+ end
47
+ end
48
+ end
@@ -2,11 +2,11 @@ title: 'Facebook page'
2
2
 
3
3
  params:
4
4
  page_id:
5
- name: 'Page ID'
5
+ title: 'Page ID'
6
6
  description: 'This is the page ID (e.g. michaeljackson or 125602120804573)'
7
7
  type: string
8
8
 
9
9
  metrics:
10
10
  likes:
11
- name: 'Likes'
11
+ title: 'Likes'
12
12
  default: true
@@ -2,42 +2,42 @@ title: 'Klout'
2
2
 
3
3
  params:
4
4
  username:
5
- name: 'Username'
5
+ title: 'Username'
6
6
  description: 'Klout username'
7
7
  type: string
8
8
 
9
9
  metrics:
10
10
  kscore:
11
- name: 'Score'
11
+ title: 'Score'
12
12
  description: 'Klout score'
13
13
  default: true
14
14
 
15
15
  slope:
16
- name: 'Slope'
16
+ title: 'Slope'
17
17
  description: 'How fast Klout score is changing'
18
18
 
19
19
  kclass:
20
- name: 'Class'
20
+ title: 'Class'
21
21
  description: 'Klout class assigned to the user'
22
22
  default: true
23
23
 
24
24
  network_score:
25
- name: 'Network score'
25
+ title: 'Network score'
26
26
  description: 'Network Influence is the influence level of your engaged audience (see http://corp.klout.com/kscore)'
27
27
 
28
28
  amplification_score:
29
- name: 'Amplification probability'
29
+ title: 'Amplification probability'
30
30
  description: 'Amplification Probability is the likelihood that your content will be acted upon (see http://corp.klout.com/kscore)'
31
31
 
32
32
  true_reach:
33
- name: 'True reach'
33
+ title: 'True reach'
34
34
  description: 'True Reach is the size of your engaged audience (see http://corp.klout.com/kscore)'
35
35
 
36
36
  delta_1day:
37
- name: '1 day delta'
37
+ title: '1 day delta'
38
38
  description: 'Change in Klout score in 1 day'
39
39
  default: true
40
40
 
41
41
  delta_5day:
42
- name: '5 day delta'
42
+ title: '5 day delta'
43
43
  description: 'Change in Klout score in 5 days'
@@ -2,11 +2,11 @@ title: 'Google PageRank'
2
2
 
3
3
  params:
4
4
  domain:
5
- name: 'Domain'
5
+ title: 'Domain'
6
6
  description: 'Domain name (e.g. google.com)'
7
7
  type: string
8
8
 
9
9
  metrics:
10
10
  pagerank:
11
- name: 'PageRank'
11
+ title: 'PageRank'
12
12
  default: true
@@ -2,15 +2,15 @@ title: 'Twitter'
2
2
 
3
3
  params:
4
4
  handle:
5
- name: 'Handle'
5
+ title: 'Handle'
6
6
  description: 'Twitter handle, i.e. username'
7
7
  type: string
8
8
 
9
9
  metrics:
10
10
  followers_count:
11
- name: 'Followers'
11
+ title: 'Followers'
12
12
  default: true
13
13
  friends_count:
14
- name: 'Following'
14
+ title: 'Following'
15
15
  statuses_count:
16
- name: 'Tweets'
16
+ title: 'Tweets'
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Trackablaze
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trackablaze
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Amol Kelkar
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-19 00:00:00 -07:00
13
+ date: 2011-06-23 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -123,6 +123,8 @@ extra_rdoc_files: []
123
123
 
124
124
  files:
125
125
  - lib/trackablaze/command.rb
126
+ - lib/trackablaze/metric.rb
127
+ - lib/trackablaze/param.rb
126
128
  - lib/trackablaze/tracker.rb
127
129
  - lib/trackablaze/tracker_item.rb
128
130
  - lib/trackablaze/utils.rb
@@ -138,6 +140,7 @@ files:
138
140
  - README.markdown
139
141
  - version.rb
140
142
  - spec/spec_helper.rb
143
+ - spec/trackablaze/trackers/sanity_spec.rb
141
144
  - bin/trackablaze
142
145
  has_rdoc: true
143
146
  homepage: http://trackablaze.com
@@ -169,3 +172,4 @@ specification_version: 3
169
172
  summary: A tool to track web metrics.
170
173
  test_files:
171
174
  - spec/spec_helper.rb
175
+ - spec/trackablaze/trackers/sanity_spec.rb