Class: EasyDrive::Client
- Inherits:
-
Object
- Object
- EasyDrive::Client
- Includes:
- Files
- Defined in:
- lib/easy_drive/client.rb
Constant Summary collapse
- API_VERSION =
'v2'- CACHED_API_FILE =
"easy_drive-#{API_VERSION}.cache"- CREDENTIAL_STORE_FILE =
"easy_drive-oauth2.json"
Instance Attribute Summary collapse
-
#application_name ⇒ Object
Returns the value of attribute application_name.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#drive ⇒ Object
readonly
Returns the value of attribute drive.
Instance Method Summary collapse
- #file_format_bug_fix(credential_store_file) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ EasyDrive::Client
constructor
Initializes a new Client object.
- #setup ⇒ Object
- #version ⇒ String
Methods included from Files
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ EasyDrive::Client
Initializes a new Client object
19 20 21 22 23 24 |
# File 'lib/easy_drive/client.rb', line 19 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end |
Instance Attribute Details
#application_name ⇒ Object
Returns the value of attribute application_name.
12 13 14 |
# File 'lib/easy_drive/client.rb', line 12 def application_name @application_name end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
13 14 15 |
# File 'lib/easy_drive/client.rb', line 13 def client @client end |
#drive ⇒ Object (readonly)
Returns the value of attribute drive.
13 14 15 |
# File 'lib/easy_drive/client.rb', line 13 def drive @drive end |
Instance Method Details
#file_format_bug_fix(credential_store_file) ⇒ Object
Note:
refresh_token bug fix
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/easy_drive/client.rb', line 28 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 ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/easy_drive/client.rb', line 47 def setup() client = Google::APIClient.new(:application_name => @application_name, :application_version => '1.0.0') file_storage = Google::APIClient::FileStorage.new(CREDENTIAL_STORE_FILE) if file_storage..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. = flow.(file_storage) else client. = file_storage. 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 ⇒ String
83 84 85 |
# File 'lib/easy_drive/client.rb', line 83 def version "#{Twitter::Version}" end |