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 esdk initializer.
- #shopify_session(&blk) ⇒ Object
- #shopify_webhook {|shop_name, webhook_body| ... } ⇒ Object
Instance Method Details
#after_shopify_auth ⇒ Object
designed to be overriden
16 17 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 16 def after_shopify_auth end |
#logout ⇒ Object
19 20 21 22 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 19 def logout session.delete(:shopify) session.clear end |
#shop_origin ⇒ Object
for the esdk initializer
25 26 27 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 25 def shop_origin "https://#{session[:shopify][:shop]}" end |
#shopify_session(&blk) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 29 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
49 50 51 52 53 54 55 |
# File 'lib/sinatra/shopify-sinatra-app.rb', line 49 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 |