Sha256: 7cdeb5a1996357691412f60344509f9feb11b17014ed0f5c4b42ec77cf6ba931

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

module CandyCheck
  module PlayStore
    # A file-based repository to cache a local copy of the Google API
    # discovery as suggested by Google.
    # @see https://github.com/google/google-api-ruby-client
    class DiscoveryRepository
      # Create a new instance bound to a single file path
      # @param file_path [String] to save and load the cached copy
      def initialize(file_path)
        @file_path = file_path
      end

      # Tries to load a cached copy of the discovery API. Me be nil if
      # no cached version is available
      # @return [Google::APIClient::API]
      def load
        return unless @file_path && File.exist?(@file_path)
        File.open(@file_path, 'rb') do |file|
          return Marshal.load(file)
        end
      end

      # Tries to save a local copy of the discovery API.
      # @param discovery [Google::APIClient::API]
      def save(discovery)
        return unless @file_path && discovery
        File.open(@file_path, 'wb') do |file|
          Marshal.dump(discovery, file)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
candy_check-0.1.2 lib/candy_check/play_store/discovery_repository.rb
candy_check-0.1.1 lib/candy_check/play_store/discovery_repository.rb
candy_check-0.1.0.pre lib/candy_check/play_store/discovery_repository.rb
candy_check-0.0.5 lib/candy_check/play_store/discovery_repository.rb
candy_check-0.0.3 lib/candy_check/play_store/discovery_repository.rb
candy_check-0.0.2 lib/candy_check/play_store/discovery_repository.rb
candy_check-0.0.1 lib/candy_check/play_store/discovery_repository.rb