class Gdrive
Public Class Methods
new(token)
click to toggle source
# File lib/gdrive.rb, line 10 def initialize(token) @client = HTTP.auth("Bearer " + token) end
Public Instance Methods
apiget(endpoint, params, js)
click to toggle source
# File lib/gdrive.rb, line 13 def apiget(endpoint, params, js) url = BASE_URL + endpoint #puts url, params r = @client.get(url, :params => params, :json => js) if r.code != 200 puts "status code: #{r.code}" puts r.to_s end JSON.parse(r.to_s) end
getChildren(folderId)
click to toggle source
# File lib/gdrive.rb, line 23 def getChildren(folderId) params = {} params["q"] = "'#{folderId}' in parents" self.apiget("/v2/files", params, nil) end
listFolder(folderPath)
click to toggle source
# File lib/gdrive.rb, line 28 def listFolder(folderPath) found, obj = self.pathToId(folderPath, 'root') unless found return end return self.getChildren(obj["id"]) end
pathToId(path, root)
click to toggle source
# File lib/gdrive.rb, line 35 def pathToId(path, root) if path == "/" return true, {'title' => '/', 'id' => "root"} end found = false obj = nil pc = [] if @nosplit pc = [path] else pc = path.split('/') end pc.each do |p| #puts(p) found = false self.getChildren(root)["items"].each do |i| if p == i["title"] root = i["id"] found = true obj = i end end if !found puts("error: path not found: #{p}") return found, obj end end return found, obj end