sheetsapi 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +31 -29
- data/lib/sheetsAPI.rb +34 -20
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 002b805781bbbdc7c80376a1dcb6d280dc2cd62f
|
|
4
|
+
data.tar.gz: 8664acaa73a42f299019b1840de8315ee4826a07
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d983efaf2af1b9947539db51c50de49ac6d66e6f2ec685f6e0fcb88b32335bcbe0b74a273cf940a0162da58ca30c7909e44e0a2f98deceded72ee6220d9b249
|
|
7
|
+
data.tar.gz: cb5a6bcc2d7b69f3b10c5fd6d7d4117834faad8d3ba3c1e473da364ef8062c623b6e416d54a5db68a61ea0ff3fac907df983e85fd2ddfafdf57f8aac6b4e1b4c
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -24,35 +24,37 @@ In the GoogleAPICredentials.json file you will find a `client_email` field. Shar
|
|
|
24
24
|
Usage
|
|
25
25
|
=====
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
27
|
+
~~~ruby
|
|
28
|
+
document = SheetsAPI.document("1xuQVCadaMmTPiz_13hXuZHGKDihc41w5aii4DtuxOmU5j_eQ4BD98T-H")
|
|
29
|
+
sheet = document.sheet("Daily Sales")
|
|
30
|
+
sheet.insert(
|
|
31
|
+
index: [:Date, :Client],
|
|
32
|
+
sort: true,
|
|
33
|
+
upsert: true,
|
|
34
|
+
rows: [
|
|
35
|
+
{
|
|
36
|
+
Date: Date.new(2017,3,9),
|
|
37
|
+
Client: "Some Guy",
|
|
38
|
+
Email: "guy@client.com",
|
|
39
|
+
Sales: 14,
|
|
40
|
+
Profit: 5
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
Date: Date.new(2017,3,9),
|
|
44
|
+
Client: "Other Guy",
|
|
45
|
+
Sales: 2,
|
|
46
|
+
Profit: -1
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
Date: Date.new(2017,3,10),
|
|
50
|
+
Client: "Some Guy",
|
|
51
|
+
Email: "guy@client.com",
|
|
52
|
+
Sales: 8,
|
|
53
|
+
Margin: 3
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
~~~
|
|
56
58
|
|
|
57
59
|
Insert Parameters
|
|
58
60
|
=================
|
data/lib/sheetsAPI.rb
CHANGED
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
require 'set'
|
|
2
2
|
require 'googleauth'
|
|
3
3
|
require 'google/apis/sheets_v4'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
require 'google/apis/drive_v3'
|
|
5
|
+
|
|
6
|
+
# Uncomment this to inspect requests made to the google API
|
|
7
|
+
module Google
|
|
8
|
+
module Apis
|
|
9
|
+
module Core
|
|
10
|
+
class HttpClientAdapter
|
|
11
|
+
alias old_call call
|
|
12
|
+
def call(request)
|
|
13
|
+
puts request.inspect
|
|
14
|
+
old_call(request)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
19
20
|
|
|
20
21
|
module SheetsAPI
|
|
21
22
|
if !File.file? "#{Dir.pwd}/GoogleAPICredentials.json"
|
|
22
|
-
|
|
23
|
+
puts "WARNING -- Missing Google API Credentials: #{Dir.pwd}/GoogleAPICredentials.json"
|
|
24
|
+
else
|
|
25
|
+
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "#{Dir.pwd}/GoogleAPICredentials.json"
|
|
23
26
|
end
|
|
24
27
|
|
|
25
|
-
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "#{Dir.pwd}/GoogleAPICredentials.json"
|
|
26
28
|
scopes = ['https://www.googleapis.com/auth/drive']
|
|
27
29
|
authorization = Google::Auth.get_application_default(scopes)
|
|
28
30
|
|
|
29
31
|
SheetService = Google::Apis::SheetsV4::SheetsService.new
|
|
30
32
|
SheetService.authorization = authorization
|
|
31
33
|
|
|
34
|
+
DriveService = Google::Apis::DriveV3::DriveService.new
|
|
35
|
+
DriveService.authorization = authorization
|
|
36
|
+
|
|
32
37
|
class << self
|
|
33
38
|
# This will raise if the document cannot be opened
|
|
34
|
-
def document(id)
|
|
35
|
-
return Document.new(id)
|
|
39
|
+
def document(name: nil, id: nil)
|
|
40
|
+
return Document.new(documentName: name, documentId: id)
|
|
36
41
|
end
|
|
37
42
|
end
|
|
38
43
|
|
|
@@ -88,7 +93,14 @@ module SheetsAPI
|
|
|
88
93
|
end
|
|
89
94
|
|
|
90
95
|
class Document
|
|
91
|
-
def initialize(documentId)
|
|
96
|
+
def initialize(documentId: nil, documentName: 'unnamed')
|
|
97
|
+
if !documentId
|
|
98
|
+
file = DriveService.create_file(Google::Apis::DriveV3::File.new(mime_type: 'application/vnd.google-apps.spreadsheet', name: documentName))
|
|
99
|
+
documentId = file.id
|
|
100
|
+
a = Google::Apis::DriveV3::Permission.new(type: 'user', role: 'owner', email_address: 'goffert@phusion.nl')
|
|
101
|
+
puts a.inspect
|
|
102
|
+
DriveService.create_permission(documentId, a, transfer_ownership: true)
|
|
103
|
+
end
|
|
92
104
|
@id = documentId
|
|
93
105
|
@document = SheetService.get_spreadsheet(documentId)
|
|
94
106
|
end
|
|
@@ -119,3 +131,5 @@ module SheetsAPI
|
|
|
119
131
|
end
|
|
120
132
|
end
|
|
121
133
|
end
|
|
134
|
+
|
|
135
|
+
puts SheetsAPI.document(name: 'test')
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sheetsapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Phusion
|
|
7
|
+
- Phusion B.V.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
@@ -26,7 +26,7 @@ dependencies:
|
|
|
26
26
|
version: '0.10'
|
|
27
27
|
description: A simple API for writing to Google Sheets
|
|
28
28
|
email:
|
|
29
|
-
-
|
|
29
|
+
- info@phusion.nl
|
|
30
30
|
executables: []
|
|
31
31
|
extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
|
@@ -34,7 +34,7 @@ files:
|
|
|
34
34
|
- LICENSE
|
|
35
35
|
- README.md
|
|
36
36
|
- lib/sheetsAPI.rb
|
|
37
|
-
homepage: https://github.com/phusion/
|
|
37
|
+
homepage: https://github.com/phusion/sheetsapi
|
|
38
38
|
licenses:
|
|
39
39
|
- MIT
|
|
40
40
|
metadata: {}
|