sheetsapi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +31 -29
  4. data/lib/sheetsAPI.rb +34 -20
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5887f33b34b4d32d067e4cc69728f5532a157af1
4
- data.tar.gz: e12c57c00648b6bbadbff69f140c49981b4c099a
3
+ metadata.gz: 002b805781bbbdc7c80376a1dcb6d280dc2cd62f
4
+ data.tar.gz: 8664acaa73a42f299019b1840de8315ee4826a07
5
5
  SHA512:
6
- metadata.gz: 53cbf7018790907f3aa5162fc84200ca85a620645c9848d8aae8290e2332d0d9f6238d6c221535a0d4222b5b1addaa293ab806533080966b124d56652d946ad1
7
- data.tar.gz: 65b7c0fa468630afe0e453e1bc17b4b11dca4e61475375881a8771df733e89aa93594909af13f9c9d20996e4e3c5ee1548f97c22c7f0b682e3bf4d74648ffde1
6
+ metadata.gz: 2d983efaf2af1b9947539db51c50de49ac6d66e6f2ec685f6e0fcb88b32335bcbe0b74a273cf940a0162da58ca30c7909e44e0a2f98deceded72ee6220d9b249
7
+ data.tar.gz: cb5a6bcc2d7b69f3b10c5fd6d7d4117834faad8d3ba3c1e473da364ef8062c623b6e416d54a5db68a61ea0ff3fac907df983e85fd2ddfafdf57f8aac6b4e1b4c
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017 Phusion B.V.
3
+ Copyright (c) 2017 Phusion Holding B.V.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- document = SheetsAPI.document("1xuQVCadaMmTPiz_13hXuZHGKDihc41w5aii4DtuxOmU5j_eQ4BD98T-H")
28
- sheet = document.sheet("Daily Sales")
29
- sheet.insert(
30
- index: [:Date, :Client],
31
- sort: true,
32
- upsert: true,
33
- rows: [
34
- {
35
- Date: Date.new(2017,3,9),
36
- Client: "Some Guy",
37
- Email: "guy@client.com",
38
- Sales: 14,
39
- Profit: 5
40
- },
41
- {
42
- Date: Date.new(2017,3,9),
43
- Client: "Other Guy",
44
- Sales: 2,
45
- Profit: -1
46
- },
47
- {
48
- Date: Date.new(2017,3,10),
49
- Client: "Some Guy",
50
- Email: "guy@client.com",
51
- Sales: 8,
52
- Margin: 3
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
- # # Uncomment this to inspect requests made to the google API
6
- # module Google
7
- # module Apis
8
- # module Core
9
- # class HttpClientAdapter
10
- # alias old_call call
11
- # def call(request)
12
- # puts request.inspect
13
- # old_call(request)
14
- # end
15
- # end
16
- # end
17
- # end
18
- # end
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
- raise "Missing Google API Credentials: #{Dir.pwd}/GoogleAPICredentials.json"
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.1
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
- - team@phusion.com
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/SheetsAPI
37
+ homepage: https://github.com/phusion/sheetsapi
38
38
  licenses:
39
39
  - MIT
40
40
  metadata: {}