class OneDrive::V1
Attributes
client_id[RW]
code[RW]
current_drive[RW]
current_item[RW]
drives[RW]
expires_in[RW]
item[RW]
items[RW]
my_drive[RW]
recent_drive[RW]
redirect_uri[RW]
scope[RW]
special_drive[RW]
special_items[RW]
token[RW]
token_type[RW]
Public Class Methods
new(client_id,redirect_uri,scope='files.read')
click to toggle source
# File lib/one_drive.rb, line 16 def initialize(client_id,redirect_uri,scope='files.read') @client_id = client_id @scope = scope @redirect_uri = redirect_uri end
Public Instance Methods
base_api_url()
click to toggle source
# File lib/one_drive.rb, line 21 def base_api_url "https://graph.microsoft.com/v1.0" end
code_url()
click to toggle source
# File lib/one_drive.rb, line 30 def code_url # Get code # https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&scope={scope} # &response_type=code&redirect_uri={redirect_uri} "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=#{@client_id}&scope=#{@scope}&response_type=code&redirect_uri=#{@redirect_uri}" #Get a new access token or refresh token # POST https://login.microsoftonline.com/common/oauth2/v2.0/token # Content-Type: application/x-www-form-urlencoded # # client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret} # &refresh_token={refresh_token}&grant_type=refresh_token end
download(options ={})
click to toggle source
# File lib/one_drive.rb, line 163 def download options ={} # Download # GET /drives/{drive-id}/items/{item-id}/content # GET /groups/{group-id}/drive/items/{item-id}/content # GET /me/drive/root:/{item-path}:/content # GET /me/drive/items/{item-id}/content # GET /sites/{siteId}/drive/items/{item-id}/content # GET /users/{userId}/drive/items/{item-id}/content # GET /drive/items/{item-id}/content?format={format} # GET /drive/root:/{path and filename}:/content?format={format} url = "https://graph.microsoft.com/v1.0" if options.include? :drive_id url = url + "/drives/#{options[:drive_id]}/" elsif options.include? :group_id url = url + "/groups/#{options[:group_id]}/drive/" elsif options.include? :site_id url = url + "/sites/#{options[:site_id]}/drive/" elsif options.include? :user_id url = url + "/users/#{options[:user_id]}/drive/" else url = url + "/me/drive/" end if options.include? :item_id url = url + "items/#{options[:item_id]}/content" elsif options.include? :item_path url = url + "root:/#{options[:item_path]}:/content" else return "OneDrive URL : Item id is not valid" end if options.include? :format url = url + "?format=#{options[:format]}" end @item = (HTTParty.get(url,headers: set_headers).body) end
get_children_of_special_folder(name)
click to toggle source
Get children of a special folder
# File lib/one_drive.rb, line 69 def get_children_of_special_folder name url = base_api_url + "/me/drive/special/#{name}/children" @special_items = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
get_drive(drive_id)
click to toggle source
Get a drive by ID
# File lib/one_drive.rb, line 44 def get_drive drive_id url = base_api_url + "/drives/#{drive_id}" @drives = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
get_drives(type = nil,id=nil)
click to toggle source
# File lib/one_drive.rb, line 84 def get_drives type = nil,id=nil # GET /me/drives # GET /users/{userId}/drives # GET /sites/{siteId}/drives # GET /groups/{groupId}/drives case type when 'users' url = "https://graph.microsoft.com/v1.0/users/#{id}/drives" when 'sites' url = "https://graph.microsoft.com/v1.0/sites/#{id}/drives" when 'groups' url = "https://graph.microsoft.com/v1.0/groups/#{id}/drives" else url = "https://graph.microsoft.com/v1.0/me/drives" end @drives = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
get_item(options={})
click to toggle source
# File lib/one_drive.rb, line 111 def get_item options={} url = "https://graph.microsoft.com/v1.0" # Get item # GET /drives/{drive-id}/items/{item-id} # GET /drives/{drive-id}/root:/{item-path} # GET /groups/{group-id}/drive/items/{item-id} # GET /groups/{group-id}/drive/root:/{item-path} # GET /me/drive/items/{item-id} # GET /me/drive/root:/{item-path} # GET /sites/{siteId}/drive/items/{itemId} # GET /sites/{siteId}/drive/root:/{item-path} # GET /users/{userId}/drive/items/{itemId} # GET /users/{userId}/drive/root:/{item-path} if options.include? :drive_id url = "/drives/#{options[:drive_id]}/" elsif options.include? :group_id url = "/groups/#{options[:group_id]}/" elsif options.include? :site_id url = "/sites/#{options[:site_id]}/" elsif options.include? :user_id url = "/users/#{options[:user_id]}/" else url = "/me/drive/" end if options.include? :item_id url = url + "items/#{options[:item_id]}" elsif options.include? :item_path url = url + "root:/#{options[:item_path]}" else return "OneDrive URL is not valid" end @items = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
get_library_for_site(site_id)
click to toggle source
Get the document library for a site
# File lib/one_drive.rb, line 59 def get_library_for_site site_id url = base_api_url + "/sites/#{site_id}/drive" @drives = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
get_list(options={})
click to toggle source
# File lib/one_drive.rb, line 197 def get_list options={} url = "https://graph.microsoft.com/v1.0" p '------------------------' # Find Children # GET /drives/{drive-id}/items/{item-id}/children # GET /groups/{group-id}/drive/items/{item-id}/children # GET /me/drive/items/{item-id}/children # GET /sites/{site-id}/drive/items/{item-id}/children # GET /users/{user-id}/drive/items/{item-id}/children if options.include? :drive_id url = url + "/drives/#{options[:drive_id]}/" elsif options.include? :group_id url = url + "/groups/#{options[:group_id]}/" elsif options.include? :site_id url = url + "/sites/#{options[:site_id]}/" elsif options.include? :user_id url = url + "/users/#{options[:user_id]}/" else url = url + "/me/drive/" end if options.include? :item_id url = url + "items/#{options[:item_id]}/children" else return "OneDrive URL : Item id is not valid" end p url @items = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
get_my_drive()
click to toggle source
Get a current user's OneDrive
# File lib/one_drive.rb, line 54 def get_my_drive url = base_api_url + "/me/drive" @my_drive = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
get_special_folder_by_name(name)
click to toggle source
Get a special folder by name
# File lib/one_drive.rb, line 64 def get_special_folder_by_name name url = base_api_url + "/me/drive/special/#{name}" @special_drive = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
get_users_drive(id_or_user_principal_name)
click to toggle source
Get a user's OneDrive
# File lib/one_drive.rb, line 49 def get_users_drive id_or_user_principal_name url = base_api_url + "/users/#{id_or_user_principal_name}/drive" @drives = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
recent()
click to toggle source
GET /drives/{remoteItem-driveId}/items/{remoteItem-id}
# File lib/one_drive.rb, line 80 def recent url = base_api_url + '/me/drive/recent' @recent_drive = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
search(options ={})
click to toggle source
# File lib/one_drive.rb, line 144 def search options ={} if options.include? :drive_id # GET /drives/{drive-id}/root/search(q='{search-text}') url = base_api_url + "/drives/#{options[:drive_id]}/root/search(q='#{options[:search_text]}')" elsif options.include? :group_id # GET /groups/{group-id}/drive/root/search(q='{search-text}') url = base_api_url + "/groups/#{options[:group_id]}/drive/root/search(q='#{options[:search_text]}')" elsif options.include? :site_id # GET /sites/{site-id}/drive/root/search(q='{search-text}') url = base_api_url + "/sites/#{options[:site_id]}/drive/root/search(q='#{options[:search_text]}')" elsif options.include? :user_id # GET /users/{user-id}/drive/root/search(q='{search-text}') url = base_api_url + "/users/#{options[:user_id]}/drive/root/search(q='#{options[:search_text]}')" else # GET /me/drive/root/search(q='{search-text}') url = base_api_url + "/me/drive/root/search(q='#{options[:search_text]}')" end @items = JSON.parse(HTTParty.get(url,headers: set_headers).body) end
set_code(code)
click to toggle source
# File lib/one_drive.rb, line 108 def set_code code @code = code end
set_headers()
click to toggle source
# File lib/one_drive.rb, line 225 def set_headers {"Content-Type"=> 'application/json',"Authorization"=>"bearer #{@token}"} end
set_token(token,expires_in=3600,token_type='bearer')
click to toggle source
# File lib/one_drive.rb, line 101 def set_token token,expires_in=3600,token_type='bearer' # &token_type=bearer&expires_in=3600&scope=Files.Read @token = token @expires_in = expires_in @token_type = token_type true end
token_url()
click to toggle source
# File lib/one_drive.rb, line 24 def token_url # OAuth URI token # GET https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&scope={scope} # &response_type=token&redirect_uri={redirect_uri} "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=#{@client_id}&scope=#{@scope}&response_type=token&redirect_uri=#{@redirect_uri}" end