versacommerce_app 1.0.17

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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/CHANGELOG +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +19 -0
  6. data/README.md +68 -0
  7. data/Rakefile +13 -0
  8. data/install.rb +20 -0
  9. data/lib/generators/versacommerce_app/README +15 -0
  10. data/lib/generators/versacommerce_app/USAGE +21 -0
  11. data/lib/generators/versacommerce_app/templates/app/assets/images/favicon.png +0 -0
  12. data/lib/generators/versacommerce_app/templates/app/assets/images/grid-18px.png +0 -0
  13. data/lib/generators/versacommerce_app/templates/app/assets/images/versacommerce-100.png +0 -0
  14. data/lib/generators/versacommerce_app/templates/app/assets/images/versacommerce-114.png +0 -0
  15. data/lib/generators/versacommerce_app/templates/app/assets/images/versacommerce-57.png +0 -0
  16. data/lib/generators/versacommerce_app/templates/app/assets/images/versacommerce-72.png +0 -0
  17. data/lib/generators/versacommerce_app/templates/app/controllers/home_controller.rb +13 -0
  18. data/lib/generators/versacommerce_app/templates/app/controllers/sessions_controller.rb +68 -0
  19. data/lib/generators/versacommerce_app/templates/app/helpers/home_helper.rb +4 -0
  20. data/lib/generators/versacommerce_app/templates/app/helpers/sessions_helper.rb +4 -0
  21. data/lib/generators/versacommerce_app/templates/app/views/home/index.html.erb +161 -0
  22. data/lib/generators/versacommerce_app/templates/app/views/layouts/application.html.erb +129 -0
  23. data/lib/generators/versacommerce_app/templates/app/views/sessions/new.html.erb +15 -0
  24. data/lib/generators/versacommerce_app/templates/config/versacommerce_api.yml +0 -0
  25. data/lib/generators/versacommerce_app/templates/public/404.html +40 -0
  26. data/lib/generators/versacommerce_app/templates/public/422.html +40 -0
  27. data/lib/generators/versacommerce_app/templates/public/500.html +40 -0
  28. data/lib/generators/versacommerce_app/templates/public/favicon.png +0 -0
  29. data/lib/generators/versacommerce_app/templates/public/versacommerce-114.png +0 -0
  30. data/lib/generators/versacommerce_app/templates/public/versacommerce-57.png +0 -0
  31. data/lib/generators/versacommerce_app/templates/public/versacommerce-72.png +0 -0
  32. data/lib/generators/versacommerce_app/versacommerce_app_generator.rb +65 -0
  33. data/lib/versacommerce_app/configuration.rb +47 -0
  34. data/lib/versacommerce_app/ensure_api_session.rb +33 -0
  35. data/lib/versacommerce_app/railtie.rb +18 -0
  36. data/lib/versacommerce_app/version.rb +4 -0
  37. data/lib/versacommerce_app.rb +18 -0
  38. data/versacommerce_app.gemspec +22 -0
  39. metadata +115 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a2a7f4d54e37905ba1e19d57a2ef5a907b988073
4
+ data.tar.gz: 4d3590c5b311ad9a259b9be92f87c521c0e120f1
5
+ SHA512:
6
+ metadata.gz: 4f566827b163e6736531db2f8e25fe95cb763215671485556c2def3643059d01950eda0209b95db3e6e2fcef76e23f3b831a69a336b76e5f13bd3958dffc26f8
7
+ data.tar.gz: e716a95df6f8491922f4cb57b9d69813ab925bab4c7231ad5773aa29008aed6e3b94abafad5a329d6ac17dd6b54f80938c80d345e2d6db4ed5e221268a921d74
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ *.swp
3
+ .bundle
4
+ .DS_Store
5
+ .rvmrc
6
+ /coverage
7
+ Gemfile.lock
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ 1.0.5
2
+ 1.0.0 initial version [dorra]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in versacommerce_app.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 VersaCommerce
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # VersaCommerce App Generator
2
+
3
+ VersaCommerce application generator for Rails 3.1 and Rails 4.0
4
+
5
+ ## Description
6
+
7
+ This gem makes it easy to get a Rails 3.1 or Rails 4.0 app up and running with the VersaCommerce API.
8
+
9
+ The generator creates a basic SessionsController for authenticating with your shop and a HomeController which displays basic information about your products, orders and the shop itself.
10
+
11
+ *Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete some of your files.*
12
+
13
+ ## Installation
14
+
15
+ ``` sh
16
+ # Create a new rails app
17
+ $ rails new my_versacommerce_app
18
+ $ cd my_versacommerce_app
19
+
20
+ # Add the gem versacommerce_app to your Gemfile
21
+ $ echo "gem 'versacommerce_app'" >> Gemfile
22
+ $ bundle install
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ``` sh
28
+ $ rails generate versacommerce_app your_app_api_key your_app_secret
29
+ ```
30
+
31
+ ### Example
32
+
33
+ ``` sh
34
+ $ rails generate versacommerce_app aabbcc1122334455667788 gghhhiijjkk998877665544
35
+ ```
36
+
37
+ This will create a SessionsController and HomeController with their own views.
38
+
39
+ ## Configuring VersaCommerce App
40
+
41
+ It's possible to set your API key and secret key from different sources:
42
+
43
+ * Configuration in a Rails `<environment>.rb` config file
44
+
45
+ ``` ruby
46
+ config.versacommerce.api_key = 'your api key'
47
+ config.versacommerce.secret = 'your secret'
48
+ ```
49
+
50
+ * Configuration loaded from `<environment>` key in `versacommerce_app.yml`
51
+
52
+ ``` yaml
53
+ development:
54
+ api_key: your api key
55
+ secret: your secret
56
+ ```
57
+
58
+ ## Next...
59
+
60
+ Start your application:
61
+
62
+ ``` sh
63
+ $ rails server
64
+ ```
65
+
66
+ Now visit http://localhost:3000 and register (install) your application with a VersaCommerce store. Even if Rails tells you to visit your app at http://0.0.0.0:3000, go to http://localhost:3000.
67
+
68
+ After your application has been given whatever API permissions, you're ready to start experimenting with the VersaCommerce API. Have Fun :)
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib/versacommerce_app'
8
+ t.libs << 'test'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ t.verbose = true
11
+ end
12
+
13
+ task :default => :test
data/install.rb ADDED
@@ -0,0 +1,20 @@
1
+ puts
2
+ puts "VERSACOMMERCE APP GENERATOR"
3
+ puts
4
+ puts "Every app needs to:"
5
+ puts
6
+ puts "1. Registered with VersaCommerce. You will receive an APP_KEY and a shared secret."
7
+ puts "2. Registered with a Shop. This will provide a token."
8
+ puts
9
+ puts
10
+ puts "To get going, register your app with VersaCommerce:"
11
+ puts
12
+ puts " - Send an E-Mail to support@versacommerce.de, we will get in touch with you immediately."
13
+ puts
14
+ puts " * Now run the generator:"
15
+ puts
16
+ puts " $ rails generate versacommerce_app API_KEY SHARED_SECRET"
17
+ puts
18
+ puts " $ rails server"
19
+ puts
20
+ puts " * Visit http://localhost:3000 and use a shop URL to install this app."
@@ -0,0 +1,15 @@
1
+
2
+ What's next?
3
+ ------------
4
+
5
+ Start your application with:
6
+
7
+ $ rails server
8
+
9
+ Now visit http://localhost:3000 and register (install) your application with a VersaCommerce store.
10
+
11
+ After your application has been given read or read/write API permission by the
12
+ shop, you're ready to start experimenting with the VersaCommerce API.
13
+
14
+
15
+ API Reference https://github.com/versacommerce/vc-api
@@ -0,0 +1,21 @@
1
+ Description:
2
+ This is a generator for creating a basic VersaCommerce application to quickly get
3
+ you started. You can see some examples on how to use the VersaCommerce API.
4
+
5
+ The generator creates a basic sessions controller for authenticating with your
6
+ Shop and a controller called "home" which displays basic information
7
+ about your products, orders and articles.
8
+
9
+ Note: It's recommended to use this on a new Rails project, so that the
10
+ generator won't overwrite/delete some of your files.
11
+
12
+ Usage:
13
+ Pass your API key and then your Secret, which the sessions controller
14
+ will need to authenticate with your shop.
15
+ If you don't have an API key yet, register your application with us.
16
+
17
+
18
+ Examples:
19
+ rails/generate versacommerce_app aabbccddeee112233445566 ppooiikkkhh99887...
20
+
21
+ This will create a sessions controller and a home controller and views.
@@ -0,0 +1,13 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class HomeController < ApplicationController
3
+ around_filter :ensure_current_api_session
4
+
5
+ def index
6
+ # get 10 products
7
+ @products = VersacommerceAPI::Product.find(:all, :params => {:limit => 10})
8
+
9
+ # get latest 5 orders
10
+ @orders = VersacommerceAPI::Order.find(:all, :params => {:limit => 5, :order => "created_at DESC" })
11
+ end
12
+
13
+ end
@@ -0,0 +1,68 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class SessionsController < ApplicationController
3
+
4
+ def new
5
+ authenticate if params[:shop].present?
6
+ end
7
+
8
+ def create
9
+ authenticate
10
+ end
11
+
12
+ def destroy
13
+ session[:versacommerce] = nil
14
+ flash[:success] = "Successfully logged out."
15
+ redirect_to :action => 'new'
16
+ end
17
+
18
+ def finalize
19
+ current_session = VersacommerceAPI::Session.new(params[:shop], params[:t], params)
20
+ if current_session.valid?
21
+ #
22
+ # IF YOU WANT TO SAVE THE TOKEN FOR LATER USE,
23
+ #
24
+ # 1) CREATE A MODEL
25
+ # $ rails generate model user shop:string token:string
26
+ # $ rake db:create && rake db:migrate
27
+ #
28
+ # 2) SAVE THE TOKEN RIGHT HERE
29
+ # User.where(shop: params[:shop]).first_or_create do |user|
30
+ # user.token = params[:t]
31
+ # end
32
+ #
33
+ # 3) USE THE TOKEN TO CONNECT TO THIS SHOP WITHOUT USER INTERACTION
34
+ # https://github.com/versacommerce/versacommerce_api (see sample code)
35
+ #
36
+ session[:versacommerce] = current_session
37
+ flash[:success] = "Connection established to: #{params[:shop]}"
38
+ redirect_to return_address
39
+ else
40
+ flash[:warning] = "Connection failed."
41
+ redirect_to :action => 'index'
42
+ end
43
+ end
44
+
45
+ protected
46
+
47
+ def authenticate
48
+ if shop_name = sanitize_shop_param(params)
49
+ redirect_to VersacommerceAPI::Session.new(shop_name).create_permission_url
50
+ else
51
+ redirect_to return_address
52
+ end
53
+ end
54
+
55
+ def return_address
56
+ session[:return_to] || root_url
57
+ end
58
+
59
+ def sanitize_shop_param(params)
60
+ return unless params[:shop].present?
61
+ name = params[:shop].to_s.strip
62
+ name += '.versacommerce.de' if !name.include?("versacommerce.de") && !name.include?(".")
63
+ name.sub('https://', '').sub('http://', '')
64
+ u = URI("http://#{name}")
65
+ u.host.ends_with?("versacommerce.de") ? u.host : nil
66
+ end
67
+
68
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module HomeHelper
3
+
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module SessionsHelper
3
+
4
+ end
@@ -0,0 +1,161 @@
1
+ <div class="page-header">
2
+ <h1>How does this work?</h1>
3
+ </div>
4
+ <p class="lead">
5
+ This is the VersaCommerce App Template build on <a href="http://getbootstrap.com" target="_blank">Bootstrap 3</a>.
6
+ To get the ball rolling: It uses the <a href="https://github.com/versacommerce/versacommerce_api" target="_blank">VersaCommerce API GEM</a> for accessing the VersaCommerce admin REST web services. It is build with the <a href="https://github.com/versacommerce/versacommerce_app" target="_blank">versacommerce_app generator</a> which provides a <a href="https://github.com/versacommerce/versacommerce_app/blob/master/lib/versacommerce_app/ensure_api_session.rb" target="_blank">module</a> to ensure the API-Session.
7
+ </p>
8
+
9
+
10
+ <div class="panel panel-default">
11
+ <div class="panel-heading">
12
+ <h3 class="panel-title">Check out the code</h3>
13
+ </div>
14
+ <div class="panel-body">
15
+ <p>
16
+ <p><strong>Check out the</strong> <code>home_controller</code></p>
17
+ <p>The controller in this demo application fetches the newest 5 orders and products and makes them available as instance variables <code>@orders</code> and <code>@products</code></p>
18
+ </p>
19
+ <p>
20
+ <p><strong>Take a look at</strong> <code>index.html.erb</code></p>
21
+ <p>Index is the Ruby template you are currently viewing. Have a look at the markup and Ruby code to see how the VersaCommerce API is being used. It's located at <code>views/home/index.html.erb</code></p>
22
+ </p>
23
+ <p>
24
+ <p><strong>Check out the</strong> <code>sessions_controller</code></p>
25
+ <p>The sessions-controller in this demo application makes sure, you are connected to a VersaCommerce Shop. If not, it asks you to register (install) your app with a shop. After authorisation it calls the action <code>sessions#finalize</code>. If you want to store the &quot;registration-token&quot; <code>token</code> for unattended usage, you can place your code right here.</p>
26
+ </p>
27
+ </div>
28
+ </div>
29
+
30
+
31
+ <div class="panel panel-default">
32
+ <div class="panel-heading">
33
+ <h3 class="panel-title">Additional Documentation</h3>
34
+ </div>
35
+ <div class="panel-body">
36
+ <p>
37
+ <%= link_to 'API documentation', 'https://github.com/versacommerce/vc-api' %><br/>
38
+ <span class="note">Learn what you can do with the VersaCommerce API</span>
39
+ </p>
40
+ <p>
41
+ <%= link_to 'Bootstrap documentation', 'http://twitter.github.com/bootstrap/' %><br/>
42
+ <span class="note">Find out what you can do with Twitter Bootstrap</span>
43
+ </p>
44
+ </div>
45
+ </div>
46
+
47
+
48
+ <div class="panel panel-default">
49
+ <div class="panel-heading">
50
+ <h3 class="panel-title">About this Shop</h3>
51
+ </div>
52
+ <div class="panel-body">
53
+ <p>
54
+ <p><strong>Name</strong></p>
55
+ <p><%= current_shop.shop.name %></p>
56
+ </p>
57
+ <p>
58
+ <p><strong>URL</strong></p>
59
+ <p><%= current_shop.shop.url %></p>
60
+ </p>
61
+ <p>
62
+ <p><strong>Price includes tax</strong></p>
63
+ <p><%= current_shop.shop.price_includes_tax%></p>
64
+ </p>
65
+ <p>
66
+ <p><strong>Currency</strong></p>
67
+ <p><%= current_shop.shop.currency_code%></p>
68
+ </p>
69
+ </div>
70
+ </div>
71
+
72
+
73
+ <div class="panel panel-default">
74
+ <div class="panel-heading">
75
+ <h3 class="panel-title">Recent Orders</h3>
76
+ </div>
77
+ <div class="panel-body">
78
+
79
+ <% if @orders.blank? %>
80
+ <table class="table table-striped">
81
+ <tr>
82
+ <td><em>There are no orders in your shop.</em></td>
83
+ </tr>
84
+ </table>
85
+ <% else %>
86
+ <table class="table table-striped">
87
+ <thead>
88
+ <tr>
89
+ <th>Order</th>
90
+ <th>Customer</th>
91
+ <th>Status</th>
92
+ <th>Total</th>
93
+ </tr>
94
+ </thead>
95
+ <% @orders.each do |order| %>
96
+ <tr>
97
+ <td><%= link_to order.code, "https://#{current_shop.url}/admin/orders/#{order.id}", :target => 'blank' %></td>
98
+ <td><%= "#{order.billing_address.firstname} #{order.billing_address.lastname}" %></td>
99
+ <td>
100
+ <%= order.status %>
101
+ </td>
102
+ <td><%= order.total %> <%= order.currency %></td>
103
+ </tr>
104
+ <% end %>
105
+ </table>
106
+ <% end %>
107
+
108
+ </div>
109
+ </div>
110
+
111
+
112
+ <h4>New Products</h4>
113
+
114
+ <% if @products.blank? %>
115
+
116
+ <div class="panel-group">
117
+ <div class="panel-heading">
118
+ <em>There are no products in your shop.</em>
119
+ </div>
120
+ </div>
121
+
122
+ <% else %>
123
+
124
+ <div class="accordion" id="accordion">
125
+ <div class="panel-group">
126
+
127
+ <% @products.each_with_index do |product, index| %>
128
+ <div class="panel panel-default">
129
+
130
+ <div class="panel-heading">
131
+ <h4 class="panel-title">
132
+ <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse<%= product.id %>">
133
+ <%= product.title %>
134
+ </a>
135
+ <span class="pull-right muted"><%= product.price %> <%= current_shop.shop.currency_code %></span>
136
+ </h4>
137
+ </div>
138
+
139
+ <div id="collapse<%= product.id %>" class="panel-body collapse <% if index == 0 %>in<% end %>">
140
+ <div class="panel-body">
141
+ <%= image_tag( product.featured_image.medium, class: "pull-right" ) unless product.featured_image_url.blank? %>
142
+ <p><strong>SKU:</strong> <%= product.code %></p>
143
+ <p><strong>Category:</strong> <%= product.category %></p>
144
+ <p><strong>Vendor:</strong> <%= product.vendor %></p>
145
+ <%= raw(product.description_html) %>
146
+ <br/>
147
+ <p class="muted">Created at <%= product.created_on.strftime("%Y-%m-%d") %></p>
148
+ <br/>
149
+ <%= link_to "Open this product in /admin", "http://#{current_shop.url}/admin/catalog/products/#{product.id}/edit", :target => 'blank', class: "btn btn-default" %>
150
+ </div>
151
+ </div>
152
+
153
+ </div>
154
+ <% end %>
155
+
156
+ </div>
157
+
158
+ </div>
159
+ <% end %>
160
+
161
+ <br/><br/>
@@ -0,0 +1,129 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta name="description" content="">
7
+ <meta name="author" content="">
8
+ <link rel="shortcut icon" href="../assets/favicon.png">
9
+ <link rel="apple-touch-icon" href="../assets/versacommerce-57.png">
10
+ <link rel="apple-touch-icon" sizes="72x72" href="../assets/versacommerce-72.png">
11
+ <link rel="apple-touch-icon" sizes="114x114" href="../assets/versacommerce-114.png">
12
+
13
+ <title>VersaCommerce Sample App</title>
14
+
15
+ <!-- Bootstrap core CSS -->
16
+ <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
17
+
18
+ <%= stylesheet_link_tag 'application' %>
19
+
20
+ <style type="text/css" media="screen">
21
+ /* Sticky footer styles
22
+ -------------------------------------------------- */
23
+
24
+ html,
25
+ body {
26
+ height: 100%;
27
+ /* The html and body elements cannot have any padding or margin. */
28
+ }
29
+
30
+ /* Wrapper for page content to push down footer */
31
+ #wrap {
32
+ min-height: 100%;
33
+ height: auto !important;
34
+ height: 100%;
35
+ /* Negative indent footer by its height */
36
+ margin: 0 auto -60px;
37
+ /* Pad bottom by footer height */
38
+ padding: 0 0 60px;
39
+ }
40
+
41
+ /* Set the fixed height of the footer here */
42
+ #footer {
43
+ height: 60px;
44
+ background-color: #f5f5f5;
45
+ }
46
+
47
+
48
+ /* Custom page CSS
49
+ -------------------------------------------------- */
50
+
51
+ #wrap > .container {
52
+ padding: 60px 15px 0;
53
+ }
54
+ .container .credit {
55
+ margin: 20px 0;
56
+ }
57
+
58
+ #footer > .container {
59
+ padding-left: 15px;
60
+ padding-right: 15px;
61
+ }
62
+
63
+ code {
64
+ font-size: 80%;
65
+ }
66
+ </style>
67
+
68
+ <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
69
+ <!--[if lt IE 9]>
70
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
71
+ <!-- <script src="../../assets/js/respond.min.js"></script> -->
72
+ <![endif]-->
73
+ <%= csrf_meta_tags %>
74
+ </head>
75
+
76
+ <body>
77
+
78
+ <!-- Wrap all page content here -->
79
+ <div id="wrap">
80
+ <!-- Fixed navbar -->
81
+ <div class="navbar navbar-default navbar-fixed-top">
82
+ <div class="container">
83
+ <div class="navbar-header">
84
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
85
+ <span class="icon-bar"></span>
86
+ <span class="icon-bar"></span>
87
+ <span class="icon-bar"></span>
88
+ </button>
89
+ <%= link_to 'VersaCommerce App', '/', :class => 'navbar-brand' %>
90
+ </div>
91
+ <% if current_shop %>
92
+ <div class="collapse navbar-collapse">
93
+ <ul class="nav navbar-nav">
94
+ <li><a href="https://github.com/versacommerce/vc-api" target="_blank">API Documentation</a></li>
95
+ <li><a href="https://github.com/versacommerce/versacommerce_api" target="_blank">API GEM</a></li>
96
+ <li class="dropdown">
97
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= current_shop.url %> <b class="caret"></b></a>
98
+ <ul class="dropdown-menu">
99
+ <li><%= link_to raw('<i class="icon-home"></i> Shop'), "http://"+current_shop.url, :target => 'blank' %></li>
100
+ <li><%= link_to raw('<i class="icon-cog"></i> Admin'), "http://"+current_shop.url+"/admin", :target => 'blank' %></li>
101
+ <li class="divider"></li>
102
+ <li><%= link_to raw('<i class="icon-off"></i> Logout'), logout_path, :method => :delete %></li>
103
+ </ul>
104
+ </li>
105
+ </ul>
106
+ </div><!--/.nav-collapse -->
107
+ <% end %>
108
+ </div>
109
+ </div>
110
+
111
+ <!-- Begin page content -->
112
+ <div class="container">
113
+ <% flash.each do |type, message| %>
114
+ <div class="alert alert-<%= type %>"><%= message %></div>
115
+ <% end %>
116
+ <%= yield %>
117
+ </div>
118
+ </div>
119
+
120
+ <div id="footer">
121
+ <div class="container">
122
+ <p class="text-muted credit">VersaCommerce Example App. Created by <a href="http://www.versacommerce.de" target="_blank">versacommerce.de</a></p>
123
+ </div>
124
+ </div>
125
+
126
+ <%= javascript_include_tag 'application' %>
127
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
128
+ </body>
129
+ </html>
@@ -0,0 +1,15 @@
1
+ <div class="page-header" id="login-header">
2
+ <%= image_tag 'versacommerce-100.png', class: "pull-right", style: "opacity:.55" %>
3
+ <h1>Register this app with your shop.</h1>
4
+ <h1><small>This app requires you to login to start using it.</small></h1>
5
+ </div>
6
+
7
+ <div>
8
+ <%= form_tag login_path, :class => 'form-inline' do %>
9
+ <span class="help-block">Please enter the shop url. Example: myshop.versacommerce.de</span>
10
+ <div class="form-group">
11
+ <%= text_field_tag 'shop', nil, size: 40, :placeholder => 'myshop.versacommerce.de', :class => 'form-control' %>
12
+ </div>
13
+ <%= submit_tag 'Install / Register', :class => 'btn btn-primary btn-large' %>
14
+ <% end %>
15
+ </div>
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>404 Error: This page doesn't exist!</title>
5
+
6
+ <style>
7
+ .container { text-align:center;}
8
+ .navbar .brand { float:none;}
9
+ </style>
10
+ </head>
11
+
12
+ <body>
13
+ <div class="navbar navbar-fixed-top">
14
+ <div class="navbar-inner">
15
+ <div class="container">
16
+ <a href="/" class="brand">VersaCommerce Demo App</a>
17
+ </div>
18
+ </div>
19
+ </div>
20
+
21
+ <div class="container">
22
+ <div class="content">
23
+ <div class="page-header">
24
+ <h1>AH! 404!</h1>
25
+ </div>
26
+
27
+ <h3><i class="icon-warning-sign" style="margin-top:6px; opacity:.5;"></i> Well dang, looks like this page doesn't exist.</h3>
28
+ <p class="muted">Well, not this one, but the one you were looking for... at least there's a kitten!</p>
29
+ <br/>
30
+ <p><img src="http://gifs.gifbin.com/122009/1259928856_surprised_kitten.gif" style="border-radius:10px;"/></p>
31
+ <br/>
32
+ <p><button type="button" value ="back" onClick="window.history.back();" class='btn btn-primary'><i class="icon-chevron-left" style="opacity:.25"></i> Back to the app</button></p>
33
+ </div>
34
+
35
+ <footer>
36
+ <p>A VersaCommerce app by (company name here)</p>
37
+ </footer>
38
+ </div> <!-- /container -->
39
+ </body>
40
+ </html>
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>422 Error: Your change was rejected</title>
5
+
6
+ <style>
7
+ .container { text-align:center;}
8
+ .navbar .brand { float:none;}
9
+ </style>
10
+ </head>
11
+
12
+ <body>
13
+ <div class="navbar navbar-fixed-top">
14
+ <div class="navbar-inner">
15
+ <div class="container">
16
+ <a href="/" class="brand">VersaCommerce Demo App</a>
17
+ </div>
18
+ </div>
19
+ </div>
20
+
21
+ <div class="container">
22
+ <div class="content">
23
+
24
+ <div class="page-header">
25
+ <h1>422 Error</h1>
26
+ </div>
27
+
28
+ <h3><i class="icon-warning-sign" style="margin-top:6px; opacity:.5;"></i> Sorry, the change you requested was rejected.</h3>
29
+ <p class="muted">Did you try to change something you don't have access to?</p>
30
+
31
+ <p><button type="button" value ="back" onClick="window.history.back();" class='btn btn-primary'><i class="icon-chevron-left" style="opacity:.25"></i> Back to the app</button></p>
32
+
33
+ </div>
34
+
35
+ <footer>
36
+ <p>A VersaCommerce app by (company name here)</p>
37
+ </footer>
38
+ </div> <!-- /container -->
39
+ </body>
40
+ </html>
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>500 Error: Something went horribly wrong</title>
5
+
6
+ <style>
7
+ .container { text-align:center;}
8
+ .navbar .brand { float:none;}
9
+ </style>
10
+ </head>
11
+
12
+ <body>
13
+ <div class="navbar navbar-fixed-top">
14
+ <div class="navbar-inner">
15
+ <div class="container">
16
+ <a href="/" class="brand">VersaCommerce Demo App</a>
17
+ </div>
18
+ </div>
19
+ </div>
20
+
21
+ <div class="container">
22
+ <div class="content">
23
+
24
+ <div class="page-header">
25
+ <h1>AH! 500 Error!</h1>
26
+ </div>
27
+
28
+ <h3><i class="icon-warning-sign" style="margin-top:6px; opacity:.5;"></i> We're sorry, but something went wrong.</h3>
29
+ <p class="muted">The developer of this app has been notified.</p>
30
+
31
+ <p><button type="button" value ="back" onClick="window.history.back();" class='btn btn-primary'><i class="icon-chevron-left" style="opacity:.25"></i> Back to the app</button></p>
32
+
33
+ </div>
34
+
35
+ <footer>
36
+ <p>A VersaCommerce app by (company name here)</p>
37
+ </footer>
38
+ </div> <!-- /container -->
39
+ </body>
40
+ </html>
@@ -0,0 +1,65 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rails/generators'
3
+
4
+ class VersacommerceAppGenerator < Rails::Generators::Base
5
+ argument :api_key, :type => :string, :required => false
6
+ argument :secret, :type => :string, :required => false
7
+
8
+ class_option :skip_routes, :type => :boolean, :default => false, :desc => 'pass true to skip route generation'
9
+
10
+ def self.source_root
11
+ File.join(File.dirname(__FILE__), 'templates')
12
+ end
13
+
14
+ def copy_files
15
+ directory 'app'
16
+ directory 'public'
17
+ directory 'config'
18
+ end
19
+
20
+ def remove_static_index
21
+ remove_file 'public/index.html'
22
+ end
23
+
24
+ def add_config_variables
25
+ return if api_key.blank? || secret.blank?
26
+
27
+ append_file 'config/versacommerce_api.yml', <<-DATA
28
+ development:
29
+ api_key: #{api_key}
30
+ secret: #{secret}
31
+
32
+ test:
33
+ api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
34
+ secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
35
+
36
+ production:
37
+ api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
38
+ secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
39
+ DATA
40
+ end
41
+
42
+ def add_routes
43
+ unless options[:skip_routes]
44
+ route_without_newline "root :to => 'home#index'"
45
+ route "end"
46
+ route_without_newline " delete '/logout' => :destroy"
47
+ route_without_newline " post '/login' => :create"
48
+ route_without_newline " get '/login' => :new"
49
+ route_without_newline " get '/finalize' => :finalize"
50
+ route_without_newline "controller :sessions do"
51
+ end
52
+ end
53
+
54
+ def show_readme
55
+ `bundle install`
56
+ readme '../README'
57
+ end
58
+
59
+ private
60
+
61
+ def route_without_newline(routing_code)
62
+ sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
63
+ inject_into_file 'config/routes.rb', "\n #{routing_code}", { after: sentinel, verbose: false }
64
+ end
65
+ end
@@ -0,0 +1,47 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class VersacommerceApp::Configuration
3
+ VALID_KEYS = [:api_key, :secret]
4
+ attr_writer *VALID_KEYS
5
+
6
+ def initialize(params={})
7
+ self.params = default_params.merge(params)
8
+ end
9
+
10
+ VALID_KEYS.each do |meth|
11
+ define_method meth do
12
+ meth = meth.to_s
13
+ config_from_env(meth) || config_from_rails(meth) || config_from_file(meth) || ''
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_accessor :params
20
+
21
+ def config_from_env(meth)
22
+ ENV["VERSACOMMERCE_#{meth.upcase}"]
23
+ end
24
+
25
+ def config_from_rails(meth)
26
+ instance_variable_get("@#{meth}")
27
+ end
28
+
29
+ def config_from_file(meth)
30
+ @config_file ||= load_config
31
+ @config_file[Rails.env].try(:[], meth) || @config_file['common'].try(:[], meth)
32
+ end
33
+
34
+ def load_config
35
+ File.exist?(config_filepath) ? YAML.load_file(config_filepath) : {}
36
+ end
37
+
38
+ def config_filepath
39
+ params[:config_file]
40
+ end
41
+
42
+ def default_params
43
+ {
44
+ config_file: File.join(Rails.root, 'config', 'versacommerce_api.yml')
45
+ }
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module VersacommerceApp::EnsureApiSession
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ rescue_from ActiveResource::UnauthorizedAccess, :with => :close_session
7
+ end
8
+
9
+ def ensure_current_api_session
10
+ if session[:versacommerce]
11
+ begin
12
+ VersacommerceAPI::Base.activate_session(session[:versacommerce])
13
+ yield
14
+ ensure
15
+ VersacommerceAPI::Base.clear_session
16
+ end
17
+ else
18
+ session[:return_to] = request.fullpath if request.get?
19
+ redirect_to login_path(shop: params[:shop])
20
+ end
21
+ end
22
+
23
+ def current_shop
24
+ session[:versacommerce]
25
+ end
26
+
27
+ protected
28
+
29
+ def close_session
30
+ session[versacommerce] = nil
31
+ redirect_to login_path
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rails'
3
+
4
+ class VersacommerceApp::Railtie < ::Rails::Railtie
5
+
6
+ config.before_configuration do
7
+ config.versacommerce = VersacommerceApp.configuration
8
+ end
9
+
10
+ initializer "versacommerce_app.action_controller_integration" do
11
+ ActionController::Base.send :include, VersacommerceApp::EnsureApiSession
12
+ ActionController::Base.send :helper_method, :current_shop
13
+ end
14
+
15
+ initializer "versacommerce_app.setup_session" do
16
+ VersacommerceApp.setup_session
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module VersacommerceApp
3
+ VERSION = "1.0.17"
4
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'versacommerce_api'
3
+
4
+ module VersacommerceApp
5
+
6
+ def self.configuration
7
+ @configuration ||= VersacommerceApp::Configuration.new
8
+ end
9
+
10
+ def self.setup_session
11
+ VersacommerceAPI::Session.setup(:api_key => VersacommerceApp.configuration.api_key, :secret => VersacommerceApp.configuration.secret)
12
+ end
13
+ end
14
+
15
+ require 'versacommerce_app/ensure_api_session'
16
+ require 'versacommerce_app/configuration'
17
+ require 'versacommerce_app/railtie'
18
+ require 'versacommerce_app/version'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "versacommerce_app/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "versacommerce_app"
7
+ s.version = VersacommerceApp::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.author = "VersaCommerce"
10
+ s.email = ["support@versacommerce.de"]
11
+ s.homepage = "http://www.versacommerce.de"
12
+ s.summary = %q{This gem is used to get quickly started with the VersaCommerce API}
13
+ s.description = %q{This generator creates a basic sessions controller for authenticating with your Shop. Also a home controller which lets you access your shop easily.}
14
+
15
+ s.add_runtime_dependency('rails', '>= 3.1', '< 5.0')
16
+ s.add_runtime_dependency('versacommerce_api', '~> 1.0.2')
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versacommerce_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.17
5
+ platform: ruby
6
+ authors:
7
+ - VersaCommerce
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-03 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.1'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: versacommerce_api
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 1.0.2
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.2
47
+ description: This generator creates a basic sessions controller for authenticating
48
+ with your Shop. Also a home controller which lets you access your shop easily.
49
+ email:
50
+ - support@versacommerce.de
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - CHANGELOG
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - install.rb
62
+ - lib/generators/versacommerce_app/README
63
+ - lib/generators/versacommerce_app/USAGE
64
+ - lib/generators/versacommerce_app/templates/app/assets/images/favicon.png
65
+ - lib/generators/versacommerce_app/templates/app/assets/images/grid-18px.png
66
+ - lib/generators/versacommerce_app/templates/app/assets/images/versacommerce-100.png
67
+ - lib/generators/versacommerce_app/templates/app/assets/images/versacommerce-114.png
68
+ - lib/generators/versacommerce_app/templates/app/assets/images/versacommerce-57.png
69
+ - lib/generators/versacommerce_app/templates/app/assets/images/versacommerce-72.png
70
+ - lib/generators/versacommerce_app/templates/app/controllers/home_controller.rb
71
+ - lib/generators/versacommerce_app/templates/app/controllers/sessions_controller.rb
72
+ - lib/generators/versacommerce_app/templates/app/helpers/home_helper.rb
73
+ - lib/generators/versacommerce_app/templates/app/helpers/sessions_helper.rb
74
+ - lib/generators/versacommerce_app/templates/app/views/home/index.html.erb
75
+ - lib/generators/versacommerce_app/templates/app/views/layouts/application.html.erb
76
+ - lib/generators/versacommerce_app/templates/app/views/sessions/new.html.erb
77
+ - lib/generators/versacommerce_app/templates/config/versacommerce_api.yml
78
+ - lib/generators/versacommerce_app/templates/public/404.html
79
+ - lib/generators/versacommerce_app/templates/public/422.html
80
+ - lib/generators/versacommerce_app/templates/public/500.html
81
+ - lib/generators/versacommerce_app/templates/public/favicon.png
82
+ - lib/generators/versacommerce_app/templates/public/versacommerce-114.png
83
+ - lib/generators/versacommerce_app/templates/public/versacommerce-57.png
84
+ - lib/generators/versacommerce_app/templates/public/versacommerce-72.png
85
+ - lib/generators/versacommerce_app/versacommerce_app_generator.rb
86
+ - lib/versacommerce_app.rb
87
+ - lib/versacommerce_app/configuration.rb
88
+ - lib/versacommerce_app/ensure_api_session.rb
89
+ - lib/versacommerce_app/railtie.rb
90
+ - lib/versacommerce_app/version.rb
91
+ - versacommerce_app.gemspec
92
+ homepage: http://www.versacommerce.de
93
+ licenses: []
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: This gem is used to get quickly started with the VersaCommerce API
115
+ test_files: []