Sha256: d85735c7b9bba92dca76c0ce807fa9580960d2d81315cc8decad795ada86a485

Contents?: true

Size: 1.59 KB

Versions: 194

Compression:

Stored size: 1.59 KB

Contents

# Copyright 2013 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'json'

module Google
  class APIClient
    ##
    # Represents cached OAuth 2 tokens stored on local disk in a
    # JSON serialized file. Meant to resemble the serialized format
    # http://google-api-python-client.googlecode.com/hg/docs/epy/oauth2client.file.Storage-class.html
    #
    # @deprecated Use google-auth-library-ruby instead
    class FileStore

      attr_accessor :path

      ##
      # Initializes the FileStorage object.
      #
      # @param [String] path
      #    Path to the credentials file.
      def initialize(path)
        @path= path
      end

      ##
      # Attempt to read in credentials from the specified file.
      def load_credentials
        open(path, 'r') { |f| JSON.parse(f.read) }
      rescue
        nil
      end

      ##
      # Write the credentials to the specified file.
      #
      # @param [Hash] credentials_hash
      def write_credentials(credentials_hash)
        open(self.path, 'w+') do |f|
          f.write(credentials_hash.to_json)
        end
      end
    end
  end
end

Version data entries

194 entries across 194 versions & 4 rubygems

Version Path
google-apis-core-0.7.0 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.6.0 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.5.0 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.4.2 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.4.1 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.4.0 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.3.0 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.2.1 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.2.0 lib/google/api_client/auth/storages/file_store.rb
google-apis-core-0.1.0 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.52.0 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.51.0 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.50.0 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.49.0 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.48.0 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.47.0 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.46.2 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.46.1 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.46.0 lib/google/api_client/auth/storages/file_store.rb
google-api-client-0.45.1 lib/google/api_client/auth/storages/file_store.rb