class Rb1drv::OneDriveItem
Attributes
ctime[R]
cuser[R]
eTag[R]
id[R]
mtime[R]
muser[R]
name[R]
parent_path[R]
remote_drive_id[R]
remote_id[R]
size[R]
Public Class Methods
new(od, api_hash)
click to toggle source
# File lib/rb1drv/onedrive_item.rb, line 5 def initialize(od, api_hash) @od = od %w(id name eTag size).each do |key| instance_variable_set("@#{key}", api_hash[key]) end @remote_drive_id = api_hash.dig('remoteItem', 'parentReference', 'driveId') @remote_id = api_hash.dig('remoteItem', 'id') @mtime = Time.iso8601(api_hash.dig('lastModifiedDateTime')) @ctime = Time.iso8601(api_hash.dig('createdDateTime')) @muser = api_hash.dig('lastModifiedBy', 'user', 'displayName') || 'N/A' @cuser = api_hash.dig('createdBy', 'user', 'displayName') || 'N/A' @parent_path = api_hash.dig('parentReference', 'path') @remote = api_hash.has_key?('remoteItem') end
Protected Class Methods
smart_new(od, item_hash)
click to toggle source
Create subclass instance by checking the item type
@return [OneDriveFile, OneDriveDir] instanciated drive item
# File lib/rb1drv/onedrive_item.rb, line 23 def self.smart_new(od, item_hash) if item_hash['remoteItem'] item_hash['remoteItem'].each do |key, value| item_hash[key] ||= value end end if item_hash['file'] OneDriveFile.new(od, item_hash) elsif item_hash['folder'] OneDriveDir.new(od, item_hash) elsif item_hash.dig('error', 'code') == 'itemNotFound' OneDrive404.new else item_hash end end
Protected Instance Methods
absolute_path()
click to toggle source
@return [String] absolute path of current item
# File lib/rb1drv/onedrive_item.rb, line 41 def absolute_path if @parent_path File.join(@parent_path, @name) else @name end end
api_path()
click to toggle source
TODO: API endpoint does not play well with remote files
@return [String] api reference path of current object
# File lib/rb1drv/onedrive_item.rb, line 52 def api_path if remote? "drives/#{@remote_drive_id}/items/#{@remote_id}" else "drive/items/#{@id}" end end
remote?()
click to toggle source
TODO: API endpoint does not play well with remote files
@return [Boolean] whether it's shared by others
# File lib/rb1drv/onedrive_item.rb, line 63 def remote? @remote end