class EasyDrive::Client
Constants
- API_VERSION
- CACHED_API_FILE
- CREDENTIAL_STORE_FILE
Attributes
application_name[RW]
client[R]
drive[R]
Public Class Methods
new(options = {}) { |self| ... }
click to toggle source
Initializes a new Client
object
@param options [Hash] @return [EasyDrive::Client]
# File lib/easy_drive/client.rb, line 24 def initialize(options = {}) options.each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end
Public Instance Methods
file_format_bug_fix(credential_store_file)
click to toggle source
@note refresh_token bug fix @see github.com/google/google-api-ruby-client/issues/90
# File lib/easy_drive/client.rb, line 33 def file_format_bug_fix(credential_store_file) return if !File.exists?(credential_store_file) temp = nil File.open(credential_store_file, "r") do |f| temp = JSON.load(f) if temp["authorization_uri"].class != String temp["authorization_uri"] = "https://accounts.google.com/o/oauth2/auth" end if temp["token_credential_uri"].class != String temp["token_credential_uri"] = "https://accounts.google.com/o/oauth2/token" end end File.open(credential_store_file, "w") do |f| f.write(temp.to_json) end end
setup()
click to toggle source
# File lib/easy_drive/client.rb, line 52 def setup() client = Google::APIClient.new(:application_name => self.class.to_s, :application_version => version) file_storage = Google::APIClient::FileStorage.new(CREDENTIAL_STORE_FILE) if file_storage.authorization.nil? client_secrets = Google::APIClient::ClientSecrets.load flow = Google::APIClient::InstalledAppFlow.new( :client_id => client_secrets.client_id, :client_secret => client_secrets.client_secret, :scope => ['https://www.googleapis.com/auth/drive'] ) client.authorization = flow.authorize(file_storage) else client.authorization = file_storage.authorization end drive = nil if File.exists? CACHED_API_FILE File.open(CACHED_API_FILE) do |file| drive = Marshal.load(file) end else drive = client.discovered_api('drive', API_VERSION) File.open(CACHED_API_FILE, 'w') do |file| Marshal.dump(drive, file) end end @client = client @drive = drive return client, drive end
version()
click to toggle source
@return [String]
# File lib/easy_drive/client.rb, line 88 def version "#{EasyDrive::Version}" end