shopqi-app 0.1.0 → 0.1.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.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # ShopQi App Engine
2
+
3
+ 集成访问 ShopQi API 的功能,支持以 ShopQi 用户身份登录
4
+
5
+ ## 安装
6
+
7
+ $ echo "gem 'shopqi-app'" >> Gemfile
8
+ $ bundle
9
+
10
+ ## 使用
11
+
12
+ $ rails g shopqi_app client_id client_secret
13
+
14
+ `client_id`, `client_secret` 在注册 Application 后显示,注册时 `REDIRECT URI` 填写 localhost:3000/app/callback
15
+
16
+ ## 配置
17
+
18
+ 如需修改 scope, 请打开 `config/app_secret_config.yml`
19
+
20
+ defaults: &defaults
21
+ oauth:
22
+ client_id: 'dffd069fa92096022628a1f7eb174bc85d90278b8c90ec7ebadfbd94924bd2b8'
23
+ secret: 'e1805141c81c496e4779371f41263c9f74ac2ffd3728302296b8af10b64d9c9b'
24
+ scope: 'read_products read_orders'
25
+ redirect_uri: 'http://localhost:3000/app/callback'
26
+
27
+ ## 最后
28
+
29
+ 启动应用服务
30
+
31
+ $ rails s
32
+
33
+ 访问 [http://localhost:3000](http://localhost:3000)
@@ -2,5 +2,6 @@ module ShopqiApp
2
2
  class ApplicationController < ActionController::Base
3
3
  include ApplicationHelper
4
4
  protect_from_forgery
5
+ layout 'application' # 使用 main_app 的 layout
5
6
  end
6
7
  end
@@ -4,5 +4,5 @@
4
4
  安装应用
5
5
  %small 请输入商店 URL 地址
6
6
  = form_tag login_path, :class => 'form-search' do
7
- = text_field_tag 'shop', nil, :placeholder => '商品 URL 地址', :class => 'btn-large', :id => 'shop'
7
+ = text_field_tag 'shop', nil, :placeholder => '商店 URL 地址', :class => 'btn-large', :id => 'shop'
8
8
  = submit_tag '安装', :class => 'btn btn-primary btn-large'
@@ -1,8 +1,8 @@
1
1
  Rails.application.config.middleware.use OmniAuth::Builder do
2
2
  provider :shopqi,
3
- SecretSetting.oauth.client_id,
4
- SecretSetting.oauth.secret,
5
- :scope => SecretSetting.oauth.scope,
3
+ (SecretSetting.oauth.client_id rescue nil), # 调用 generator 时还没有 app_secret_config.yml 文件
4
+ (SecretSetting.oauth.secret rescue nil),
5
+ :scope => (SecretSetting.oauth.scope rescue nil),
6
6
  :callback_path => '/app/callback',
7
7
  :setup => lambda {|env|
8
8
  params = Rack::Utils.parse_query(env['QUERY_STRING'])
@@ -0,0 +1,20 @@
1
+ Description:
2
+ Generator ShopQi API files.
3
+
4
+ Example:
5
+ rails generate shopqi_app client_id client_secret
6
+
7
+ This will remove:
8
+ app/assets/javascripts/application.js
9
+ app/assets/stylesheets/application_helpern.css
10
+ app/views/layouts/application.html.erb
11
+ public/index.html
12
+
13
+ This will create:
14
+ app/assets/javascripts/application.js.coffee
15
+ app/assets/stylesheets/application_helpernon.css.less.erb
16
+ app/controllers/home_controller.rb
17
+ app/helpers/home_helper.rb
18
+ app/views/home/
19
+ app/views/layouts/application.html.haml
20
+ config/app_secret_config.yml
@@ -0,0 +1,27 @@
1
+ class ShopqiAppGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ argument :client_id , type: :string, required: true
5
+ argument :client_secret, type: :string, required: true
6
+
7
+ def copy_files
8
+ directory 'app'
9
+ template 'config/app_secret_config.yml.erb', 'config/app_secret_config.yml'
10
+ end
11
+
12
+ def remove_files
13
+ remove_file 'public/index.html'
14
+ remove_file 'app/assets/javascripts/application.js'
15
+ remove_file 'app/assets/stylesheets/application.css'
16
+ remove_file 'app/views/layouts/application.html.erb'
17
+ end
18
+
19
+ def add_routes
20
+ route "mount ShopqiApp::Engine => '/app'"
21
+ route "root :to => 'home#index'"
22
+ end
23
+
24
+ def show
25
+ readme "README"
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ ===============================================================================
2
+
3
+ There is something that you need to do before you use shopqi-app.
4
+
5
+ Step 0.
6
+ If you DO NOT use database, you MUST comment the line below in config/application.rb
7
+ # require "active_record/railtie"
8
+
9
+ Step 1.
10
+ $ rails server
11
+
12
+ ===============================================================================
@@ -0,0 +1,18 @@
1
+ #= require jquery
2
+ #= require jquery_ujs
3
+ #= require_tree .
4
+
5
+ #= require twitter/bootstrap/dropdown.js
6
+ # accordion 依赖
7
+ #= require twitter/bootstrap/transition.js
8
+ #= require twitter/bootstrap/collapse.js
9
+ ###
10
+ #= require twitter/bootstrap/tooltip.js
11
+ ###
12
+
13
+ $(document).ready ->
14
+ $('#shop').focus()
15
+
16
+ ###
17
+ #$('#main').tooltip selector: "span[rel=tooltip], a[rel=tooltip]"
18
+ ###
@@ -18,19 +18,19 @@
18
18
  @import "twitter/bootstrap/type.less";
19
19
  //@import "twitter/bootstrap/code.less";
20
20
  @import "twitter/bootstrap/forms.less";
21
- //@import "twitter/bootstrap/tables.less";
21
+ @import "twitter/bootstrap/tables.less";
22
22
 
23
23
  // Components: common
24
24
  @import "twitter/bootstrap/sprites.less";
25
25
  @import "twitter/bootstrap/dropdowns.less";
26
26
  @import "twitter/bootstrap/wells.less";
27
- //@import "twitter/bootstrap/component-animations.less";
27
+ @import "twitter/bootstrap/component-animations.less";
28
28
  //@import "twitter/bootstrap/close.less";
29
29
 
30
30
  // Components: Buttons & Alerts
31
31
  @import "twitter/bootstrap/buttons.less";
32
32
  //@import "twitter/bootstrap/button-groups.less";
33
- //@import "twitter/bootstrap/alerts.less"; // Note: alerts share common CSS with buttons and thus have styles in buttons.less
33
+ @import "twitter/bootstrap/alerts.less"; // Note: alerts share common CSS with buttons and thus have styles in buttons.less
34
34
 
35
35
  // Components: Nav
36
36
  @import "twitter/bootstrap/navs.less";
@@ -41,14 +41,14 @@
41
41
 
42
42
  // Components: Popovers
43
43
  //@import "twitter/bootstrap/modals.less";
44
- //@import "twitter/bootstrap/tooltip.less";
44
+ @import "twitter/bootstrap/tooltip.less";
45
45
  //@import "twitter/bootstrap/popovers.less";
46
46
 
47
47
  // Components: Misc
48
48
  //@import "twitter/bootstrap/thumbnails.less";
49
49
  @import "twitter/bootstrap/labels-badges.less";
50
50
  //@import "twitter/bootstrap/progress-bars.less";
51
- //@import "twitter/bootstrap/accordion.less";
51
+ @import "twitter/bootstrap/accordion.less";
52
52
  //@import "twitter/bootstrap/carousel.less";
53
53
  @import "twitter/bootstrap/hero-unit.less";
54
54
 
@@ -58,3 +58,8 @@
58
58
  body {
59
59
  margin-top: 50px;
60
60
  margin-bottom: 100px; }
61
+
62
+ .accordion-body {
63
+ background: #F9F9F9;
64
+ .accordion-inner {
65
+ padding: 20px; }}
@@ -0,0 +1,6 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ helper ShopqiApp::ApplicationHelper
4
+ include ShopqiApp::ApplicationHelper
5
+ prepend_before_filter :authenticate_shop!
6
+ end
@@ -0,0 +1,13 @@
1
+ class HomeController < ApplicationController
2
+ skip_before_filter :authenticate_shop!, only: :index
3
+
4
+ def index
5
+ if signed_in?
6
+ Shopkit.setup url: session[:shopqi][:url], access_token: session[:shopqi][:access_token] # set in shopqi-app sessions controller
7
+ @orders = Shopkit.orders per_page: 3
8
+ @products = Shopkit.products per_page: 5
9
+ else
10
+ redirect_to shopqi_app.login_path
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module HomeHelper
2
+
3
+ def financial_class(financial_status)
4
+ case financial_status
5
+ when 'pending' then 'label-warning'
6
+ when 'paid' then 'label-success'
7
+ end
8
+ end
9
+
10
+ def fulfillment_class(fulfillment_status)
11
+ case fulfillment_status
12
+ when 'partial' then 'label-warning'
13
+ when 'fulfilled' then 'label-success'
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,37 @@
1
+ .content
2
+ %h2 最近订单
3
+ %table.table.table-striped
4
+ %thead
5
+ %tr
6
+ %th 订单号
7
+ %th 顾客
8
+ %th 支付状态
9
+ %th 发货状态
10
+ %th 总金额
11
+ %tbody
12
+ -@orders.each do |order|
13
+ %tr
14
+ %td=link_to order['name'], "#{shop_url}/admin/orders/#{order['id']}", target: :_blank
15
+ %td=order['customer']['name']
16
+ %td
17
+ %span.label(class="#{financial_class(order['financial_status'])}")
18
+ =order['financial_status_name']
19
+ %td
20
+ %span.label(class="#{fulfillment_class(order['fulfillment_status'])}")
21
+ =order['fulfillment_status_name']
22
+ %td=order['total_price']
23
+
24
+ %h2 商品信息
25
+ #product-accordion.accordion
26
+ -@products.each do |product|
27
+ .accordion-group
28
+ .accordion-heading
29
+ %a.accordion-toggle{href: "#product-#{product['id']}", data: {toggle: 'collapse', parent: '#product-accordion'}}
30
+ =product['title']
31
+ %div.accordion-body.collapse(id="product-#{product['id']}")
32
+ .accordion-inner
33
+ %p==类型: #{product['product_type']}
34
+ %p==生产商: #{product['vendor']}
35
+ =raw product['body_html']
36
+ %br/
37
+ %p=link_to "前往 ShopQi 后台管理查看", "#{shop_url}/admin/products/#{product['id']}", class: 'btn btn-primary', target: :_blank
@@ -27,7 +27,7 @@
27
27
  商店后台
28
28
  %li.divider
29
29
  %li
30
- =link_to sign_out_path do
30
+ =link_to shopqi_app.sign_out_path do
31
31
  %i.icon-off
32
32
  退出
33
33
 
@@ -0,0 +1,20 @@
1
+ defaults: &defaults
2
+ oauth:
3
+ client_id: <%= client_id %>
4
+ secret: <%= client_secret %>
5
+ scope: 'read_products read_orders'
6
+ redirect_uri: 'http://localhost:3000/app/callback'
7
+
8
+ development:
9
+ <<: *defaults
10
+
11
+ test:
12
+ <<: *defaults
13
+
14
+ production:
15
+ <<: *defaults
16
+ oauth:
17
+ client_id: <%= client_id %>
18
+ client_secret: <%= client_secret %>
19
+ scope: 'read_products read_orders'
20
+ redirect_uri: 'http://localhost:3000/app/callback'
data/lib/shopqi-app.rb CHANGED
@@ -7,4 +7,5 @@ require 'omniauth-shopqi'
7
7
  require 'shopkit'
8
8
 
9
9
  module ShopqiApp
10
+ autoload :Helpers, "shopqi_app/helpers"
10
11
  end
@@ -8,5 +8,12 @@ module ShopqiApp
8
8
  g.integration_tool :rspec
9
9
  end
10
10
 
11
+
12
+ initializer "shopqi_app.helpers" do
13
+ ActiveSupport.on_load(:action_controller) do
14
+ include ShopqiApp::Helpers
15
+ end
16
+ end
11
17
  end
18
+
12
19
  end
@@ -0,0 +1,8 @@
1
+ module ShopqiApp
2
+ module Helpers
3
+ def self.included(base)
4
+ base.send :helper, ShopqiApp::ApplicationHelper
5
+ base.send :include, ShopqiApp::ApplicationHelper
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module ShopqiApp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopqi-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-02 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -150,19 +150,28 @@ files:
150
150
  - app/controllers/shopqi_app/application_controller.rb
151
151
  - app/controllers/shopqi_app/sessions_controller.rb
152
152
  - app/models/secret_setting.rb
153
- - app/assets/javascripts/shopqi_app/application.js.coffee
154
- - app/assets/stylesheets/shopqi_app/application.css.less.erb
155
153
  - app/views/shopqi_app/sessions/new.html.haml
156
- - app/views/layouts/shopqi_app/application.html.haml
157
154
  - config/initializers/omniauth.rb
158
155
  - config/routes.rb
156
+ - lib/generators/shopqi_app/templates/app/helpers/home_helper.rb
157
+ - lib/generators/shopqi_app/templates/app/controllers/application_controller.rb
158
+ - lib/generators/shopqi_app/templates/app/controllers/home_controller.rb
159
+ - lib/generators/shopqi_app/templates/app/assets/javascripts/application.js.coffee
160
+ - lib/generators/shopqi_app/templates/app/assets/stylesheets/application.css.less.erb
161
+ - lib/generators/shopqi_app/templates/app/views/layouts/application.html.haml
162
+ - lib/generators/shopqi_app/templates/app/views/home/index.html.haml
163
+ - lib/generators/shopqi_app/templates/config/app_secret_config.yml.erb
164
+ - lib/generators/shopqi_app/templates/README
165
+ - lib/generators/shopqi_app/USAGE
166
+ - lib/generators/shopqi_app/shopqi_app_generator.rb
159
167
  - lib/shopqi-app.rb
160
168
  - lib/shopqi_app/version.rb
161
169
  - lib/shopqi_app/engine.rb
170
+ - lib/shopqi_app/helpers.rb
162
171
  - lib/tasks/shopqi_app_tasks.rake
163
172
  - MIT-LICENSE
164
173
  - Rakefile
165
- - README.rdoc
174
+ - README.md
166
175
  homepage: https://github.com/saberma/shopqi-app
167
176
  licenses: []
168
177
  post_install_message:
@@ -177,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
186
  version: '0'
178
187
  segments:
179
188
  - 0
180
- hash: -618896387
189
+ hash: 850028705
181
190
  required_rubygems_version: !ruby/object:Gem::Requirement
182
191
  none: false
183
192
  requirements:
@@ -186,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
195
  version: '0'
187
196
  segments:
188
197
  - 0
189
- hash: -618896387
198
+ hash: 850028705
190
199
  requirements: []
191
200
  rubyforge_project:
192
201
  rubygems_version: 1.8.24
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = ShopqiApp
2
-
3
- This project rocks and uses MIT-LICENSE.
@@ -1,9 +0,0 @@
1
- #= require jquery
2
- #= require jquery_ujs
3
- #= require_tree .
4
-
5
- #= require twitter/bootstrap/dropdown.js
6
-
7
- $(document).ready ->
8
- $('#shop').focus()
9
- $('.dropdown-toggle').dropdown()