Sha256: 47146bb518a6c756cc78ed85c794ada8081f878619a093f4e2ed65670f198d3b

Contents?: true

Size: 1.58 KB

Versions: 7

Compression:

Stored size: 1.58 KB

Contents

# typed: strict
# frozen_string_literal: true

module ShopifyAPI
  module Auth
    class FileSessionStorage
      extend T::Sig
      extend T::Helpers
      include ShopifyAPI::Auth::SessionStorage

      sig { returns(String) }
      attr_accessor :path

      sig { params(path: String).void }
      def initialize(path: "/tmp/shopify_api_sessions")
        @path = path
        FileUtils.mkdir_p(path) unless Dir.exist?(path)
      end

      sig do
        override.params(session: Session)
          .returns(T::Boolean)
      end
      def store_session(session)
        File.write(session_file_path(session.id), session.serialize) > 0
      end

      sig do
        override.params(id: String)
          .returns(T.nilable(Session))
      end
      def load_session(id)
        session_path = session_file_path(id)
        if File.exist?(session_path)
          ShopifyAPI::Auth::Session.deserialize(File.read(session_path))
        end
      end

      sig do
        override.params(id: String)
          .returns(T::Boolean)
      end
      def delete_session(id)
        session_path = session_file_path(id)
        File.delete(session_path) if File.exist?(session_path)
        true
      end

      alias_method :eql?, :==
      sig { params(other: T.nilable(FileSessionStorage)).returns(T::Boolean) }
      def ==(other)
        if other
          @path == other.path
        else
          false
        end
      end

      private

      sig do
        params(id: String)
          .returns(String)
      end
      def session_file_path(id)
        "#{@path}/#{id}"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shopify_api-11.0.1 lib/shopify_api/auth/file_session_storage.rb
shopify_api-11.0.0 lib/shopify_api/auth/file_session_storage.rb
shopify_api-10.1.0 lib/shopify_api/auth/file_session_storage.rb
shopify_api-10.0.3 lib/shopify_api/auth/file_session_storage.rb
shopify_api-10.0.2 lib/shopify_api/auth/file_session_storage.rb
shopify_api-10.0.1 lib/shopify_api/auth/file_session_storage.rb
shopify_api-10.0.0 lib/shopify_api/auth/file_session_storage.rb