Sha256: de900fe091fc96f19f51d31aaef8f265e190bb3c856fc75c0bb54530faf89966

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module ShopifyApp
  module SessionStorage
    extend ActiveSupport::Concern

    included do
      validates :shopify_token, presence: true
      validates :api_version, presence: true
      validates :shopify_domain, presence: true,
        if: Proc.new {|_| ShopifyApp.configuration.per_user_tokens? }
      validates :shopify_domain, presence: true, uniqueness: { case_sensitive: false },
        if: Proc.new {|_| !ShopifyApp.configuration.per_user_tokens? }
    end

    def with_shopify_session(&block)
      ShopifyAPI::Session.temp(
        domain: shopify_domain,
        token: shopify_token,
        api_version: api_version,
        &block
      )
    end

    class_methods do

      def strategy_klass
        ShopifyApp.configuration.per_user_tokens? ? 
          ShopifyApp::SessionStorage::UserStorageStrategy : 
          ShopifyApp::SessionStorage::ShopStorageStrategy
      end

      def store(auth_session, user: nil)
        strategy_klass.store(auth_session, user)
      end

      def retrieve(id)
        strategy_klass.retrieve(id)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify_app-11.7.0 lib/shopify_app/session/session_storage.rb
shopify_app-11.5.0 lib/shopify_app/session/session_storage.rb