Module: Sinatra::Shopify::Methods
- Defined in:
- lib/sinatra/shopify-sinatra-app.rb
Instance Method Summary collapse
-
#after_shopify_auth ⇒ Object
designed to be overriden.
- #logout ⇒ Object
-
#shop_origin ⇒ Object
for the app bridge initializer.
- #shopify_session(&blk) ⇒ Object
- #shopify_webhook {|shop_name, webhook_body| ... } ⇒ Object
Instance Method Details
#after_shopify_auth ⇒ Object
designed to be overriden
15 16 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 15 def after_shopify_auth end |
#logout ⇒ Object
18 19 20 21 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 18 def logout session.delete(:shopify) session.clear end |
#shop_origin ⇒ Object
for the app bridge initializer
24 25 26 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 24 def shop_origin "#{session[:shopify][:shop]}" end |
#shopify_session(&blk) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 28 def shopify_session(&blk) return_to = request.path return_params = request.params if no_session? authenticate(return_to, return_params) elsif different_shop? logout authenticate(return_to, return_params) else shop_name = session[:shopify][:shop] token = session[:shopify][:token] activate_shopify_api(shop_name, token) yield shop_name end rescue ActiveResource:: clear_session shop_name redirect request.path end |
#shopify_webhook {|shop_name, webhook_body| ... } ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 48 def shopify_webhook(&blk) return unless verify_shopify_webhook shop_name = request.env['HTTP_X_SHOPIFY_SHOP_DOMAIN'] webhook_body = ActiveSupport::JSON.decode(request.body.read.to_s) yield shop_name, webhook_body status 200 end |