koudoku_coupons 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e7900ebb8890965fa7f9337a7a422aff58790d40
4
+ data.tar.gz: e56acd5960e67a578292bb9689c16749a8f10766
5
+ SHA512:
6
+ metadata.gz: 049af9bdf01c373249c18e5919aff3fefa2de5c9b3d91be12d3d613d06c67c8f1c4e4dbe3a400256635f20880c5f1ce503072707ae1dd723a2a9b4d9f6b88701
7
+ data.tar.gz: ad63c11831f50b70255e73a8b7d10293e0db9b41948e6ecd8a8749a756fe353855bff47cb8cca0870f3075bc7acc0e135050132b055e57e889e517553546d212
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # KoudokuCoupons
2
+
3
+ KoudokuCoupons adds support for [Stripe](http://www.stripe.com) coupons to [Koudoku](https://github.com/yas4891/koudoku).
4
+
5
+ **NOTE**: KoudokuCoupons currently only works with my fork of Koudoku, because the upstream repository does not merge pull requests at the moment.
6
+
7
+ ## Installation
8
+
9
+ For KoudokuCoupons to work properly you need to add the following lines to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'koudoku', git: 'https://github.com/yas4891/koudoku.git' # handles stripe subscriptions
13
+ gem 'koudoku_coupons'
14
+ ```
15
+
16
+ Next run `bundle install`. After that you need to add the migrations to your application:
17
+ ```ruby
18
+ rails g koudoku_coupons:install
19
+ rake db:migrate
20
+ ```
21
+ This will copy the migration into your application and run it. Additionally it will mount KoudokuCoupons at `/promotions`
22
+
23
+ If you are using [Devise](https://github.com/plataformatec/devise) for authentication, you need to add this line
24
+ to your `ApplicationController` to allow non-logged-in users to use coupons:
25
+
26
+ ```ruby
27
+ skip_filter :authenticate_user!, :if => :koudoku_coupons_controller?
28
+ ```
29
+
30
+ ## Setting Up New Coupons
31
+
32
+ First you need to create a new coupon in the [Stripe dashboard](https://dashboard.stripe.com/coupons).
33
+ To add a new promotion visit your application at `/promotions/promotions/new` and enter the following data:
34
+
35
+ - `name`: a name for the promotion. A promotion with name "50percentoff" will be available at `/promotions/50percentoff`
36
+ - `coupon_code`: the coupon code that you selected in the Stripe Dashboard
37
+ - `redirect`: The URL users will be redirected to after hitting the promotion URL - e.g. [https://www.linksspy.com/email/landingpage?utm_source=github&utm_medium=web&utm_campaign=open_source](https://www.linksspy.com/email/landingpage?utm_source=github&utm_medium=web&utm_campaign=open_source)
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'KoudokuCoupons'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module KoudokuCoupons
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,60 @@
1
+ module KoudokuCoupons
2
+ class PromotionsController < KoudokuCoupons::ApplicationController
3
+
4
+ def index
5
+ @promotions = Promotion.all
6
+ end
7
+
8
+ def new
9
+ @promotion = Promotion.new
10
+ end
11
+
12
+ def create
13
+ @promotion = Promotion.new(params[:promotion])
14
+
15
+ respond_to do |format|
16
+ if @promotion.save
17
+
18
+ format.html { redirect_to promotions_path, notice: 'Promotion was successfully created.' }
19
+ format.json { render json: @promotion, status: :created, location: @promotion}
20
+ else
21
+ format.html { render action: "new" }
22
+ format.json { render json: @promotion.errors, status: :unprocessable_entity }
23
+ end
24
+ end
25
+ end
26
+
27
+ def destroy
28
+ @promotion = Promotion.find(params[:id])
29
+ @promotion.destroy
30
+ redirect_to promotions_path
31
+ end
32
+
33
+ def edit
34
+ @promotion = Promotion.find(params[:id])
35
+ end
36
+
37
+ def update
38
+ @promotion = Promotion.find(params[:id])
39
+
40
+ respond_to do |format|
41
+ if @promotion.update_attributes(params[:promotion])
42
+ format.html { redirect_to promotions_path, notice: 'Promotion was successfully updated.' }
43
+ format.json { head :no_content }
44
+ else
45
+ format.html { render action: "edit" }
46
+ format.json { render json: @promotion.errors, status: :unprocessable_entity }
47
+ end
48
+ end
49
+ end
50
+
51
+ def show
52
+ return redirect_to main_app.root_path, status: 302 if params[:id].nil? || params[:id] == ''
53
+ @promotion = Promotion.find_by_name(params[:id])
54
+
55
+ return redirect_to main_app.root_path, status: 302 if @promotion.nil?
56
+ session[:koudoku_coupon_code] = @promotion.coupon_code
57
+ redirect_to @promotion.redirect, status: 302
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,10 @@
1
+ module KoudokuCoupons
2
+ module ApplicationHelper
3
+ # returns TRUE if the controller belongs to KoudokuCoupons
4
+ # false in all other cases, for convenience when executing filters
5
+ # in the main application
6
+ def koudoku_coupons_controller?
7
+ is_a? KoudokuCoupons::ApplicationController
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module KoudokuCoupons
2
+ class Promotion < ActiveRecord::Base
3
+ attr_accessible :coupon_code, :name, :redirect
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ - #@promotion.new_record? ? uri = calendar_appointments_path : uri = calendar_appointment_path
2
+ = form_for(@promotion, {html: {:class => 'form-horizontal', role: 'form', id: 'promotion_form'}}) do |f|
3
+ - if @promotion.errors.any?
4
+ #error_explanation
5
+ %h2= "#{pluralize(@promotion.errors.count, "error")} prohibited this promotion from being saved:"
6
+
7
+ %ul
8
+ -@promotion.errors.full_messages.each do |msg|
9
+ %li= msg
10
+ .form-group
11
+ = f.label :name, :class => 'col-sm-2 control-label'
12
+ .col-sm-10
13
+ = f.text_field :name, placeholder: 'Promotion Name', length: 30
14
+ .form-group
15
+ = f.label :coupon_code, 'Coupon Code', :class => 'col-sm-2 control-label'
16
+ .col-sm-10
17
+ = f.text_field :coupon_code, placeholder: 'Stripe Coupon Code', length: 30
18
+ .form-group
19
+ = f.label :redirect, 'Redirect URL', :class => 'col-sm-2 control-label'
20
+ .col-sm-10
21
+ = f.text_field :redirect, placeholder: 'Redirection URL'
22
+ .form-group
23
+ .col-sm-offset-2.col-sm-10
24
+ = f.submit 'Create', {:class => 'btn btn-primary btn-small', id: 'promotion_submit'}
@@ -0,0 +1,5 @@
1
+ .container
2
+ .row
3
+ .col-md-offset-1.col-md-10
4
+ %h3 Edit Promotion
5
+ = render partial: 'form'
@@ -0,0 +1,18 @@
1
+ .container
2
+ .row
3
+ .col-md-offset-1.col-md-10
4
+ %table.table.table-bordered.table-condensed
5
+ %tr
6
+ %th Name
7
+ %th Coupon Code
8
+ %th Redirection Target
9
+ %th
10
+ - @promotions.each do |promotion|
11
+ %tr
12
+ %td= promotion.name
13
+ %td= promotion.coupon_code
14
+ %td= promotion.redirect
15
+ %td
16
+ = link_to "Edit", edit_promotion_path(promotion)
17
+ = link_to "Delete", promotion_path(promotion), method: 'DELETE'
18
+ =link_to 'New Promotion', new_promotion_path, :class => 'btn btn-default'
@@ -0,0 +1,5 @@
1
+ .container
2
+ .row
3
+ .col-md-offset-1.col-md-10
4
+ %h3 Create new Promotion
5
+ = render partial: 'form'
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>KoudokuCoupons</title>
5
+ <%= stylesheet_link_tag "koudoku_coupons/application", :media => "all" %>
6
+ <%= javascript_include_tag "koudoku_coupons/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ KoudokuCoupons::Engine.routes.draw do
2
+
3
+ resources :promotions
4
+
5
+ get ":id" => 'promotions#show', :as => :default_route, :defaults => {id: ''}
6
+ end
@@ -0,0 +1,11 @@
1
+ class CreateKoudokuCouponsPromotions < ActiveRecord::Migration
2
+ def change
3
+ create_table :koudoku_coupons_promotions do |t|
4
+ t.string :name
5
+ t.string :coupon_code
6
+ t.string :redirect
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+
2
+ require 'rails/generators'
3
+
4
+ module KoudokuCoupons
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root "#{KoudokuCoupons::Engine.root}/app/views/koudoku_coupons/"
8
+ desc "installs koudoku_coupons"
9
+
10
+ def install
11
+ unless defined?(KoudokuCoupons)
12
+ gem 'koudoku_coupons'
13
+ end
14
+
15
+ # mounts KoudokuCoupons in the applications routes.rb file
16
+ route "mount KoudokuCoupons::Engine, at: 'promotions'"
17
+
18
+ end
19
+
20
+ def copy_migrations
21
+ rake("koudoku_coupons:install:migrations")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module KoudokuCoupons
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace KoudokuCoupons
4
+
5
+ # loads KoudokuCoupons::ApplicationHelper into ::ApplicationController
6
+ # so we can use #koudoku_coupons_controller? in the main_app
7
+ initializer 'load_koudoku_coupons_helpers' do
8
+ ActiveSupport.on_load(:action_controller) do
9
+ include KoudokuCoupons::ApplicationHelper
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module KoudokuCoupons
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "koudoku_coupons/engine"
2
+
3
+ module KoudokuCoupons
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :koudoku_coupons do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koudoku_coupons
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christoph Engelhardt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.19
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.19
27
+ - !ruby/object:Gem::Dependency
28
+ name: koudoku
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.11
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.11
41
+ - !ruby/object:Gem::Dependency
42
+ name: haml-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'KoudokuCoupons allows you to use the full power of '
70
+ email:
71
+ - christoph@it-engelhardt.de
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - README.md
77
+ - Rakefile
78
+ - app/assets/javascripts/koudoku_coupons/application.js
79
+ - app/assets/stylesheets/koudoku_coupons/application.css
80
+ - app/controllers/koudoku_coupons/application_controller.rb
81
+ - app/controllers/koudoku_coupons/promotions_controller.rb
82
+ - app/helpers/koudoku_coupons/application_helper.rb
83
+ - app/models/koudoku_coupons/promotion.rb
84
+ - app/views/koudoku_coupons/promotions/_form.html.haml
85
+ - app/views/koudoku_coupons/promotions/edit.html.haml
86
+ - app/views/koudoku_coupons/promotions/index.html.haml
87
+ - app/views/koudoku_coupons/promotions/new.html.haml
88
+ - app/views/layouts/koudoku_coupons/application.html.erb
89
+ - config/routes.rb
90
+ - db/migrate/20140918035910_create_koudoku_coupons_promotions.rb
91
+ - lib/generators/koudoku_coupons/install_generator.rb
92
+ - lib/koudoku_coupons.rb
93
+ - lib/koudoku_coupons/engine.rb
94
+ - lib/koudoku_coupons/version.rb
95
+ - lib/tasks/koudoku_coupons_tasks.rake
96
+ homepage: http://www.it-engelhardt.de
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Adds capability for full Stripe coupons to Koudoku
119
+ test_files: []