epom_rails 1.0.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/epom_rails/acts_as.rb +41 -14
  3. data/lib/epom_rails/acts_as_advertiser.rb +24 -0
  4. data/lib/epom_rails/acts_as_analytic.rb +33 -0
  5. data/lib/epom_rails/acts_as_campaign.rb +20 -1
  6. data/lib/epom_rails/acts_as_zone.rb +19 -0
  7. data/lib/epom_rails/config.rb +8 -6
  8. data/lib/epom_rails/version.rb +1 -1
  9. data/lib/epom_rails.rb +5 -3
  10. data/lib/generators/epom_rails/config/templates/epom_rails.rb +7 -4
  11. data/test/dummy/app/assets/javascripts/analytics.js +2 -0
  12. data/test/dummy/app/assets/stylesheets/analytics.css +4 -0
  13. data/test/dummy/app/controllers/analytics_controller.rb +58 -0
  14. data/test/dummy/app/controllers/zones_controller.rb +1 -1
  15. data/test/dummy/app/helpers/analytics_helper.rb +2 -0
  16. data/test/dummy/app/models/advertiser.rb +2 -1
  17. data/test/dummy/app/models/analytic.rb +3 -0
  18. data/test/dummy/app/models/banner.rb +2 -0
  19. data/test/dummy/app/models/campaign.rb +3 -0
  20. data/test/dummy/app/models/placement.rb +2 -0
  21. data/test/dummy/app/models/publisher.rb +1 -0
  22. data/test/dummy/app/models/zone.rb +3 -0
  23. data/test/dummy/app/views/analytics/_form.html.erb +133 -0
  24. data/test/dummy/app/views/analytics/edit.html.erb +6 -0
  25. data/test/dummy/app/views/analytics/index.html.erb +83 -0
  26. data/test/dummy/app/views/analytics/new.html.erb +5 -0
  27. data/test/dummy/app/views/analytics/show.html.erb +149 -0
  28. data/test/dummy/app/views/zones/_form.html.erb +2 -2
  29. data/test/dummy/app/views/zones/index.html.erb +2 -2
  30. data/test/dummy/app/views/zones/show.html.erb +2 -2
  31. data/test/dummy/config/routes.rb +2 -1
  32. data/test/dummy/db/migrate/{20150622160449_create_zones.rb → 20150803195716_create_zones.rb} +1 -1
  33. data/test/dummy/db/migrate/20150821041145_create_analytics.rb +37 -0
  34. data/test/dummy/db/schema.rb +38 -4
  35. data/test/dummy/test/controllers/analytics_controller_test.rb +49 -0
  36. data/test/dummy/test/controllers/banners_controller_test.rb +3 -1
  37. data/test/dummy/test/controllers/campaigns_controller_test.rb +4 -2
  38. data/test/dummy/test/controllers/placements_controller_test.rb +5 -3
  39. data/test/dummy/test/controllers/publishers_controller_test.rb +2 -2
  40. data/test/dummy/test/controllers/zones_controller_test.rb +5 -3
  41. data/test/dummy/test/fixtures/advertisers.yml +1 -0
  42. data/test/dummy/test/fixtures/analytics.yml +63 -0
  43. data/test/dummy/test/fixtures/banners.yml +16 -1
  44. data/test/dummy/test/fixtures/campaigns.yml +3 -2
  45. data/test/dummy/test/fixtures/placements.yml +4 -3
  46. data/test/dummy/test/fixtures/publishers.yml +2 -1
  47. data/test/dummy/test/fixtures/zones.yml +3 -2
  48. data/test/dummy/test/models/analytic_test.rb +7 -0
  49. data/test/epom_rails/acts_as_advertiser_test.rb +54 -1
  50. data/test/epom_rails/acts_as_analytic_test.rb +9 -0
  51. data/test/epom_rails/acts_as_banner_test.rb +9 -6
  52. data/test/epom_rails/acts_as_campaign_test.rb +24 -5
  53. data/test/epom_rails/acts_as_placement_test.rb +6 -3
  54. data/test/epom_rails/acts_as_site_test.rb +8 -5
  55. data/test/epom_rails/acts_as_zone_test.rb +16 -3
  56. data/test/test_helper.rb +8 -5
  57. metadata +42 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4962f4fd1ba3541d9bef5d8636abd40adf73b026
4
- data.tar.gz: f3357980470748efd86a47a01433253fe263cc86
3
+ metadata.gz: c8477a4424a385f16a87257167587ec38126d35e
4
+ data.tar.gz: 4832ff15f4f780afd3cf64582ee06ec457c89c92
5
5
  SHA512:
6
- metadata.gz: c7ad76795810c969c0bfd976c0e8b4a1a6742f08f400f9ad6e29a97865322ed7b4454e3a34d3bda7125df6ef899172a0488cdf4d32a071002023dad3f2754de1
7
- data.tar.gz: 7034623022877440f796d849336c92d1caf17d780e298d669000525dbe63c344532bdbe9f91eebb7c602534f49fe501d5e0eb593765705c479dffd8c3cd60699
6
+ metadata.gz: c369bfaebe40a96f527f6753875c4e960a8621a5e32643b46b2c6ba0094f0c3a38a12b86e12e0017ae7cb490e4b0ee595291e90e920503a707a666cd1cfaa988
7
+ data.tar.gz: a7c14a9c460452566fb512649a48a36b31343010572dee2da6b8f10b497cac4c590e1e274fdf74423cdcee8315e9afcfaa25fb1fcdccec1f57fa60e70e79b8e4
@@ -1,5 +1,30 @@
1
1
  class ActiveRecord::Base
2
2
 
3
+ def method_missing(method_name, *args)
4
+ fields = self.class.get_config[:fields]
5
+
6
+ # shortcut for epom fields, instead of self.send(fields.key(epom_field))
7
+ # use self.send(epom_field)
8
+ if fields.values.include?(method_name.to_s)
9
+ real_method = fields.key(method_name.to_s)
10
+ return self.send(real_method)
11
+ # when self.send('advertiser.epom_id')
12
+ elsif method_name.to_s.include?('.')
13
+ methods = method_name.to_s.split('.')
14
+ target = self
15
+ methods.each do |method|
16
+ if method == methods.last
17
+ target = target.send(method, *args)
18
+ else
19
+ target = target.send(method)
20
+ end
21
+ end
22
+ return target
23
+ else
24
+ super
25
+ end
26
+ end
27
+
3
28
  private
4
29
 
5
30
  def self.acts_as(klass, params)
@@ -10,29 +35,30 @@ class ActiveRecord::Base
10
35
  define_before_destroy(klass)
11
36
  end
12
37
 
13
- def self.get_klass_name(klass)
14
- klass.name.include?('::') ? klass.name.split('::').last : klass.name
38
+ def self.get_epom_class_name
39
+ # for Epom::Site returns Site
40
+ epom_class.name.include?('::') ? epom_class.name.split('::').last : epom_class.name
15
41
  end
16
42
 
17
- def self.get_config(klass)
18
- klass_name = get_klass_name(klass)
43
+ def self.get_config
44
+ klass_name = get_epom_class_name
19
45
  EpomRails.config.send(klass_name.downcase)
20
46
  end
21
47
 
22
48
  def self.override_config(klass, params)
23
- fields ||= {}
24
- config = get_config(klass)
49
+ config = get_config
25
50
  config[:fields] = params[:fields] if params[:fields]
26
51
  config[:has_many] = params[:has_many] if params[:has_many]
27
52
  config[:belongs_to] = params[:belongs_to] if params[:belongs_to]
28
53
  end
29
54
 
30
55
  def self.define_before_save(klass)
31
- unless EpomRails.config.offline
32
- klass_name = get_klass_name(klass)
33
- fields = get_config(klass)[:fields]
56
+ klass_name = get_epom_class_name
57
+ fields = get_config[:fields]
34
58
 
35
- before_save do
59
+ before_save do
60
+ puts "before_save for #{self.inspect}"
61
+ unless EpomRails.config.offline
36
62
  method = if self.send fields.key('id') then "update_#{klass_name.downcase}" else "create_#{klass_name.downcase}" end
37
63
 
38
64
  url_params = {}
@@ -67,10 +93,11 @@ class ActiveRecord::Base
67
93
  end
68
94
 
69
95
  def self.define_before_destroy(klass)
70
- unless EpomRails.config.offline
71
- klass_name = get_klass_name(klass)
72
- fields = get_config(klass)[:fields]
73
- before_destroy do
96
+ klass_name = get_epom_class_name
97
+ fields = get_config[:fields]
98
+ before_destroy do
99
+ puts "before_destroy for #{self.inspect}"
100
+ unless EpomRails.config.offline
74
101
  if self.send fields.key('id')
75
102
  epom_response = klass.send "delete_#{klass_name.downcase}", {"#{klass_name.downcase}Id" => self.send(fields.key('id'))}, {}
76
103
  epom_response['success'] if epom_response
@@ -3,6 +3,30 @@ class ActiveRecord::Base
3
3
  def self.acts_as_advertiser(params = {})
4
4
  EpomRails.config.advertiser[:model] = self
5
5
  acts_as(Epom::Advertiser, params)
6
+
7
+ define_before_add_and_before_remove_for_campaigns
8
+ end
9
+
10
+ def self.define_before_add_and_before_remove_for_campaigns
11
+ campaigns_association = EpomRails.config.advertiser[:has_many].find{|a| a[:epom_element]=="Campaign"}
12
+
13
+ if campaigns_association
14
+ before_add_for_campaigns << proc do |callback, advertiser, campaign|
15
+ puts callback
16
+ if campaign.advertiser_id and advertiser.id != campaign.advertiser_id
17
+ # remove in Epom this campaign from his older advertiser
18
+ Advertiser.find(campaign.advertiser_id).campaigns.delete(campaign)
19
+ end
20
+ end
21
+ before_remove_for_campaigns << proc do |callback, advertiser, campaign|
22
+ puts callback
23
+ fields = EpomRails.config.campaign[:fields]
24
+ # delete this campaign in Epom
25
+ Campaign.delete_campaign({campaignId: campaign.send(fields.key('id'))})
26
+ # set nil epom_id field for this campaign
27
+ campaign.send "#{fields.key('id')}=", nil
28
+ end
29
+ end
6
30
  end
7
31
 
8
32
  end
@@ -0,0 +1,33 @@
1
+ class ActiveRecord::Base
2
+ def self.acts_as_analytic(params = {})
3
+ EpomRails.config.analytic[:model] = self
4
+
5
+ extend EpomRails
6
+ override_config(Epom::Analytic, params)
7
+
8
+ define_analytic_from_epom
9
+ end
10
+
11
+ private
12
+ def self.define_analytic_from_epom
13
+ self.class_eval do
14
+ def self.analytic_from_epom(params)
15
+ default = {
16
+ :format => 'JSON',
17
+ :displayIds => true,
18
+ :groupBy => 'ADVERTISER,CAMPAIGN,BANNER,SITE,ZONE,PLACEMENT,CHANNEL,COUNTRY',
19
+ :groupRange => 'DAY',
20
+ }
21
+ analytics = JSON.parse(self.analytics(default.merge(params)))
22
+ # analytics = [{"Date"=>"01/08/2015", "Advertiser"=>"Praneet Shrivastava", "Advertiser ID"=>"911", "Campaign"=>"Camoaign by Praneet", "Campaign ID"=>"1409", "Banner"=>"Banner1", "Banner ID"=>"2364", "Site"=>"CN Beauty", "Site ID"=>"687", "Zone"=>"Zone Malaysia", "Zone ID"=>"762", "Placement"=>"CN Beauty site", "Placement ID"=>"1308", "Channel"=>"", "Country"=>"Malaysia", "Impressions"=>"642", "Clicks"=>"0", "CTR"=>"0.0000%", "Conversions"=>"0", "I2C"=>"0.0000%", "CCR"=>"0.0000%", "Net"=>"0.000", "Gross"=>"0.000", "Profit"=>"0.000", "eCPM Net"=>"0.000", "eCPM Gross"=>"0.000", "eCPM Profit"=>"0.000", "Status"=>"Preliminary confirmed"}, {"Date"=>"01/08/2015", "Advertiser"=>"Praneet Shrivastava", "Advertiser ID"=>"911", "Campaign"=>"Camoaign by Praneet", "Campaign ID"=>"1409", "Banner"=>"Banner1", "Banner ID"=>"2364", "Site"=>"CN Beauty", "Site ID"=>"687", "Zone"=>"Zone Malaysia", "Zone ID"=>"762", "Placement"=>"CN Beauty site", "Placement ID"=>"1308", "Channel"=>"", "Country"=>"Indonesia", "Impressions"=>"33", "Clicks"=>"0", "CTR"=>"0.0000%", "Conversions"=>"0", "I2C"=>"0.0000%", "CCR"=>"0.0000%", "Net"=>"0.000", "Gross"=>"0.000", "Profit"=>"0.000", "eCPM Net"=>"0.000", "eCPM Gross"=>"0.000", "eCPM Profit"=>"0.000", "Status"=>"Preliminary confirmed"}, {"Date"=>"01/08/2015", "Advertiser"=>"Praneet Shrivastava", "Advertiser ID"=>"911", "Campaign"=>"Camoaign by Praneet", "Campaign ID"=>"1409", "Banner"=>"Banner1", "Banner ID"=>"2364", "Site"=>"CN Beauty", "Site ID"=>"687", "Zone"=>"Zone Malaysia", "Zone ID"=>"762", "Placement"=>"CN Beauty site", "Placement ID"=>"1308", "Channel"=>"", "Country"=>"Brunei Darussalam", "Impressions"=>"31", "Clicks"=>"0", "CTR"=>"0.0000%", "Conversions"=>"0", "I2C"=>"0.0000%", "CCR"=>"0.0000%", "Net"=>"0.000", "Gross"=>"0.000", "Profit"=>"0.000", "eCPM Net"=>"0.000", "eCPM Gross"=>"0.000", "eCPM Profit"=>"0.000", "Status"=>"Preliminary confirmed"}, {"Date"=>"01/08/2015", "Advertiser"=>"Praneet Shrivastava", "Advertiser ID"=>"911", "Campaign"=>"Camoaign by Praneet", "Campaign ID"=>"1409", "Banner"=>"Banner1", "Banner ID"=>"2364", "Site"=>"CN Beauty", "Site ID"=>"687", "Zone"=>"Zone Malaysia", "Zone ID"=>"762", "Placement"=>"CN Beauty site", "Placement ID"=>"1308", "Channel"=>"", "Country"=>"Singapore", "Impressions"=>"31", "Clicks"=>"0", "CTR"=>"0.0000%", "Conversions"=>"0", "I2C"=>"0.0000%", "CCR"=>"0.0000%", "Net"=>"0.000", "Gross"=>"0.000", "Profit"=>"0.000", "eCPM Net"=>"0.000", "eCPM Gross"=>"0.000", "eCPM Profit"=>"0.000", "Status"=>"Preliminary confirmed"}, {"Date"=>"01/08/2015", "Advertiser"=>"NetUy", "Advertiser ID"=>"1253", "Campaign"=>"Netuy Envios de Titulares Matinales Campaña 2015", "Campaign ID"=>"1661", "Banner"=>"NetUy envíos", "Banner ID"=>"2598", "Site"=>"El Observador", "Site ID"=>"1059", "Zone"=>"Newsletters", "Zone ID"=>"1211", "Placement"=>"Titulares_Matinal_Cabezal", "Placement ID"=>"1704", "Channel"=>"", "Country"=>"Uruguay", "Impressions"=>"8", "Clicks"=>"0", "CTR"=>"0.0000%", "Conversions"=>"0", "I2C"=>"0.0000%", "CCR"=>"0.0000%", "Net"=>"0.000", "Gross"=>"0.000", "Profit"=>"0.000", "eCPM Net"=>"0.000", "eCPM Gross"=>"0.000", "eCPM Profit"=>"0.000", "Status"=>"Preliminary confirmed"}]
23
+ fields = get_config[:fields]
24
+ analytics.map do |analytic|
25
+ data = {}
26
+ fields.map {|key, value| data[key] = analytic[value]}
27
+ data[:date] = Date.parse(data[:date]) if data[:date].is_a?(String)
28
+ Analytic.new(data)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -3,6 +3,25 @@ class ActiveRecord::Base
3
3
  def self.acts_as_campaign(params = {})
4
4
  EpomRails.config.campaign[:model] = self
5
5
  acts_as(Epom::Campaign, params)
6
+
7
+ override_belongs_to_advertiser
8
+ end
9
+
10
+ def self.override_belongs_to_advertiser
11
+ advertiser_association = EpomRails.config.campaign[:belongs_to].find{|a| a[:epom_element]=="Advertiser"}
12
+
13
+ if advertiser_association
14
+ # overriding belongs_to: advertiser
15
+ define_method advertiser_association[:name] do
16
+ fields = EpomRails.config.campaign[:fields]
17
+ object = super()
18
+
19
+ if object.respond_to?(fields.key('id')) and object.send(fields.key('id'))
20
+ # here, retrieve this advertiser from Epom
21
+ end
22
+ object
23
+ end
24
+ end
6
25
  end
7
26
 
8
- end
27
+ end
@@ -3,6 +3,25 @@ class ActiveRecord::Base
3
3
  def self.acts_as_zone(params = {})
4
4
  EpomRails.config.zone[:model] = self
5
5
  acts_as(Epom::Zone, params)
6
+
7
+ override_belongs_to_zone
8
+ end
9
+
10
+ def self.override_belongs_to_zone
11
+ site_association = EpomRails.config.zone[:belongs_to].find{|a| a[:epom_element]=="Site"}
12
+
13
+ if site_association
14
+ # overriding belongs_to: site
15
+ define_method site_association[:name] do
16
+ fields = EpomRails.config.zone[:fields]
17
+ object = super()
18
+
19
+ if object.respond_to?(fields.key('id')) and object.send(fields.key('id'))
20
+ # here, retrieve this site from Epom
21
+ end
22
+ object
23
+ end
24
+ end
6
25
  end
7
26
 
8
27
  end
@@ -17,7 +17,7 @@ module EpomRails
17
17
  # need a Class for 3.0
18
18
  class Configuration #:nodoc:
19
19
  include ActiveSupport::Configurable
20
- config_accessor :offline, :advertiser, :campaign, :banner, :site, :zone, :placement
20
+ config_accessor :offline, :advertiser, :campaign, :banner, :site, :zone, :placement, :analytic
21
21
 
22
22
  def param_name
23
23
  config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
@@ -29,7 +29,6 @@ module EpomRails
29
29
  class_eval writer, __FILE__, line
30
30
  end
31
31
 
32
- # this is ugly. why can't we pass the default value to config_accessor...?
33
32
  EpomRails.configure do |config|
34
33
  config.offline = false
35
34
 
@@ -38,12 +37,12 @@ module EpomRails
38
37
  config.advertiser[:has_many] = [{:name => 'campaigns', :epom_element => 'Campaign', :model => 'Campaign'}]
39
38
 
40
39
  config.campaign = {}
41
- config.campaign[:fields] = {epom_id: 'id', name: 'name', description: 'description', advertiser_id: 'advertiserId', weight: 'weight'}
40
+ config.campaign[:fields] = {epom_id: 'id', name: 'name', description: 'description', weight: 'weight', 'advertiser.epom_id' => 'advertiserId'}
42
41
  config.campaign[:has_many] = [{:name => 'banners', :epom_element => 'Banner', :model => 'Banner'}]
43
42
  config.campaign[:belongs_to] = [{:name => 'advertiser', :epom_element => 'Advertiser', :model => 'Advertiser'}]
44
43
 
45
44
  config.banner = {}
46
- config.banner[:fields] = {epom_id: 'id', placement_type: 'placementType', campaign_id: 'campaignId', weight: 'weight', image_banner_link: 'imageBannerLink', url: 'url', name: 'name', banner_type: 'bannerType', ad_unit_id: 'adUnitId', ad_unit_width: 'adUnitWidth', ad_unit_height: 'adUnitHeight'}
45
+ config.banner[:fields] = {epom_id: 'id', placement_type: 'placementType', 'campaign.epom_id' => 'campaignId', weight: 'weight', image_banner_link: 'imageBannerLink', url: 'url', name: 'name', banner_type: 'bannerType', ad_unit_id: 'adUnitId', ad_unit_width: 'adUnitWidth', ad_unit_height: 'adUnitHeight'}
47
46
  config.banner[:has_many] = [{:name => 'placements', :epom_element => 'Placement', :model => 'Placement'}]
48
47
  config.banner[:belongs_to] = [{:name => 'campaign', :epom_element => 'Campaign', :model => 'Campaign'}]
49
48
 
@@ -52,13 +51,16 @@ module EpomRails
52
51
  config.site[:has_many] = [{:name => 'zones', :epom_element => 'Zone', :model => 'Zone'}]
53
52
 
54
53
  config.zone = {}
55
- config.zone[:fields] = {epom_id: 'id', name: 'name', description: 'description', site_id: 'siteId'}
54
+ config.zone[:fields] = {epom_id: 'id', name: 'name', description: 'description', 'site.epom_id' => 'siteId'}
56
55
  config.zone[:has_many] = [{:name => 'placements', :epom_element => 'Placement', :model => 'Placement'}]
57
56
  config.zone[:belongs_to] = [{:name => 'site', :epom_element => 'Site', :model => 'Site'}]
58
57
 
59
58
  config.placement = {}
60
- config.placement[:fields] = {epom_id: 'id', zone_id: 'zoneId', placement_type: 'type', name: 'name', ad_unit_id: 'adUnitId', size_height: 'size.height', size_width: 'size.width'}
59
+ config.placement[:fields] = {epom_id: 'id', 'zone.epom_id' => 'zoneId', placement_type: 'type', name: 'name', ad_unit_id: 'adUnitId', size_height: 'size.height', size_width: 'size.width'}
61
60
  config.placement[:has_many] = [{:name => 'banners', :epom_element => 'Banner', :model => 'Banner'}]
62
61
  config.placement[:belongs_to] = [{:name => 'zone', :epom_element => 'Zone', :model => 'Zone'}]
62
+
63
+ config.analytic = {}
64
+ config.analytic[:fields] = {date: "Date", hour: "Hour", advertiser: "Advertiser", advertiser_id: "Advertiser ID", campaign: "Campaign", campaign_id: "Campaign ID", banner: "Banner", banner_id: "Banner ID", site: "Site", site_id: "Site ID", zone: "Zone", zone_id: "Zone ID", placement: "Placement", placement_id: "Placement ID", channel: "Channel", country: "Country", impressions: "Impressions", clicks: "Clicks", ctr: "CTR", conversions: "Conversions", i2c: "I2C", ccr: "CCR", net: "Net", gross: "Gross", profit: "Profit", ecpm_net: "eCPM Net", ecpm_gross: "eCPM Gross", ecpm_profit: "eCPM Profit", status: "Status"}
63
65
  end
64
66
  end
@@ -1,3 +1,3 @@
1
1
  module EpomRails
2
- VERSION = "1.0.0"
2
+ VERSION = "1.3.2"
3
3
  end
data/lib/epom_rails.rb CHANGED
@@ -6,20 +6,21 @@ require 'epom_rails/acts_as_banner'
6
6
  require 'epom_rails/acts_as_site'
7
7
  require 'epom_rails/acts_as_zone'
8
8
  require 'epom_rails/acts_as_placement'
9
+ require 'epom_rails/acts_as_analytic'
9
10
 
10
11
  require 'epom_rails/config'
11
12
 
12
13
  module EpomRails
13
14
  def method_missing(method_name, *args)
14
15
  if not EpomRails.config.offline and epom_class.respond_to?(method_name)
15
- epom_class.send(method_name, args[0], args[1])
16
+ # this permits to use:
17
+ # Campaign.get_campaign({:campaignId => campaign.send(epom_field('id'))}, {})
18
+ epom_class.send(method_name, *args)
16
19
  else
17
20
  super
18
21
  end
19
22
  end
20
23
 
21
- private
22
-
23
24
  def epom_class
24
25
  return Epom::Advertiser if EpomRails.config.advertiser[:model] == self
25
26
  return Epom::Campaign if EpomRails.config.campaign[:model] == self
@@ -27,5 +28,6 @@ module EpomRails
27
28
  return Epom::Site if EpomRails.config.site[:model] == self
28
29
  return Epom::Zone if EpomRails.config.zone[:model] == self
29
30
  return Epom::Placement if EpomRails.config.placement[:model] == self
31
+ return Epom::Analytic if EpomRails.config.analytic[:model] == self
30
32
  end
31
33
  end
@@ -6,12 +6,12 @@ EpomRails.configure do |config|
6
6
  config.advertiser[:has_many] = [{:name => 'campaigns', :epom_element => 'Campaign', :model => 'Campaign'}]
7
7
 
8
8
  config.campaign = {}
9
- config.campaign[:fields] = {epom_id: 'id', name: 'name', description: 'description', advertiser_id: 'advertiserId', weight: 'weight'}
9
+ config.campaign[:fields] = {epom_id: 'id', name: 'name', description: 'description', weight: 'weight', 'advertiser.epom_id' => 'advertiserId'}
10
10
  config.campaign[:has_many] = [{:name => 'banners', :epom_element => 'Banner', :model => 'Banner'}]
11
11
  config.campaign[:belongs_to] = [{:name => 'advertiser', :epom_element => 'Advertiser', :model => 'Advertiser'}]
12
12
 
13
13
  config.banner = {}
14
- config.banner[:fields] = {epom_id: 'id', placement_type: 'placementType', campaign_id: 'campaignId', weight: 'weight', image_banner_link: 'imageBannerLink', url: 'url', name: 'name', banner_type: 'bannerType', ad_unit_id: 'adUnitId', ad_unit_width: 'adUnitWidth', ad_unit_height: 'adUnitHeight'}
14
+ config.banner[:fields] = {epom_id: 'id', placement_type: 'placementType', 'campaign.epom_id' => 'campaignId', weight: 'weight', image_banner_link: 'imageBannerLink', url: 'url', name: 'name', banner_type: 'bannerType', ad_unit_id: 'adUnitId', ad_unit_width: 'adUnitWidth', ad_unit_height: 'adUnitHeight'}
15
15
  config.banner[:has_many] = [{:name => 'placements', :epom_element => 'Placement', :model => 'Placement'}]
16
16
  config.banner[:belongs_to] = [{:name => 'campaign', :epom_element => 'Campaign', :model => 'Campaign'}]
17
17
 
@@ -20,12 +20,15 @@ EpomRails.configure do |config|
20
20
  config.site[:has_many] = [{:name => 'zones', :epom_element => 'Zone', :model => 'Zone'}]
21
21
 
22
22
  config.zone = {}
23
- config.zone[:fields] = {epom_id: 'id', name: 'name', description: 'description', site_id: 'siteId'}
23
+ config.zone[:fields] = {epom_id: 'id', name: 'name', description: 'description', 'site.epom_id' => 'siteId'}
24
24
  config.zone[:has_many] = [{:name => 'placements', :epom_element => 'Placement', :model => 'Placement'}]
25
25
  config.zone[:belongs_to] = [{:name => 'site', :epom_element => 'Site', :model => 'Site'}]
26
26
 
27
27
  config.placement = {}
28
- config.placement[:fields] = {epom_id: 'id', zone_id: 'zoneId', placement_type: 'type', name: 'name', ad_unit_id: 'adUnitId', size_height: 'size.height', size_width: 'size.width'}
28
+ config.placement[:fields] = {epom_id: 'id', 'zone.epom_id' => 'zoneId', placement_type: 'type', name: 'name', ad_unit_id: 'adUnitId', size_height: 'size.height', size_width: 'size.width'}
29
29
  config.placement[:has_many] = [{:name => 'banners', :epom_element => 'Banner', :model => 'Banner'}]
30
30
  config.placement[:belongs_to] = [{:name => 'zone', :epom_element => 'Zone', :model => 'Zone'}]
31
+
32
+ config.analytic = {}
33
+ config.analytic[:fields] = {date: "Date", hour: "Hour", advertiser: "Advertiser", advertiser_id: "Advertiser ID", campaign: "Campaign", campaign_id: "Campaign ID", banner: "Banner", banner_id: "Banner ID", site: "Site", site_id: "Site ID", zone: "Zone", zone_id: "Zone ID", placement: "Placement", placement_id: "Placement ID", channel: "Channel", country: "Country", impressions: "Impressions", clicks: "Clicks", ctr: "CTR", conversions: "Conversions", i2c: "I2C", ccr: "CCR", net: "Net", gross: "Gross", profit: "Profit", ecpm_net: "eCPM Net", ecpm_gross: "eCPM Gross", ecpm_profit: "eCPM Profit", status: "Status"}
31
34
  end
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,58 @@
1
+ class AnalyticsController < ApplicationController
2
+ before_action :set_analytic, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /analytics
5
+ def index
6
+ @analytics = Analytic.all
7
+ end
8
+
9
+ # GET /analytics/1
10
+ def show
11
+ end
12
+
13
+ # GET /analytics/new
14
+ def new
15
+ @analytic = Analytic.new
16
+ end
17
+
18
+ # GET /analytics/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /analytics
23
+ def create
24
+ @analytic = Analytic.new(analytic_params)
25
+
26
+ if @analytic.save
27
+ redirect_to @analytic, notice: 'Analytic was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /analytics/1
34
+ def update
35
+ if @analytic.update(analytic_params)
36
+ redirect_to @analytic, notice: 'Analytic was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /analytics/1
43
+ def destroy
44
+ @analytic.destroy
45
+ redirect_to analytics_url, notice: 'Analytic was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_analytic
51
+ @analytic = Analytic.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def analytic_params
56
+ params.require(:analytic).permit(:date, :hour, :advertiser, :advertiser_id, :campaign, :campaign_id, :banner, :banner_id, :site, :site_id, :zone, :zone_id, :placement, :placement_id, :channel, :country, :impressions, :clicks, :ctr, :conversions, :i2c, :ccr, :net, :gross, :profit, :ecpm_net, :ecpm_gross, :ecpm_profit, :status)
57
+ end
58
+ end
@@ -53,6 +53,6 @@ class ZonesController < ApplicationController
53
53
 
54
54
  # Only allow a trusted parameter "white list" through.
55
55
  def zone_params
56
- params.require(:zone).permit(:epom_id, :name, :description, :site_id)
56
+ params.require(:zone).permit(:epom_id, :name, :description, :publisher_id)
57
57
  end
58
58
  end
@@ -0,0 +1,2 @@
1
+ module AnalyticsHelper
2
+ end
@@ -1,3 +1,4 @@
1
1
  class Advertiser < ActiveRecord::Base
2
+ has_many :campaigns
2
3
  acts_as_advertiser
3
- end
4
+ end
@@ -0,0 +1,3 @@
1
+ class Analytic < ActiveRecord::Base
2
+ acts_as_analytic
3
+ end
@@ -1,3 +1,5 @@
1
1
  class Banner < ActiveRecord::Base
2
+ belongs_to :campaign
3
+ validates :campaign_id, presence: true
2
4
  acts_as_banner
3
5
  end
@@ -1,3 +1,6 @@
1
1
  class Campaign < ActiveRecord::Base
2
+ belongs_to :advertiser
3
+ has_many :banners
4
+ validates :advertiser_id, presence: true
2
5
  acts_as_campaign
3
6
  end
@@ -1,3 +1,5 @@
1
1
  class Placement < ActiveRecord::Base
2
+ belongs_to :zone
3
+ validates :zone_id, presence: true
2
4
  acts_as_placement
3
5
  end
@@ -1,3 +1,4 @@
1
1
  class Publisher < ActiveRecord::Base
2
+ has_many :zones
2
3
  acts_as_site
3
4
  end
@@ -1,3 +1,6 @@
1
1
  class Zone < ActiveRecord::Base
2
+ belongs_to :publisher
3
+ has_many :placements
4
+ validates :publisher_id, presence: true
2
5
  acts_as_zone belongs_to: [{:name => 'publisher', :epom_element => 'Site', :model => 'Publisher'}]
3
6
  end
@@ -0,0 +1,133 @@
1
+ <%= form_for(@analytic) do |f| %>
2
+ <% if @analytic.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@analytic.errors.count, "error") %> prohibited this analytic from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @analytic.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :date %><br>
16
+ <%= f.date_select :date %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :hour %><br>
20
+ <%= f.time_select :hour %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :advertiser %><br>
24
+ <%= f.text_field :advertiser %>
25
+ </div>
26
+ <div class="field">
27
+ <%= f.label :advertiser_id %><br>
28
+ <%= f.number_field :advertiser_id %>
29
+ </div>
30
+ <div class="field">
31
+ <%= f.label :campaign %><br>
32
+ <%= f.text_field :campaign %>
33
+ </div>
34
+ <div class="field">
35
+ <%= f.label :campaign_id %><br>
36
+ <%= f.number_field :campaign_id %>
37
+ </div>
38
+ <div class="field">
39
+ <%= f.label :banner %><br>
40
+ <%= f.text_field :banner %>
41
+ </div>
42
+ <div class="field">
43
+ <%= f.label :banner_id %><br>
44
+ <%= f.number_field :banner_id %>
45
+ </div>
46
+ <div class="field">
47
+ <%= f.label :site %><br>
48
+ <%= f.text_field :site %>
49
+ </div>
50
+ <div class="field">
51
+ <%= f.label :site_id %><br>
52
+ <%= f.number_field :site_id %>
53
+ </div>
54
+ <div class="field">
55
+ <%= f.label :zone %><br>
56
+ <%= f.text_field :zone %>
57
+ </div>
58
+ <div class="field">
59
+ <%= f.label :zone_id %><br>
60
+ <%= f.number_field :zone_id %>
61
+ </div>
62
+ <div class="field">
63
+ <%= f.label :placement %><br>
64
+ <%= f.text_field :placement %>
65
+ </div>
66
+ <div class="field">
67
+ <%= f.label :placement_id %><br>
68
+ <%= f.number_field :placement_id %>
69
+ </div>
70
+ <div class="field">
71
+ <%= f.label :channel %><br>
72
+ <%= f.text_field :channel %>
73
+ </div>
74
+ <div class="field">
75
+ <%= f.label :country %><br>
76
+ <%= f.text_field :country %>
77
+ </div>
78
+ <div class="field">
79
+ <%= f.label :impressions %><br>
80
+ <%= f.number_field :impressions %>
81
+ </div>
82
+ <div class="field">
83
+ <%= f.label :clicks %><br>
84
+ <%= f.number_field :clicks %>
85
+ </div>
86
+ <div class="field">
87
+ <%= f.label :ctr %><br>
88
+ <%= f.text_field :ctr %>
89
+ </div>
90
+ <div class="field">
91
+ <%= f.label :conversions %><br>
92
+ <%= f.number_field :conversions %>
93
+ </div>
94
+ <div class="field">
95
+ <%= f.label :i2c %><br>
96
+ <%= f.text_field :i2c %>
97
+ </div>
98
+ <div class="field">
99
+ <%= f.label :ccr %><br>
100
+ <%= f.text_field :ccr %>
101
+ </div>
102
+ <div class="field">
103
+ <%= f.label :net %><br>
104
+ <%= f.number_field :net %>
105
+ </div>
106
+ <div class="field">
107
+ <%= f.label :gross %><br>
108
+ <%= f.number_field :gross %>
109
+ </div>
110
+ <div class="field">
111
+ <%= f.label :profit %><br>
112
+ <%= f.number_field :profit %>
113
+ </div>
114
+ <div class="field">
115
+ <%= f.label :ecpm_net %><br>
116
+ <%= f.number_field :ecpm_net %>
117
+ </div>
118
+ <div class="field">
119
+ <%= f.label :ecpm_gross %><br>
120
+ <%= f.number_field :ecpm_gross %>
121
+ </div>
122
+ <div class="field">
123
+ <%= f.label :ecpm_profit %><br>
124
+ <%= f.number_field :ecpm_profit %>
125
+ </div>
126
+ <div class="field">
127
+ <%= f.label :status %><br>
128
+ <%= f.text_field :status %>
129
+ </div>
130
+ <div class="actions">
131
+ <%= f.submit %>
132
+ </div>
133
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Analytic</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @analytic %> |
6
+ <%= link_to 'Back', analytics_path %>