Sha256: b403b787ad75dbcd492892bcd35274af64492bc8e242760de9332f9e50bb09bd

Contents?: true

Size: 816 Bytes

Versions: 6

Compression:

Stored size: 816 Bytes

Contents

module SpiffyStoresApp
  module SessionStorage
    extend ActiveSupport::Concern

    included do
      validates :spiffy_stores_domain, presence: true, uniqueness: true
      validates :spiffy_stores_token, presence: true
    end

    def with_spiffy_stores_session(&block)
      SpiffyStoresAPI::Session.temp(spiffy_stores_domain, spiffy_stores_token, &block)
    end

    class_methods do
      def store(session)
        shop = self.find_or_initialize_by(spiffy_stores_domain: session.url)
        shop.spiffy_stores_token = session.token
        shop.save!
        shop.id
      end

      def retrieve(id)
        return unless id

        if shop = self.find_by(id: id)
          SpiffyStoresAPI::Session.new(shop.spiffy_stores_domain, shop.spiffy_stores_token, shop)
        end
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spiffy_stores_app-8.2.11 lib/spiffy_stores_app/session/session_storage.rb
spiffy_stores_app-8.2.10 lib/spiffy_stores_app/session/session_storage.rb
spiffy_stores_app-8.2.9 lib/spiffy_stores_app/session/session_storage.rb
spiffy_stores_app-8.2.8 lib/spiffy_stores_app/session/session_storage.rb
spiffy_stores_app-8.2.7 lib/spiffy_stores_app/session/session_storage.rb
spiffy_stores_app-8.2.6 lib/spiffy_stores_app/session/session_storage.rb