aggregator-gem 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.document +5 -0
  2. data/Gemfile +16 -0
  3. data/Gemfile.lock +91 -0
  4. data/LICENSE.txt +20 -0
  5. data/README +0 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +53 -0
  8. data/VERSION +1 -0
  9. data/app/controllers/application_controller.rb +3 -0
  10. data/app/controllers/cj_fetch_controller.rb +5 -0
  11. data/app/helpers/application_helper.rb +2 -0
  12. data/app/helpers/cj_fetch_helper.rb +2 -0
  13. data/app/models/advertiser.rb +18 -0
  14. data/app/models/advertiser_category_link.rb +6 -0
  15. data/app/models/advertiser_site_link.rb +5 -0
  16. data/app/models/advertiser_vendor_link.rb +4 -0
  17. data/app/models/category.rb +12 -0
  18. data/app/models/category_coupon_link.rb +6 -0
  19. data/app/models/cj_coupon.rb +148 -0
  20. data/app/models/coupon.rb +14 -0
  21. data/app/models/coupon_product_link.rb +4 -0
  22. data/app/models/product.rb +6 -0
  23. data/app/models/site.rb +11 -0
  24. data/app/models/site_vendor_link.rb +5 -0
  25. data/app/models/sites_vendors.rb +2 -0
  26. data/app/models/vendor.rb +9 -0
  27. data/app/views/layouts/application.html.erb +14 -0
  28. data/db/migrate/20111004055535_create_sites.rb +15 -0
  29. data/db/migrate/20111004055623_create_vendors.rb +14 -0
  30. data/db/migrate/20111004055648_create_advertisers.rb +23 -0
  31. data/db/migrate/20111004055950_create_products.rb +14 -0
  32. data/db/migrate/20111004060028_create_categories.rb +16 -0
  33. data/db/migrate/20111005025903_create_coupons.rb +21 -0
  34. data/db/migrate/20111010054838_create_site_vendor_links.rb +15 -0
  35. data/db/migrate/20111012024234_create_coupon_product_links.rb +14 -0
  36. data/db/migrate/20111012024246_create_category_coupon_links.rb +14 -0
  37. data/db/migrate/20111012024455_create_advertiser_site_links.rb +14 -0
  38. data/db/migrate/20111012025453_create_advertiser_vendor_links.rb +14 -0
  39. data/db/migrate/20111012061448_add_sites_info.rb +12 -0
  40. data/db/migrate/20111012190927_create_advertiser_category_links.rb +14 -0
  41. data/lib/coupon_aggregator.rb +0 -0
  42. data/tasks/coupon_aggregator_tasks.rake +4 -0
  43. data/test/helper.rb +18 -0
  44. data/test/test_coupon_aggregator.rb +7 -0
  45. metadata +172 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'rails', '3.0.9'
6
+ gem 'mysql2', '< 0.3'
7
+ gem 'nokogiri', '1.5.0'
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "shoulda", ">= 0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.6.4"
15
+ gem "rcov", ">= 0"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.9)
6
+ actionpack (= 3.0.9)
7
+ mail (~> 2.2.19)
8
+ actionpack (3.0.9)
9
+ activemodel (= 3.0.9)
10
+ activesupport (= 3.0.9)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.9)
19
+ activesupport (= 3.0.9)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.9)
23
+ activemodel (= 3.0.9)
24
+ activesupport (= 3.0.9)
25
+ arel (~> 2.0.10)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.9)
28
+ activemodel (= 3.0.9)
29
+ activesupport (= 3.0.9)
30
+ activesupport (3.0.9)
31
+ arel (2.0.10)
32
+ builder (2.1.2)
33
+ erubis (2.6.6)
34
+ abstract (>= 1.0.0)
35
+ git (1.2.5)
36
+ i18n (0.5.0)
37
+ jeweler (1.6.4)
38
+ bundler (~> 1.0)
39
+ git (>= 1.2.5)
40
+ rake
41
+ json (1.6.1)
42
+ mail (2.2.19)
43
+ activesupport (>= 2.3.6)
44
+ i18n (>= 0.4.0)
45
+ mime-types (~> 1.16)
46
+ treetop (~> 1.4.8)
47
+ mime-types (1.16)
48
+ mysql2 (0.2.13)
49
+ nokogiri (1.5.0)
50
+ polyglot (0.3.2)
51
+ rack (1.2.4)
52
+ rack-mount (0.6.14)
53
+ rack (>= 1.0.0)
54
+ rack-test (0.5.7)
55
+ rack (>= 1.0)
56
+ rails (3.0.9)
57
+ actionmailer (= 3.0.9)
58
+ actionpack (= 3.0.9)
59
+ activerecord (= 3.0.9)
60
+ activeresource (= 3.0.9)
61
+ activesupport (= 3.0.9)
62
+ bundler (~> 1.0)
63
+ railties (= 3.0.9)
64
+ railties (3.0.9)
65
+ actionpack (= 3.0.9)
66
+ activesupport (= 3.0.9)
67
+ rake (>= 0.8.7)
68
+ rdoc (~> 3.4)
69
+ thor (~> 0.14.4)
70
+ rake (0.9.2)
71
+ rcov (0.9.11)
72
+ rdoc (3.10)
73
+ json (~> 1.4)
74
+ shoulda (2.11.3)
75
+ thor (0.14.6)
76
+ treetop (1.4.10)
77
+ polyglot
78
+ polyglot (>= 0.3.1)
79
+ tzinfo (0.3.30)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ bundler (~> 1.0.0)
86
+ jeweler (~> 1.6.4)
87
+ mysql2 (< 0.3)
88
+ nokogiri (= 1.5.0)
89
+ rails (= 3.0.9)
90
+ rcov
91
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Allen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = coupon_aggregator
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to coupon_aggregator
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Allen. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "aggregator-gem"
18
+ gem.homepage = "https://github.com/allentsai/aggregator-gem"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Aggregates Coupons}
21
+ gem.description = %Q{Cut media coupon aggregator}
22
+ gem.email = "allentsai87@gmail.com"
23
+ gem.authors = ["Allen Tsai"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "aggregator-gem #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.5
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,5 @@
1
+ class CjFetchController < ApplicationController
2
+
3
+
4
+
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module CjFetchHelper
2
+ end
@@ -0,0 +1,18 @@
1
+ class Advertiser < ActiveRecord::Base
2
+ validates_uniqueness_of :advertiser_id
3
+
4
+ has_many :coupons
5
+
6
+ has_many :categories, :through => :advertiser_category_links
7
+ has_many :advertiser_category_links
8
+
9
+ has_many :sites, :through => :advertiser_site_links
10
+ has_many :advertiser_site_links
11
+
12
+ has_many :vendors, :through => :advertiser_vendor_links
13
+ has_many :advertiser_vendor_links
14
+
15
+
16
+
17
+
18
+ end
@@ -0,0 +1,6 @@
1
+ class AdvertiserCategoryLink < ActiveRecord::Base
2
+ validates_uniqueness_of :advertiser_id, :scope => :category_id
3
+
4
+ belongs_to :advertiser
5
+ belongs_to :category
6
+ end
@@ -0,0 +1,5 @@
1
+ class AdvertiserSiteLink < ActiveRecord::Base
2
+ belongs_to :advertiser
3
+ belongs_to :site
4
+
5
+ end
@@ -0,0 +1,4 @@
1
+ class AdvertiserVendorLink < ActiveRecord::Base
2
+ belongs_to :vendor
3
+ belongs_to :advertiser
4
+ end
@@ -0,0 +1,12 @@
1
+ class Category < ActiveRecord::Base
2
+ validates_uniqueness_of :nice_name
3
+
4
+ has_many :sites, :through => :coupons
5
+
6
+ has_many :coupons, :through => :category_coupon_links
7
+ has_many :category_coupon_links
8
+
9
+ has_many :advertisers, :through => :advertiser_category_links
10
+ has_many :advertiser_category_links
11
+
12
+ end
@@ -0,0 +1,6 @@
1
+ class CategoryCouponLink < ActiveRecord::Base
2
+ validates_uniqueness_of :coupon_id, :scope => :category_id
3
+
4
+ belongs_to :coupon
5
+ belongs_to :category
6
+ end
@@ -0,0 +1,148 @@
1
+ class CjCoupon < ActiveRecord::Base
2
+ require 'net/https'
3
+ require 'open-uri'
4
+ require 'cgi'
5
+ require 'nokogiri'
6
+
7
+ has_one :vendor
8
+ has_one :advertiser
9
+ has_one :site
10
+
11
+ def self.update_website_coupons (website_id, type_of_promotion = "coupon", records_per_page = 100)
12
+ #Start off with setting up the request.
13
+ uri = URI("https://linksearch.api.cj.com/v2/link-search")
14
+ params = {"website-id" => website_id,
15
+ "advertiser-ids" => "joined",
16
+ "records-per-page" => records_per_page,
17
+ "promotion-type" => type_of_promotion,
18
+ "page-number" => 1}
19
+ headers = {"authorization" => "00b0786d8cc156bc642d3b3531b858efbf445f0b9fac809ce739506268f388170e14eb47e411c5a7fd2b6eebfc333e09821e6a4748fc068e7ebe545f7a43171029/009d71a493cb3f3e6fc627280b8724da29f4af33e8aef84484cb8edb6e35b0fa97592c51e20eea0f63a36101cbe92f47073a28acbb29a293ed27c5884ef3d5a09d"}
20
+
21
+ #set up the request
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = true if uri.port == 443
24
+ request = build_request(uri, params, headers)
25
+ response = http.request(request)
26
+ firstResponse = CGI.unescapeHTML(response.body)
27
+
28
+ #Massage Data Here
29
+ #first_response = CjFeedMassager.massage_feed(firstResponse)
30
+
31
+ doc = Nokogiri::XML(firstResponse)
32
+
33
+ total_num = doc.xpath("//links/@total-matched")[0].to_s
34
+ total_num = total_num.to_i + 1
35
+
36
+ (1..total_num/records_per_page).each do |n|
37
+ page_number = {"page-number" => n}
38
+ params.merge(page_number)
39
+
40
+ #rebuild the request.
41
+ request = build_request(uri,params,headers)
42
+ response = http.request(request)
43
+ response = CGI.unescapeHTML(response.body)
44
+ doc = Nokogiri::XML(response)
45
+ #parse and save all records per loop
46
+ (doc.xpath("//link")).each do |link|
47
+ advertiser_id = link.xpath("./advertiser-id/text()")
48
+ link_id = link.xpath("./link-id/text()")
49
+
50
+ coupon = CjCoupon.find_by_advertiser_id_and_link_id(advertiser_id.to_s.to_i, link_id.to_s.to_i)
51
+ if(!coupon.nil?)
52
+ coupon.update_with_link(link)
53
+ else
54
+ coupon = CjCoupon.create_from_link(link, website_id)
55
+ end
56
+ coupon.save
57
+ end
58
+ end
59
+ #Hit the url
60
+ #Parse out total-matched
61
+ #set up loop
62
+ end
63
+
64
+ def update_with_link(link)
65
+ self.advertiser_name = link.xpath("./advertiser-name/text()").to_s
66
+ self.category = link.xpath("./category/text()").to_s
67
+ self.language = link.xpath("./language/text()").to_s
68
+ self.click_commission = link.xpath("./click-commission/text()").to_s
69
+ self.lead_commission = link.xpath("./lead-commission/text()").to_s
70
+ self.link_code_html = link.xpath("./link-code-html/*").to_s
71
+ self.link_code_description = link.xpath("./link-code-description/text()").to_s
72
+ self.link_code_destination = link.xpath("./link-code-destination/text()").to_s
73
+ self.link_name = link.xpath("./link-name/text()").to_s
74
+ self.link_type = link.xpath("./link-type/text()").to_s
75
+ self.performance_incentive = link.xpath("./performance-incentive/text()").to_s
76
+ self.promotion_start = link.xpath("./promotion-start-date/text()").to_s
77
+ self.promotion_end = link.xpath("./promotion-end-date/text()").to_s
78
+ self.promotion_type = link.xpath("./promotion-type/text()").to_s
79
+ self.ad_relationship = link.xpath("./relationship-status/text()").to_s
80
+ self.sale_commission = link.xpath("./sale-commission/text()").to_s
81
+ self.seven_day_epc = link.xpath("./seven-day-epc/text()").to_s.to_f
82
+ self.three_month_epc = link.xpath("./three-month-epc/text()").to_s.to_f
83
+ end
84
+
85
+ def self.create_from_link(link, website_id)
86
+ coupon = CjCoupon.new()
87
+ =begin
88
+ puts website_id
89
+ puts link.xpath("./advertiser-id/text()")
90
+ puts link.xpath("./link-id/text()")
91
+ puts link.xpath("./advertiser-name/text()")
92
+ puts link.xpath("./category/text()")[0]
93
+ puts link.xpath("./language/text()")
94
+ puts link.xpath("./click-commission/text()")[0]
95
+ puts link.xpath("./lead-commission/text()")
96
+ puts link.xpath("./link-code-html/text()")
97
+ puts link.xpath("./link-code-description/text()")
98
+ puts link.xpath("./link-code-destination/text()")
99
+ puts link.xpath("./link-name/text()")
100
+ puts link.xpath("./link-type/text()")
101
+ puts link.xpath("./performance-incentive/text()")
102
+ puts link.xpath("./promotion-start-date/text()")
103
+ puts link.xpath("./promotion-end-date/text()")
104
+ puts link.xpath("./promotion-type/text()")
105
+ puts link.xpath("./relationship-status/text()")
106
+ puts link.xpath("./sale-commission/text()")
107
+ puts link.xpath("./sale-commission/text()")
108
+ puts link.xpath("./seven-day-epc/text()").to_s.to_f
109
+ puts link.xpath("./three-month-epc/text()").to_s.to_f
110
+ =end
111
+ coupon.website_id = website_id
112
+ coupon.advertiser_id = link.xpath("./advertiser-id/text()").to_s.to_i
113
+ coupon.link_id = link.xpath("./link-id/text()").to_s.to_i
114
+ coupon.advertiser_name = link.xpath("./advertiser-name/text()").to_s
115
+ coupon.category = link.xpath("./category/text()").to_s
116
+ coupon.language = link.xpath("./language/text()").to_s
117
+ coupon.click_commission = link.xpath("./click-commission/text()").to_s
118
+ coupon.lead_commission = link.xpath("./lead-commission/text()").to_s
119
+ coupon.link_code_html = link.xpath("./link-code-html/*").to_s
120
+ coupon.link_code_description = link.xpath("./link-code-description/text()").to_s
121
+ coupon.link_code_destination = link.xpath("./link-code-destination/text()").to_s
122
+ coupon.link_name = link.xpath("./link-name/text()").to_s
123
+ coupon.link_type = link.xpath("./link-type/text()").to_s
124
+ coupon.performance_incentive = link.xpath("./performance-incentive/text()").to_s
125
+ coupon.promotion_start = link.xpath("./promotion-start-date/text()").to_s
126
+ coupon.promotion_end = link.xpath("./promotion-end-date/text()").to_s
127
+ coupon.promotion_type = link.xpath("./promotion-type/text()").to_s
128
+ coupon.ad_relationship = link.xpath("./relationship-status/text()").to_s
129
+ coupon.sale_commission = link.xpath("./sale-commission/text()").to_s
130
+ coupon.seven_day_epc = link.xpath("./seven-day-epc/text()").to_s.to_f
131
+ coupon.three_month_epc = link.xpath("./three-month-epc/text()").to_s.to_f
132
+ return coupon
133
+ end
134
+
135
+ private
136
+
137
+ def self.build_request(uri, params, headers)
138
+
139
+ request = Net::HTTP::Get.new(uri.path)
140
+
141
+ #load the params in
142
+ request.set_form_data(params)
143
+
144
+ #load the headers in
145
+ return Net::HTTP::Get.new(uri.path+'?' + request.body, headers)
146
+ end
147
+
148
+ end
@@ -0,0 +1,14 @@
1
+ class Coupon < ActiveRecord::Base
2
+ validates_uniqueness_of :item_id
3
+
4
+ belongs_to :site
5
+ belongs_to :vendor
6
+ belongs_to :advertiser
7
+
8
+ has_many :products, :through => :coupon_product_links
9
+ has_many :coupon_product_links
10
+
11
+ has_many :categories, :through => :category_coupon_links
12
+ has_many :category_coupon_links
13
+
14
+ end
@@ -0,0 +1,4 @@
1
+ class CouponProductLink < ActiveRecord::Base
2
+ belongs_to :coupon
3
+ belongs_to :product
4
+ end
@@ -0,0 +1,6 @@
1
+ class Product < ActiveRecord::Base
2
+ has_many :sites, :through => :coupons
3
+
4
+ has_many :coupons, :through => :coupon_product_links
5
+ has_many :coupon_product_links
6
+ end
@@ -0,0 +1,11 @@
1
+ class Site < ActiveRecord::Base
2
+ has_many :coupons
3
+ has_many :products, :through => :coupons
4
+ has_many :categories, :through => :coupons
5
+
6
+ has_many :vendors, :through => :site_vendor_links
7
+ has_many :site_vendor_links
8
+
9
+ has_many :advertisers, :through => :advertiser_site_links
10
+ has_many :advertiser_site_links
11
+ end
@@ -0,0 +1,5 @@
1
+ class SiteVendorLink < ActiveRecord::Base
2
+ belongs_to :site
3
+ belongs_to :vendor
4
+
5
+ end
@@ -0,0 +1,2 @@
1
+ class SitesVendors < ActiveRecord::Base
2
+ end
@@ -0,0 +1,9 @@
1
+ class Vendor < ActiveRecord::Base
2
+ has_many :coupons
3
+
4
+ has_many :sites, :through => :site_vendor_links
5
+ has_many :site_vendor_links
6
+
7
+ has_many :advertisers, :through => :advertiser_vendor_links
8
+ has_many :advertiser_vendor_links
9
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Aggregator</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,15 @@
1
+ class CreateSites < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :sites do |t|
4
+ t.string :name
5
+ t.string :url
6
+ t.string :nice_name
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :sites
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateVendors < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :vendors do |t|
4
+ t.string :name
5
+ t.string :nice_name
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :vendors
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ class CreateAdvertisers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :advertisers do |t|
4
+ t.string :name
5
+ t.integer :advertiser_id
6
+ t.string :account_status
7
+ t.decimal :seven_day_epc, :precision => 30, :scale => 4
8
+ t.decimal :three_month_epc, :precision => 30, :scale => 4
9
+ t.string :language
10
+ t.string :program_url
11
+ t.string :relationship_status
12
+ t.integer :network_rank
13
+ t.boolean :performance_incentives
14
+ t.string :nice_name
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+
20
+ def self.down
21
+ drop_table :advertisers
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ class CreateProducts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :products do |t|
4
+ t.string :name
5
+ t.float :msrp
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :products
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ class CreateCategories < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :categories do |t|
4
+ t.string :name
5
+ t.string :nice_name
6
+ t.integer :parent_id
7
+
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :categories
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ class CreateCoupons < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :coupons do |t|
4
+ t.integer :item_id
5
+ t.string :code
6
+ t.string :description
7
+ t.string :link
8
+ t.string :link_type
9
+ t.integer :site_id
10
+ t.integer :vendor_id
11
+ t.integer :advertiser_id
12
+
13
+
14
+ t.timestamps
15
+ end
16
+ end
17
+
18
+ def self.down
19
+ drop_table :coupons
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ class CreateSiteVendorLinks < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :site_vendor_links do |t|
4
+ t.integer :site_id
5
+ t.integer :vendor_id
6
+ t.integer :relationship_id
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :site_vendor_links
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateCouponProductLinks < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :coupon_product_links do |t|
4
+ t.integer :coupon_id
5
+ t.integer :product_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :coupon_product_links
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class CreateCategoryCouponLinks < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :category_coupon_links do |t|
4
+ t.integer :category_id
5
+ t.integer :coupon_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :coupon_category_links
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class CreateAdvertiserSiteLinks < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :advertiser_site_links do |t|
4
+ t.integer :advertiser_id
5
+ t.integer :site_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :site_advertiser_links
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class CreateAdvertiserVendorLinks < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :advertiser_vendor_links do |t|
4
+ t.integer :advertiser_id
5
+ t.integer :vendor_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :vendor_advertiser_links
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class AddSitesInfo < ActiveRecord::Migration
2
+ def self.up
3
+ Site.create(:name => "All", :url => "", :nice_name => "all")
4
+ Site.create(:name => "Amplifed Media", :url => "http://www.amplifiedmedia.com", :nice_name => "amplified-media")
5
+ Vendor.create(:name => 'Commission Junction', :nice_name => 'commission-junction')
6
+ SiteVendorLink.create(:site_id => 2, :vendor_id => 1, :relationship_id => 5374071)
7
+ end
8
+
9
+ def self.down
10
+ Site.find_by_site_name("All").destroy
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateAdvertiserCategoryLinks < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :advertiser_category_links do |t|
4
+ t.integer :advertiser_id
5
+ t.integer :category_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :advertiser_category_links
13
+ end
14
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ desc "copy railscasts 149. copies migrations over"
2
+ task :sync do
3
+ system "rsync -ruv db/migrate db"
4
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'coupon_aggregator'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCouponAggregator < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aggregator-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Allen Tsai
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &26228320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *26228320
25
+ - !ruby/object:Gem::Dependency
26
+ name: mysql2
27
+ requirement: &26227700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '0.3'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *26227700
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ requirement: &26227060 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *26227060
47
+ - !ruby/object:Gem::Dependency
48
+ name: shoulda
49
+ requirement: &26226360 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *26226360
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &26225640 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *26225640
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &26225020 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.6.4
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *26225020
80
+ - !ruby/object:Gem::Dependency
81
+ name: rcov
82
+ requirement: &26224380 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *26224380
91
+ description: Cut media coupon aggregator
92
+ email: allentsai87@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files:
96
+ - LICENSE.txt
97
+ - README
98
+ - README.rdoc
99
+ files:
100
+ - .document
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - LICENSE.txt
104
+ - README
105
+ - README.rdoc
106
+ - Rakefile
107
+ - VERSION
108
+ - app/controllers/application_controller.rb
109
+ - app/controllers/cj_fetch_controller.rb
110
+ - app/helpers/application_helper.rb
111
+ - app/helpers/cj_fetch_helper.rb
112
+ - app/models/advertiser.rb
113
+ - app/models/advertiser_category_link.rb
114
+ - app/models/advertiser_site_link.rb
115
+ - app/models/advertiser_vendor_link.rb
116
+ - app/models/category.rb
117
+ - app/models/category_coupon_link.rb
118
+ - app/models/cj_coupon.rb
119
+ - app/models/coupon.rb
120
+ - app/models/coupon_product_link.rb
121
+ - app/models/product.rb
122
+ - app/models/site.rb
123
+ - app/models/site_vendor_link.rb
124
+ - app/models/sites_vendors.rb
125
+ - app/models/vendor.rb
126
+ - app/views/layouts/application.html.erb
127
+ - db/migrate/20111004055535_create_sites.rb
128
+ - db/migrate/20111004055623_create_vendors.rb
129
+ - db/migrate/20111004055648_create_advertisers.rb
130
+ - db/migrate/20111004055950_create_products.rb
131
+ - db/migrate/20111004060028_create_categories.rb
132
+ - db/migrate/20111005025903_create_coupons.rb
133
+ - db/migrate/20111010054838_create_site_vendor_links.rb
134
+ - db/migrate/20111012024234_create_coupon_product_links.rb
135
+ - db/migrate/20111012024246_create_category_coupon_links.rb
136
+ - db/migrate/20111012024455_create_advertiser_site_links.rb
137
+ - db/migrate/20111012025453_create_advertiser_vendor_links.rb
138
+ - db/migrate/20111012061448_add_sites_info.rb
139
+ - db/migrate/20111012190927_create_advertiser_category_links.rb
140
+ - lib/coupon_aggregator.rb
141
+ - tasks/coupon_aggregator_tasks.rake
142
+ - test/helper.rb
143
+ - test/test_coupon_aggregator.rb
144
+ homepage: https://github.com/allentsai/aggregator-gem
145
+ licenses:
146
+ - MIT
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ segments:
158
+ - 0
159
+ hash: -3690616005165935710
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 1.8.5
169
+ signing_key:
170
+ specification_version: 3
171
+ summary: Aggregates Coupons
172
+ test_files: []