sfanalytics 0.2.13 → 0.2.15

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/README.rdoc CHANGED
@@ -16,7 +16,7 @@ A simple example of its usage is:
16
16
  :city => 'Test City',
17
17
  :county => 'Test County',
18
18
  :country => 'Test Kingdom'
19
- }, 'UA-1234567-1'
19
+ }
20
20
  )
21
21
 
22
22
  analytics_add_item( {
@@ -25,7 +25,7 @@ A simple example of its usage is:
25
25
  :category => 'Test Categoru',
26
26
  :price => '1.99',
27
27
  :quantity => '2'
28
- }, 'UA-1234567-1'
28
+ }
29
29
  )
30
30
 
31
31
  analytics_add_item( {
@@ -34,14 +34,14 @@ A simple example of its usage is:
34
34
  :category => 'Test Categoru',
35
35
  :price => '1.99',
36
36
  :quantity => '3'
37
- }, 'UA-1234567-2'
37
+ }
38
38
  )
39
39
 
40
40
  %>
41
41
 
42
42
  <%= analytics_generate('UA-1234566-1') %>
43
43
 
44
- This adds a transaction, then some line items to the transaction, then outputs the analytics code when analytics_generate is called. Technically the analytics ID is only required on the first helper call, but it does no harm to include it on each call.
44
+ This adds a transaction, then some line items to the transaction, then outputs the analytics code when analytics_generate is called.
45
45
 
46
46
  == Note on Patches/Pull Requests
47
47
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.13
1
+ 0.2.15
@@ -2,17 +2,17 @@ module SFanalytics
2
2
  module ViewHelpers
3
3
  attr_reader :analytics
4
4
  def analytics_generate(analytics_id = '')
5
- @analytics = SFanalytics::SFa::new(analytics_id) unless @analytics
6
- return @analytics.generate
5
+ @analytics = SFanalytics::SFa::new() unless @analytics
6
+ return @analytics.generate(analytics_id)
7
7
  end
8
8
 
9
- def analytics_add_transaction(transaction, analytics_id = '')
10
- @analytics = SFanalytics::SFa::new(analytics_id) unless @analytics
9
+ def analytics_add_transaction(transaction)
10
+ @analytics = SFanalytics::SFa::new() unless @analytics
11
11
  return @analytics.add_transaction(transaction)
12
12
  end
13
13
 
14
- def analytics_add_item(item, analytics_id = '')
15
- @analytics = SFanalytics::SFa::new(analytics_id) unless @analytics
14
+ def analytics_add_item(item)
15
+ @analytics = SFanalytics::SFa::new() unless @analytics
16
16
  return @analytics.add_line_item(item)
17
17
  end
18
18
  end
data/lib/sfanalytics.rb CHANGED
@@ -9,15 +9,16 @@ module SFanalytics
9
9
  ActionView::Base.send :include, ViewHelpers
10
10
  end
11
11
 
12
- def initialize(analytics_id)
13
- raise ArgumentError.new if ! analytics_id.match(/UA-\d{0,8}-\d{0,3}/)
14
- @analytics_id = analytics_id
12
+ def initialize()
15
13
  @line_items = ''
16
14
  end
17
15
 
18
- def generate
16
+ def generate(analytics_id)
19
17
  template = File.read(File.dirname(__FILE__) + '/../templates/analytics.html.haml')
20
-
18
+
19
+ raise ArgumentError.new if ! analytics_id.match(/UA-\d{0,8}-\d{0,3}/)
20
+ @analytics_id = analytics_id
21
+
21
22
  obj = Object.new
22
23
  Haml::Engine.new(template).def_method(obj, :render, :analytics_id, :analytics_transaction, :line_items)
23
24
  return obj.render(
data/sfanalytics.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sfanalytics}
8
- s.version = "0.2.13"
8
+ s.version = "0.2.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Graeme Lawton"]
12
- s.date = %q{2010-05-04}
12
+ s.date = %q{2010-05-05}
13
13
  s.description = %q{
14
14
  SFanalytics provides Google Analytics for your app. Probably only really
15
15
  useful for Ecommerce users of analytics, to provide the functionality to add
@@ -3,9 +3,8 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe SFanalytics do
4
4
  describe SFanalytics::SFa, "initialize" do
5
5
 
6
- it "should be instantiated with a valid looking analytics id" do
7
- lambda { SFanalytics::SFa.new( "UA-1234567-1" ) }.should_not raise_error
8
- lambda { SFanalytics::SFa.new() }.should raise_error(ArgumentError)
6
+ it "should be instantiated" do
7
+ lambda { SFanalytics::SFa.new() }.should_not raise_error
9
8
  lambda { SFanalytics::SFa.new( "foobar" ) }.should raise_error(ArgumentError)
10
9
  end
11
10
 
@@ -14,16 +13,17 @@ describe SFanalytics do
14
13
  describe SFanalytics::SFa, "generate" do
15
14
 
16
15
  before(:each) do
17
- @sfanalytics = SFanalytics::SFa.new('UA-1234567-1')
16
+ @sfanalytics = SFanalytics::SFa.new()
18
17
  end
19
18
 
20
19
  it "should be able to generate output code" do
21
20
  @sfanalytics.should respond_to(:generate)
22
- @sfanalytics.generate.class.should == String
21
+ lambda { SFanalytics::SFa.new.generate() }.should raise_error(ArgumentError)
22
+ @sfanalytics.generate('UA-1234567-1').class.should == String
23
23
  end
24
24
 
25
25
  it "should generate the correct basic tracking code" do
26
- @sfanalytics.generate.should == <<-EOS
26
+ @sfanalytics.generate('UA-1234567-1').should == <<-EOS
27
27
  <script type='text/javascript'>
28
28
  var _gaq = _gaq || [];
29
29
  _gaq.push(['_setAccount', 'UA-1234567-1']);
@@ -43,7 +43,7 @@ describe SFanalytics do
43
43
 
44
44
  describe SFanalytics::SFa, "generate_transaction" do
45
45
  before(:each) do
46
- @sfanalytics = SFanalytics::SFa.new('UA-1234567-1')
46
+ @sfanalytics = SFanalytics::SFa.new
47
47
  @trx_data = {
48
48
  :id => 'A01',
49
49
  :store_name => 'TEST STORE',
@@ -64,7 +64,7 @@ describe SFanalytics do
64
64
 
65
65
  it "should generate the correct code with a transaction" do
66
66
  @sfanalytics.add_transaction(@trx_data).should
67
- @sfanalytics.generate().should == <<-EOS
67
+ @sfanalytics.generate('UA-1234567-1').should == <<-EOS
68
68
  <script type='text/javascript'>
69
69
  var _gaq = _gaq || [];
70
70
  _gaq.push(['_setAccount', 'UA-1234567-1']);
@@ -93,7 +93,7 @@ describe SFanalytics do
93
93
  describe SFanalytics::SFa, "Add order items" do
94
94
 
95
95
  before(:each) do
96
- @sfanalytics = SFanalytics::SFa.new('UA-1234567-1')
96
+ @sfanalytics = SFanalytics::SFa.new()
97
97
  @sfanalytics.add_transaction({
98
98
  :id => 'A01',
99
99
  :store_name => 'TEST STORE',
@@ -117,17 +117,17 @@ describe SFanalytics do
117
117
  @sfanalytics.should respond_to(:add_line_item)
118
118
  lambda {@sfanalytics.add_line_item}.should raise_error(ArgumentError)
119
119
  @sfanalytics.add_line_item(@line_item).should == true
120
- @sfanalytics.generate.should match /_addItem/
120
+ @sfanalytics.generate('UA-1234567-1').should match /_addItem/
121
121
  end
122
122
 
123
123
  it "should allow multiple line_items to be added" do
124
124
  @sfanalytics.add_line_item(@line_item)
125
125
  @sfanalytics.add_line_item(@line_item)
126
126
  #Check there are two instances of _addItem
127
- @sfanalytics.generate.split(/_addItem/).count.should == 3
127
+ @sfanalytics.generate('UA-1234567-1').split(/_addItem/).count.should == 3
128
128
 
129
- @sfanalytics.generate.split(/TEST123/).count.should == 3
130
- @sfanalytics.generate.split(/A01/).count.should == 4
129
+ @sfanalytics.generate('UA-1234567-1').split(/TEST123/).count.should == 3
130
+ @sfanalytics.generate('UA-1234567-1').split(/A01/).count.should == 4
131
131
  end
132
132
 
133
133
  end
@@ -144,7 +144,7 @@ describe SFanalytics do
144
144
  end
145
145
 
146
146
  it "should fail if you try to add items with no transaction" do
147
- sfanalytics = SFanalytics::SFa.new('UA-1234567-1')
147
+ sfanalytics = SFanalytics::SFa.new
148
148
  lambda{sfanalytics.add_line_item(@line_item)}.should raise_error
149
149
  end
150
150
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 13
9
- version: 0.2.13
8
+ - 15
9
+ version: 0.2.15
10
10
  platform: ruby
11
11
  authors:
12
12
  - Graeme Lawton
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-04 00:00:00 +01:00
17
+ date: 2010-05-05 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency