gdrive 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/client.rb +68 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c0d71a7eab6e75b6b0a5e76c62c235c14af7a48da679663220e276b51f9a359d
4
+ data.tar.gz: df4ce99fcc5e8f19e49311412a0caf88ad60719386ea307b4b8d2a7f9f19b563
5
+ SHA512:
6
+ metadata.gz: d52a5352720be047b30019b7d3c2a83b2d37d2ff0a1517049bdd158b3f0737cac17d44c29411c920ebb6a544bcd6a821d2ddf7b0b7d09d87e403e0bea518a013
7
+ data.tar.gz: '01928324a9c3a079180eff75814583d68bfe1498633961ff79e28d7886caff5cc0dcc22e1e2c72f5d698ac1f3c6fcf275cd975d364b5d92c396491b0d3009e7d'
data/lib/client.rb ADDED
@@ -0,0 +1,68 @@
1
+ require "http"
2
+ require 'json'
3
+ require 'optparse'
4
+ require 'ruby-progressbar'
5
+ require 'yaml'
6
+
7
+ BASE_URL = "https://www.googleapis.com/drive"
8
+
9
+ class Gdrive
10
+ def initialize(token)
11
+ @client = HTTP.auth("Bearer " + token)
12
+ end
13
+ def apiget(endpoint, params, js)
14
+ url = BASE_URL + endpoint
15
+ #puts url, params
16
+ r = @client.get(url, :params => params, :json => js)
17
+ if r.code != 200
18
+ puts "status code: #{r.code}"
19
+ puts r.to_s
20
+ end
21
+ JSON.parse(r.to_s)
22
+ end
23
+ def getChildren(folderId)
24
+ params = {}
25
+ params["q"] = "'#{folderId}' in parents"
26
+ self.apiget("/v2/files", params, nil)
27
+ end
28
+ def listFolder(folderPath)
29
+ found, obj = self.pathToId(folderPath, 'root')
30
+ unless found
31
+ return
32
+ end
33
+ return self.getChildren(obj["id"])
34
+ end
35
+ def pathToId(path, root)
36
+ if path == "/"
37
+ return true, {'title' => '/', 'id' => "root"}
38
+ end
39
+ found = false
40
+ obj = nil
41
+ pc = []
42
+ if @nosplit
43
+ pc = [path]
44
+ else
45
+ pc = path.split('/')
46
+ end
47
+ pc.each do |p|
48
+ #puts(p)
49
+ found = false
50
+ self.getChildren(root)["items"].each do |i|
51
+ if p == i["title"]
52
+ root = i["id"]
53
+ found = true
54
+ obj = i
55
+ end
56
+ end
57
+ if !found
58
+ puts("error: path not found: #{p}")
59
+ return found, obj
60
+ end
61
+ end
62
+ return found, obj
63
+ end
64
+ end
65
+
66
+
67
+
68
+
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gdrive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - xiconet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Manage files stored at google drive
14
+ email: xiconet2009@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/client.rb
20
+ homepage: https://rubygems.org/gems/gdrive
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.1.2
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: A basic gdrive api client
43
+ test_files: []