rails_adserver 1.0.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/MIT-LICENSE +20 -0
- data/README.rdoc +0 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/rails_adserver/adspaces.js +2 -0
- data/app/assets/javascripts/rails_adserver/advertisements.js +2 -0
- data/app/assets/javascripts/rails_adserver/application.js +15 -0
- data/app/assets/javascripts/rails_adserver/rails_adserver_form.js.coffee +47 -0
- data/app/assets/stylesheets/rails_adserver/adspaces.css +4 -0
- data/app/assets/stylesheets/rails_adserver/advertisements.css +4 -0
- data/app/assets/stylesheets/rails_adserver/application.css +13 -0
- data/app/assets/stylesheets/rails_adserver/bootstrap-responsive.css +581 -0
- data/app/assets/stylesheets/rails_adserver/bootstrap.css +3496 -0
- data/app/assets/stylesheets/rails_adserver/pages.css +16 -0
- data/app/controllers/rails_adserver/adspaces_controller.rb +88 -0
- data/app/controllers/rails_adserver/advertisements_controller.rb +113 -0
- data/app/controllers/rails_adserver/application_controller.rb +25 -0
- data/app/controllers/rails_adserver/pages_controller.rb +9 -0
- data/app/helpers/rails_adserver/adspaces_helper.rb +4 -0
- data/app/helpers/rails_adserver/advertisements_helper.rb +4 -0
- data/app/helpers/rails_adserver/application_helper.rb +4 -0
- data/app/helpers/rails_adserver/pages_helper.rb +5 -0
- data/app/models/rails_adserver/adspace.rb +6 -0
- data/app/models/rails_adserver/advertisement.rb +110 -0
- data/app/models/rails_adserver/click.rb +5 -0
- data/app/uploaders/rails_adserver/advertisement_uploader.rb +56 -0
- data/app/views/layouts/rails_adserver/_sidebar.html.haml +21 -0
- data/app/views/layouts/rails_adserver/_topbar.html.haml +15 -0
- data/app/views/layouts/rails_adserver/advertisement.html.haml +3 -0
- data/app/views/layouts/rails_adserver/application.html.haml +25 -0
- data/app/views/rails_adserver/adspaces/_form.html.haml +16 -0
- data/app/views/rails_adserver/adspaces/edit.html.haml +1 -0
- data/app/views/rails_adserver/adspaces/index.html.haml +17 -0
- data/app/views/rails_adserver/adspaces/new.html.haml +1 -0
- data/app/views/rails_adserver/adspaces/show.html.haml +0 -0
- data/app/views/rails_adserver/advertisements/_advertisement.html.haml +7 -0
- data/app/views/rails_adserver/advertisements/_advertisements_table.html.haml +38 -0
- data/app/views/rails_adserver/advertisements/_form.html.haml +103 -0
- data/app/views/rails_adserver/advertisements/edit.html.haml +1 -0
- data/app/views/rails_adserver/advertisements/index.html.haml +2 -0
- data/app/views/rails_adserver/advertisements/new.html.haml +1 -0
- data/app/views/rails_adserver/advertisements/show.html.haml +5 -0
- data/app/views/rails_adserver/pages/home.html.haml +9 -0
- data/config/initializers/geokit.rb +1 -0
- data/config/initializers/haml.rb +2 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20120227014859_create_rails_adserver_advertisements.rb +13 -0
- data/db/migrate/20120227014945_create_rails_adserver_clicks.rb +9 -0
- data/db/migrate/20120228000410_add_param_restriction_to_advertisement.rb +5 -0
- data/db/migrate/20120228000647_add_name_of_param_restriction_to_advertisement.rb +5 -0
- data/db/migrate/20120228010151_create_rails_adserver_adspaces.rb +8 -0
- data/db/migrate/20120228010315_add_name_to_adspace.rb +5 -0
- data/db/migrate/20120228043946_add_adspace_id_to_advertisement.rb +6 -0
- data/db/migrate/20120305034458_add_ad_type_to_advertisement.rb +6 -0
- data/db/migrate/20120305040026_add_parameter_restriction_boolean_to_advertisement.rb +6 -0
- data/db/migrate/20120305044238_add_more_options_to_advertisement.rb +7 -0
- data/db/migrate/20120305054319_add_image_to_advertisement.rb +5 -0
- data/db/migrate/20120305195421_add_max_clicks_to_advertisement.rb +6 -0
- data/db/migrate/20120305203049_add_indexes.rb +8 -0
- data/db/migrate/20120305212451_change_indexes.rb +11 -0
- data/db/migrate/20120305214753_add_click_count_to_advertisement.rb +6 -0
- data/db/migrate/20120306023105_geolocation.rb +5 -0
- data/db/migrate/20120306052705_add_geolocation_names_to_advertisements.rb +7 -0
- data/db/migrate/20120306065447_add_advertisement_indexes.rb +8 -0
- data/db/migrate/20120323174313_add_backup_boolean_to_ads.rb +5 -0
- data/db/migrate/20120328043354_add_view_count_to_ads.rb +6 -0
- data/db/migrate/20120328043651_add_views_to_ads.rb +6 -0
- data/lib/rails_adserver.rb +13 -0
- data/lib/rails_adserver/config.rb +13 -0
- data/lib/rails_adserver/engine.rb +5 -0
- data/lib/rails_adserver/version.rb +3 -0
- data/lib/tasks/rails_adserver_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/page.js +5 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/page.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/page_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/page_helper.rb +2 -0
- data/test/dummy/app/models/user.rb +9 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/page/home.html.haml +1 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +57 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/carrierwave.rb +4 -0
- data/test/dummy/config/initializers/devise.rb +223 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/rails_adserver.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/devise.en.yml +57 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +10 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20120227204751_devise_create_users.rb +49 -0
- data/test/dummy/db/migrate/20120307204255_add_can_manage_ads_to_users.rb +6 -0
- data/test/dummy/db/schema.rb +84 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +26491 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/public/uploads/rails_adserver/advertisement/image/1/uszgP.jpg +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/users.yml +11 -0
- data/test/dummy/test/functional/page_controller_test.rb +9 -0
- data/test/dummy/test/unit/helpers/page_helper_test.rb +4 -0
- data/test/dummy/test/unit/user_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/C8F/860/sprockets%2Fd57276033f66173927e782e5c5b90c7b +0 -0
- data/test/dummy/tmp/cache/assets/C9E/E90/sprockets%2F4cebc1ca866a787736432410406a1b50 +0 -0
- data/test/dummy/tmp/cache/assets/CA6/990/sprockets%2F379e6655f2bcbb2380bc62b313314727 +0 -0
- data/test/dummy/tmp/cache/assets/CA7/ED0/sprockets%2F1e7b5a8a1137789918c115c01224bf4e +0 -0
- data/test/dummy/tmp/cache/assets/CC5/850/sprockets%2F7744952a67b1f4545bee9716f198c19b +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CE6/0F0/sprockets%2Ff173f2af55165a9415194d3e854c85da +0 -0
- data/test/dummy/tmp/cache/assets/CE7/DA0/sprockets%2F8ed8b29fe6a806301c31c79881a90c09 +0 -0
- data/test/dummy/tmp/cache/assets/CF2/CD0/sprockets%2Fda5995b74493c93c586f584b54c74a0b +0 -0
- data/test/dummy/tmp/cache/assets/CF3/920/sprockets%2F55f039ac18775d9358bdc75406f1e8f5 +0 -0
- data/test/dummy/tmp/cache/assets/D11/7F0/sprockets%2F9bcb57444f3287a8fa6fc45404e414c2 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D35/D40/sprockets%2F75eff8f38359ea04cb0101ae2b91d702 +0 -0
- data/test/dummy/tmp/cache/assets/D3C/710/sprockets%2Fe62ab8b4376ed759a9cb72a62b0651e0 +0 -0
- data/test/dummy/tmp/cache/assets/D3D/A90/sprockets%2Fb9991dccd27b48a625b6a0146717ade3 +0 -0
- data/test/dummy/tmp/cache/assets/D3E/910/sprockets%2F5fdb0e602ada6a930583809f853d39bb +0 -0
- data/test/dummy/tmp/cache/assets/D3F/D00/sprockets%2Fbe9a1d851c3b30e4a710983eda7f7196 +0 -0
- data/test/dummy/tmp/cache/assets/D42/E30/sprockets%2F261c172e1fdf9b39a4678a48371eaad6 +0 -0
- data/test/dummy/tmp/cache/assets/D4D/2F0/sprockets%2Fd7dd6367378df15e4f0bb6d93fb41529 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D5C/210/sprockets%2Fc78ac0bb1ca02e0ac1a566663840f8d6 +0 -0
- data/test/dummy/tmp/cache/assets/D5D/040/sprockets%2F539152cca8a2a9422e2a3ffa2a285d2d +0 -0
- data/test/dummy/tmp/cache/assets/D6D/670/sprockets%2F6ca4a9214539aeaf6f8401d3b77af16f +0 -0
- data/test/dummy/tmp/cache/assets/D73/BD0/sprockets%2Fac1f8d241dad59f05983cc1039ff4c58 +0 -0
- data/test/dummy/tmp/cache/assets/D7B/EA0/sprockets%2F0faa78844d169df84da0f122c89eb4f9 +0 -0
- data/test/dummy/tmp/cache/assets/D93/220/sprockets%2Fc0dcb0c6b055384fbd88d5b529c0da08 +0 -0
- data/test/dummy/tmp/cache/assets/DA0/180/sprockets%2F399fd2be6e4cf00a819a2630f8dd7ea2 +0 -0
- data/test/dummy/tmp/cache/assets/DB3/D90/sprockets%2F13d110dd2bde3bcd20b72f882330feae +0 -0
- data/test/dummy/tmp/cache/assets/DBA/2C0/sprockets%2F3879aa153bb0fe0de0fa0281f8cba2f2 +0 -0
- data/test/dummy/tmp/cache/assets/DCD/700/sprockets%2F57ee5a1f5e64e611b990eeadb75b14cb +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DDD/700/sprockets%2F78da8de4fc4dba2a5e7fa624ff518973 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E06/950/sprockets%2Fbc8b0eff6fc13759f0c069b4f8bc3e6c +0 -0
- data/test/dummy/tmp/cache/assets/EB3/120/sprockets%2Fbaadea6fabac9ad5d1215ef8d3bf67a6 +0 -0
- data/test/fixtures/rails_adserver/adspaces.yml +11 -0
- data/test/fixtures/rails_adserver/advertisements.yml +15 -0
- data/test/fixtures/rails_adserver/clicks.yml +7 -0
- data/test/functional/rails_adserver/adspaces_controller_test.rb +51 -0
- data/test/functional/rails_adserver/advertisements_controller_test.rb +51 -0
- data/test/functional/rails_adserver/pages_controller_test.rb +9 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/rails_adserver_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/helpers/rails_adserver/adspaces_helper_test.rb +6 -0
- data/test/unit/helpers/rails_adserver/advertisements_helper_test.rb +6 -0
- data/test/unit/helpers/rails_adserver/pages_helper_test.rb +6 -0
- data/test/unit/rails_adserver/adspace_test.rb +9 -0
- data/test/unit/rails_adserver/advertisement_test.rb +9 -0
- data/test/unit/rails_adserver/click_test.rb +9 -0
- data/test/unit/rails_adserver/clicks_test.rb +9 -0
- metadata +401 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Place all the styles related to the matching controller here.
|
|
3
|
+
They will automatically be included in application.css.
|
|
4
|
+
*/
|
|
5
|
+
footer{
|
|
6
|
+
padding: 40px 0 0 0;
|
|
7
|
+
text-align:center;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
legend{
|
|
11
|
+
font-size: 30px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
h1{
|
|
15
|
+
padding: 0 0 30px 0;
|
|
16
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
module RailsAdserver
|
|
2
|
+
class AdspacesController < RailsAdserver::ApplicationController
|
|
3
|
+
before_filter :_authenticate
|
|
4
|
+
# GET /adspaces
|
|
5
|
+
# GET /adspaces.json
|
|
6
|
+
def index
|
|
7
|
+
@title = "Ad-Spaces"
|
|
8
|
+
@adspaces = Adspace.all
|
|
9
|
+
respond_to do |format|
|
|
10
|
+
format.html # index.html.erb
|
|
11
|
+
format.json { render json: @adspaces }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# GET /adspaces/1
|
|
16
|
+
# GET /adspaces/1.json
|
|
17
|
+
def show
|
|
18
|
+
@adspace = Adspace.find(params[:id])
|
|
19
|
+
@tile = "Ad-Space - #{@adspace.name}"
|
|
20
|
+
respond_to do |format|
|
|
21
|
+
format.html # show.html.erb
|
|
22
|
+
format.json { render json: @adspace }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# GET /adspaces/new
|
|
27
|
+
# GET /adspaces/new.json
|
|
28
|
+
def new
|
|
29
|
+
@title = "New Ad-Space"
|
|
30
|
+
@adspace = Adspace.new
|
|
31
|
+
respond_to do |format|
|
|
32
|
+
format.html # new.html.erb
|
|
33
|
+
format.json { render json: @adspace }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# GET /adspaces/1/edit
|
|
38
|
+
def edit
|
|
39
|
+
@title = "Edit Ad-Space"
|
|
40
|
+
@adspace = Adspace.find(params[:id])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# POST /adspaces
|
|
44
|
+
# POST /adspaces.json
|
|
45
|
+
def create
|
|
46
|
+
@title = "New Ad-Space"
|
|
47
|
+
@adspace = Adspace.new(params[:adspace])
|
|
48
|
+
respond_to do |format|
|
|
49
|
+
if @adspace.save
|
|
50
|
+
format.html { redirect_to adspaces_url, notice: 'Adspace was successfully created.' }
|
|
51
|
+
format.json { render json: @adspace, status: :created, location: @adspace }
|
|
52
|
+
else
|
|
53
|
+
format.html { render action: "new" }
|
|
54
|
+
format.json { render json: @adspace.errors, status: :unprocessable_entity }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# PUT /adspaces/1
|
|
60
|
+
# PUT /adspaces/1.json
|
|
61
|
+
def update
|
|
62
|
+
@title = "Edit Ad-Space"
|
|
63
|
+
@adspace = Adspace.find(params[:id])
|
|
64
|
+
respond_to do |format|
|
|
65
|
+
if @adspace.update_attributes(params[:adspace])
|
|
66
|
+
format.html { redirect_to @adspace, notice: 'Adspace was successfully updated.' }
|
|
67
|
+
format.json { head :no_content }
|
|
68
|
+
else
|
|
69
|
+
format.html { render action: "edit" }
|
|
70
|
+
format.json { render json: @adspace.errors, status: :unprocessable_entity }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# DELETE /adspaces/1
|
|
76
|
+
# DELETE /adspaces/1.json
|
|
77
|
+
def destroy
|
|
78
|
+
@adspace = Adspace.find(params[:id])
|
|
79
|
+
@adspace.destroy
|
|
80
|
+
|
|
81
|
+
respond_to do |format|
|
|
82
|
+
format.html { redirect_to adspaces_url }
|
|
83
|
+
format.json { head :no_content }
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
module RailsAdserver
|
|
2
|
+
class AdvertisementsController < RailsAdserver::ApplicationController
|
|
3
|
+
before_filter :_authenticate, :except => [:ad_param, :ad_space]
|
|
4
|
+
require 'carrierwave'
|
|
5
|
+
def ad_param
|
|
6
|
+
id = RailsAdserver::Advertisement.ad_with_parameter(params[:adspace_id],params[:id],request.remote_ip)
|
|
7
|
+
@advertisement = RailsAdserver::Advertisement.find(id)
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.html {render :partial => 'advertisement', :layout => false}
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def ad_space
|
|
14
|
+
id = RailsAdserver::Advertisement.ad(params[:adspace_id],request.remote_ip)
|
|
15
|
+
@advertisement = RailsAdserver::Advertisement.find(id)
|
|
16
|
+
respond_to do |format|
|
|
17
|
+
format.html {render :partial => 'advertisement', :layout => false}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def click
|
|
22
|
+
client_ip = request.remote_ip
|
|
23
|
+
ad = Advertisement.find(params[:id])
|
|
24
|
+
ad.clicks.create(:ip_address => client_ip)
|
|
25
|
+
ad.update_attribute(:click_count,ad.clicks.count)
|
|
26
|
+
if ad.click_count >= ad.max_clicks
|
|
27
|
+
unless ad.max_clicks == 0
|
|
28
|
+
ad.update_attribute(:is_active,false)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
redirect_to ad.url
|
|
32
|
+
end
|
|
33
|
+
# GET /advertisements
|
|
34
|
+
def index
|
|
35
|
+
@advertisements = Advertisement.all
|
|
36
|
+
@title = "Advertisements"
|
|
37
|
+
respond_to do |format|
|
|
38
|
+
format.html # index.html.erb
|
|
39
|
+
format.json { render json: @advertisements }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# GET /advertisements/1
|
|
44
|
+
def show
|
|
45
|
+
@advertisement = Advertisement.find(params[:id])
|
|
46
|
+
@title = @advertisement.title
|
|
47
|
+
respond_to do |format|
|
|
48
|
+
format.html # show.html.erb
|
|
49
|
+
format.json { render json: @advertisement }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# GET /advertisements/new
|
|
54
|
+
def new
|
|
55
|
+
@advertisement = Advertisement.new
|
|
56
|
+
@title = "New Advertisement"
|
|
57
|
+
respond_to do |format|
|
|
58
|
+
format.html # new.html.erb
|
|
59
|
+
format.json { render json: @advertisement }
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# GET /advertisements/1/edit
|
|
64
|
+
def edit
|
|
65
|
+
@title = "Edit Advertisement"
|
|
66
|
+
@advertisement = Advertisement.find(params[:id])
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# POST /advertisements
|
|
70
|
+
def create
|
|
71
|
+
@advertisement = Advertisement.new(params[:advertisement])
|
|
72
|
+
geo = Geokit::Geocoders::MultiGeocoder.geocode(@advertisement.geolocation_location)
|
|
73
|
+
@advertisement.update_attributes(:city_name => geo.city, :state_name => geo.state, :country_name => geo.country)
|
|
74
|
+
respond_to do |format|
|
|
75
|
+
if @advertisement.save
|
|
76
|
+
format.html { redirect_to @advertisement, notice: 'Advertisement was successfully created.' }
|
|
77
|
+
format.json { render json: @advertisement, status: :created, location: @advertisement }
|
|
78
|
+
else
|
|
79
|
+
format.html { render action: "new" }
|
|
80
|
+
format.json { render json: @advertisement.errors, status: :unprocessable_entity }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# PUT /advertisements/1
|
|
86
|
+
def update
|
|
87
|
+
@advertisement = Advertisement.find(params[:id])
|
|
88
|
+
respond_to do |format|
|
|
89
|
+
if @advertisement.update_attributes(params[:advertisement])
|
|
90
|
+
geo = Geokit::Geocoders::MultiGeocoder.geocode(@advertisement.geolocation_location)
|
|
91
|
+
@advertisement.update_attributes(:city_name => geo.city, :state_name => geo.state, :country_name => geo.country)
|
|
92
|
+
format.html { redirect_to @advertisement, notice: 'Advertisement was successfully updated.' }
|
|
93
|
+
format.json { head :no_content }
|
|
94
|
+
else
|
|
95
|
+
format.html { render action: "edit" }
|
|
96
|
+
format.json { render json: @advertisement.errors, status: :unprocessable_entity }
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# DELETE /advertisements/1
|
|
102
|
+
def destroy
|
|
103
|
+
@advertisement = Advertisement.find(params[:id])
|
|
104
|
+
@advertisement.destroy
|
|
105
|
+
|
|
106
|
+
respond_to do |format|
|
|
107
|
+
format.html { redirect_to advertisements_url }
|
|
108
|
+
format.json { head :no_content }
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module RailsAdserver
|
|
2
|
+
class ApplicationController < ActionController::Base
|
|
3
|
+
helper :all
|
|
4
|
+
helper_method :_current_user, :_application_name, :_model_pool
|
|
5
|
+
private
|
|
6
|
+
def _model_pool
|
|
7
|
+
RailsAdserver::Config.models_pool
|
|
8
|
+
end
|
|
9
|
+
def _application_name
|
|
10
|
+
RailsAdserver::Config.application_name
|
|
11
|
+
end
|
|
12
|
+
def _current_user
|
|
13
|
+
instance_eval &RailsAdserver::Config.current_user_method
|
|
14
|
+
end
|
|
15
|
+
def _authenticate
|
|
16
|
+
if _current_user == nil
|
|
17
|
+
redirect_to '/404.html'
|
|
18
|
+
else
|
|
19
|
+
unless _current_user.can_manage_ads
|
|
20
|
+
redirect_to '/404.html'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
module RailsAdserver
|
|
2
|
+
class Advertisement < ActiveRecord::Base
|
|
3
|
+
belongs_to :adspace
|
|
4
|
+
has_many :clicks
|
|
5
|
+
require 'carrierwave/orm/activerecord'
|
|
6
|
+
|
|
7
|
+
attr_accessible :image, :title, :content, :width, :height, :is_active, :param_restriction, :ad_text, :parameter_restriction_boolean,
|
|
8
|
+
:param_restriction_name, :adspace_id, :ad_type, :url, :geolocation_boolean, :max_clicks, :geolocation_location, :city_name, :state_name, :country_name, :backup,
|
|
9
|
+
:max_impressions
|
|
10
|
+
|
|
11
|
+
validates :title, :presence => true
|
|
12
|
+
validates :adspace_id, :presence => true
|
|
13
|
+
|
|
14
|
+
mount_uploader :image, AdvertisementUploader
|
|
15
|
+
|
|
16
|
+
def self.ad_with_parameter(adspace_id,param,ip)
|
|
17
|
+
space = RailsAdserver::Adspace.find(adspace_id)
|
|
18
|
+
id = space.advertisements.random_ad(param)
|
|
19
|
+
if id == nil
|
|
20
|
+
geo_ip = Geokit::Geocoders::MultiGeocoder.geocode(ip)
|
|
21
|
+
geo = Geokit::Geocoders::MultiGeocoder.geocode("#{geo_ip.city},#{geo_ip.state},#{geo_ip.country}")
|
|
22
|
+
id = space.advertisements.geo_city(geo.city)
|
|
23
|
+
if id == nil
|
|
24
|
+
id = space.advertisements.geo_state(geo.state)
|
|
25
|
+
if id == nil
|
|
26
|
+
id = space.advertisements.geo_country(geo.country)
|
|
27
|
+
if id == nil
|
|
28
|
+
id = space.advertisements.random_ad(nil)
|
|
29
|
+
if id == nil
|
|
30
|
+
id = space.advertisements.backup_ad
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
unless id == nil
|
|
37
|
+
advertisement = RailsAdserver::Advertisement.find(id)
|
|
38
|
+
if advertisement.impressions_count == nil
|
|
39
|
+
advertisement.update_attribute(:impressions_count,0)
|
|
40
|
+
end
|
|
41
|
+
count = advertisement.impressions_count+1
|
|
42
|
+
advertisement.update_attribute(:impressions_count,count)
|
|
43
|
+
unless advertisement.max_impressions == 0 || advertisement.max_impressions == nil
|
|
44
|
+
if advertisement.max_impressions <= advertisement.impressions_count
|
|
45
|
+
advertisement.update_attribute(:is_active,false)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
return id
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.ad(adspace_id,ip)
|
|
53
|
+
space = RailsAdserver::Adspace.find(adspace_id)
|
|
54
|
+
geo_ip = Geokit::Geocoders::MultiGeocoder.geocode(ip)
|
|
55
|
+
geo = Geokit::Geocoders::MultiGeocoder.geocode("#{geo_ip.city},#{geo_ip.state},#{geo_ip.country}")
|
|
56
|
+
id = space.advertisements.geo_city(geo.city)
|
|
57
|
+
if id == nil
|
|
58
|
+
id = space.advertisements.geo_state(geo.state)
|
|
59
|
+
if id == nil
|
|
60
|
+
id = space.advertisements.geo_country(geo.country)
|
|
61
|
+
if id == nil
|
|
62
|
+
id = space.advertisements.random_ad(nil)
|
|
63
|
+
if id == nil
|
|
64
|
+
id = space.advertisements.backup_ad
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
unless id == nil
|
|
70
|
+
advertisement = RailsAdserver::Advertisement.find(id)
|
|
71
|
+
if advertisement.impressions_count == nil
|
|
72
|
+
advertisement.update_attribute(:impressions_count,0)
|
|
73
|
+
end
|
|
74
|
+
count = advertisement.impressions_count+1
|
|
75
|
+
advertisement.update_attribute(:impressions_count,count)
|
|
76
|
+
unless advertisement.max_impressions == 0 || advertisement.max_impressions == nil
|
|
77
|
+
if advertisement.max_impressions <= advertisement.impressions_count
|
|
78
|
+
advertisement.update_attribute(:is_active,false)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
return id
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def self.random_ad(param)
|
|
86
|
+
if param == nil
|
|
87
|
+
ad_ids = self.where("is_active = ? AND parameter_restriction_boolean = ? AND geolocation_boolean = ? AND backup = ?", true, false, false, false).map(&:id)
|
|
88
|
+
else
|
|
89
|
+
ad_ids = self.where("is_active = ? AND param_restriction = ? AND backup = ?",true, param, false).map(&:id)
|
|
90
|
+
end
|
|
91
|
+
id = ad_ids[rand(ad_ids.length)]
|
|
92
|
+
end
|
|
93
|
+
def self.geo_city(city)
|
|
94
|
+
ad_ids = self.where("city_name = ? AND is_active = ?", city, true).map(&:id)
|
|
95
|
+
id = ad_ids[rand(ad_ids.length)]
|
|
96
|
+
end
|
|
97
|
+
def self.geo_state(state)
|
|
98
|
+
ad_ids = self.where("state_name = ? AND city_name = ? AND is_active = ?", state, nil, true).map(&:id)
|
|
99
|
+
id = ad_ids[rand(ad_ids.length)]
|
|
100
|
+
end
|
|
101
|
+
def self.geo_country(country)
|
|
102
|
+
ad_ids = self.where("country_name = ? AND state_name = ? AND city_name = ? AND is_active = ?", country, nil, nil, true).map(&:id)
|
|
103
|
+
id = ad_ids[rand(ad_ids.length)]
|
|
104
|
+
end
|
|
105
|
+
def self.backup_ad
|
|
106
|
+
ad_ids = self.where("backup = ?", true).map(&:id)
|
|
107
|
+
id = ad_ids[rand(ad_ids.length)]
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module RailsAdserver
|
|
2
|
+
class AdvertisementUploader < CarrierWave::Uploader::Base
|
|
3
|
+
|
|
4
|
+
# Include RMagick or MiniMagick support:
|
|
5
|
+
# include CarrierWave::RMagick
|
|
6
|
+
# include CarrierWave::MiniMagick
|
|
7
|
+
|
|
8
|
+
# Choose what kind of storage to use for this uploader:
|
|
9
|
+
if RailsAdserver::Config.carrierwave_method == "Fog"
|
|
10
|
+
storage :fog
|
|
11
|
+
else
|
|
12
|
+
storage :file
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Override the directory where uploaded files will be stored.
|
|
16
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
|
17
|
+
def store_dir
|
|
18
|
+
"public/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
|
19
|
+
end
|
|
20
|
+
def extension_white_list
|
|
21
|
+
%w(jpg jpeg gif png)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cache_dir
|
|
25
|
+
"#{Rails.root}/tmp/uploads"
|
|
26
|
+
end
|
|
27
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
|
28
|
+
# def default_url
|
|
29
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
|
30
|
+
# end
|
|
31
|
+
|
|
32
|
+
# Process files as they are uploaded:
|
|
33
|
+
# process :scale => [200, 300]
|
|
34
|
+
#
|
|
35
|
+
# def scale(width, height)
|
|
36
|
+
# # do something
|
|
37
|
+
# end
|
|
38
|
+
|
|
39
|
+
# Create different versions of your uploaded files:
|
|
40
|
+
# version :thumb do
|
|
41
|
+
# process :scale => [50, 50]
|
|
42
|
+
# end
|
|
43
|
+
|
|
44
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
|
45
|
+
# For images you might use something like this:
|
|
46
|
+
# def extension_white_list
|
|
47
|
+
# %w(jpg jpeg gif png)
|
|
48
|
+
# end
|
|
49
|
+
|
|
50
|
+
# Override the filename of the uploaded files:
|
|
51
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
|
52
|
+
# def filename
|
|
53
|
+
# "something.jpg" if original_filename
|
|
54
|
+
# end
|
|
55
|
+
end
|
|
56
|
+
end
|