kenshoo 0.1.0

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/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake'
4
+ gem 'echoe'
5
+ gem 'activesupport'
6
+ gem 'actionpack'
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionpack (3.0.3)
6
+ activemodel (= 3.0.3)
7
+ activesupport (= 3.0.3)
8
+ builder (~> 2.1.2)
9
+ erubis (~> 2.6.6)
10
+ i18n (~> 0.4)
11
+ rack (~> 1.2.1)
12
+ rack-mount (~> 0.6.13)
13
+ rack-test (~> 0.5.6)
14
+ tzinfo (~> 0.3.23)
15
+ activemodel (3.0.3)
16
+ activesupport (= 3.0.3)
17
+ builder (~> 2.1.2)
18
+ i18n (~> 0.4)
19
+ activesupport (3.0.3)
20
+ builder (2.1.2)
21
+ echoe (4.3.1)
22
+ gemcutter
23
+ rubyforge
24
+ erubis (2.6.6)
25
+ abstract (>= 1.0.0)
26
+ gemcutter (0.6.1)
27
+ i18n (0.5.0)
28
+ json_pure (1.4.6)
29
+ rack (1.2.1)
30
+ rack-mount (0.6.13)
31
+ rack (>= 1.0.0)
32
+ rack-test (0.5.6)
33
+ rack (>= 1.0)
34
+ rake (0.8.7)
35
+ rubyforge (2.0.4)
36
+ json_pure (>= 1.1.7)
37
+ tzinfo (0.3.23)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ actionpack
44
+ activesupport
45
+ echoe
46
+ rake
data/Manifest ADDED
@@ -0,0 +1,7 @@
1
+ Gemfile
2
+ Gemfile.lock
3
+ Manifest
4
+ README.rdoc
5
+ Rakefile
6
+ lib/kenshoo.rb
7
+ test/kenshoo_test.rb
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Kenshoo
2
+
3
+ Rails gem for Wrapping Kenshoo tracking id on given affiliate link
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'rake'
6
+ require 'echoe'
7
+
8
+ Echoe.new('kenshoo', '0.1.0') do |p|
9
+ p.description = "Wrap Kenshoo tracking id on given affiliate link"
10
+ p.url = "http://github.com/58phases/kenshoo"
11
+ p.author = "David Hsu"
12
+ p.email = "david@yibs.com"
13
+ p.ignore_pattern = ["tmp/*", "script/*"]
14
+ p.development_dependencies = []
15
+ end
16
+
17
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/kenshoo.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{kenshoo}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["David Hsu"]
9
+ s.date = %q{2010-12-10}
10
+ s.description = %q{Wrap Kenshoo tracking id on given affiliate link}
11
+ s.email = %q{david@yibs.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/kenshoo.rb"]
13
+ s.files = ["Gemfile", "Gemfile.lock", "Manifest", "README.rdoc", "Rakefile", "lib/kenshoo.rb", "test/kenshoo_test.rb", "kenshoo.gemspec"]
14
+ s.homepage = %q{http://github.com/58phases/kenshoo}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Kenshoo", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{kenshoo}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Wrap Kenshoo tracking id on given affiliate link}
20
+ s.test_files = ["test/kenshoo_test.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
data/lib/kenshoo.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'action_controller'
2
+
3
+ module Kenshoo
4
+ def self.included(base) base.extend ClassMethods
5
+ # Automatic before filter (optional)
6
+ base.before_filter :set_kenshoo_tracking_id
7
+ end
8
+
9
+ KENSHOO_PARAMS = { 'CJ' => 'sid', 'LS' => 'u1', 'PJ' => 'sid', 'GN' => 'mid', 'SAS' => 'afftrack' }
10
+
11
+ def self.link_with_tracking_id(instance, session)
12
+ link = instance.try(:link)
13
+ if instance.class == Coupon && link
14
+ network_code = nil
15
+ begin
16
+ network_code = instance.store.affiliate_network.code
17
+ rescue
18
+ puts "Error on getting network code"
19
+ end
20
+ return wrap_link_with_tracking_id(link, network_code, session)
21
+ else
22
+ return nil
23
+ end
24
+ end
25
+
26
+ def self.wrap_link_with_tracking_id(link, network_code, session)
27
+ outlink = link
28
+ begin
29
+ tracking_param = KENSHOO_PARAMS[network_code]
30
+ if !session['sid'].blank? && !tracking_param.blank?
31
+ uri = URI(link)
32
+ if uri.query
33
+ uri.query << "&#{tracking_param.upcase}=#{session['sid']}"
34
+ else
35
+ uri.query = "#{tracking_param.upcase}=#{session['sid']}"
36
+ end
37
+ outlink = uri.to_s
38
+ end
39
+ rescue => e
40
+ if defined?(HoptoadNotifier) == "constant"
41
+ HoptoadNotifier.notify(:error_class => e.class.name, :error_message => e.message)
42
+ end
43
+ puts "[#{e.class.name}] #{e.message}"
44
+ end
45
+ return outlink
46
+ end
47
+
48
+ module ClassMethods
49
+
50
+ end
51
+
52
+ private
53
+
54
+ def set_kenshoo_tracking_id
55
+ ['sid'].each do |track_param|
56
+ track_id = params[track_param] || params[track_param.upcase]
57
+ if session[track_param].blank? && !track_id.blank?
58
+ session[track_param] = track_id
59
+ elsif !session[track_param].blank? && !track_id.blank?
60
+ session[track_param] = track_id if session[track_param] != track_id
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ ActionController::Base.send(:include, Kenshoo)
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'kenshoo'
3
+
4
+ class KenshooTest < Test::Unit::TestCase
5
+ def test_wrap_link_with_tracking_id
6
+ link = "http://www.tkqlhce.com/click-3986307-10731808"
7
+ network_code = 'CJ'
8
+ session = {'sid' => '452b3346-37bb-0bc8-7290-000057cc146f'}
9
+ outlink = Kenshoo.wrap_link_with_tracking_id(link, network_code, session)
10
+ assert_equal outlink, "http://www.tkqlhce.com/click-3986307-10731808?SID=452b3346-37bb-0bc8-7290-000057cc146f"
11
+
12
+ network_code = 'LS'
13
+ outlink = Kenshoo.wrap_link_with_tracking_id(link, network_code, session)
14
+ assert_equal outlink, "http://www.tkqlhce.com/click-3986307-10731808?U1=452b3346-37bb-0bc8-7290-000057cc146f"
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kenshoo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - David Hsu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-10 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Wrap Kenshoo tracking id on given affiliate link
23
+ email: david@yibs.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ - lib/kenshoo.rb
31
+ files:
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - Manifest
35
+ - README.rdoc
36
+ - Rakefile
37
+ - lib/kenshoo.rb
38
+ - test/kenshoo_test.rb
39
+ - kenshoo.gemspec
40
+ has_rdoc: true
41
+ homepage: http://github.com/58phases/kenshoo
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - Kenshoo
50
+ - --main
51
+ - README.rdoc
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 11
69
+ segments:
70
+ - 1
71
+ - 2
72
+ version: "1.2"
73
+ requirements: []
74
+
75
+ rubyforge_project: kenshoo
76
+ rubygems_version: 1.3.7
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Wrap Kenshoo tracking id on given affiliate link
80
+ test_files:
81
+ - test/kenshoo_test.rb