module Sinatra::Shopified::Helpers
Helper module for the Gem
Attributes
shop[R]
Instance variable for storing shop object
Public Instance Methods
current_shop()
click to toggle source
Grab the current shop from the database @return [Object, nil] the shop object
# File lib/sinatra/shopified/helpers.rb, line 10 def current_shop return nil if session[:shopify_domain] == nil @shop ||= Models::Shop.find_by(shop: session[:shopify_domain]) end
esdk_redirect(redirect_url)
click to toggle source
Forces a redirect to get out of the iFrame for embedded apps @param [String] redirect_url the URL to redirect to @return [String] the Javascript for redirecting @example
esdk_redirect '/admin/products'
# File lib/sinatra/shopified/helpers.rb, line 67 def esdk_redirect(redirect_url) "<script type='text/javascript'>top.window.location.href = '#{redirect_url}';</script>" end
shopify_session_activate()
click to toggle source
Activates Shopify session
# File lib/sinatra/shopified/helpers.rb, line 16 def shopify_session_activate api_session = ShopifyAPI::Session.new current_shop.shop, current_shop.token ShopifyAPI::Base.activate_session api_session end
shopify_session_clear()
click to toggle source
Clears all sessions
# File lib/sinatra/shopified/helpers.rb, line 22 def shopify_session_clear session[:shopify_domain] = nil ShopifyAPI::Base.clear_session end
shopify_session_with(shop, &block)
click to toggle source
Allowing using a temporary session for a shop @param [Object] shop the shop's object @example
shop = Shopify::Models::Shop.find(shop: 'coolshop.myshopify.com') shopify_session_with shop do ShopifyAPI::Product.find 42 end
# File lib/sinatra/shopified/helpers.rb, line 34 def shopify_session_with(shop, &block) ShopifyAPI::Session.temp shop.shop, shop.token, &block end