ruboty-google_spreadsheet 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +39 -2
- data/lib/ruboty/brains/google_spreadsheet.rb +15 -3
- data/lib/ruboty/google_spreadsheet.rb +1 -0
- data/lib/ruboty/google_spreadsheet/client.rb +35 -0
- data/lib/ruboty/google_spreadsheet/spreadsheet.rb +3 -3
- data/lib/ruboty/google_spreadsheet/version.rb +1 -1
- metadata +4 -5
- data/lib/ruboty/google/spreadsheet.rb +0 -9
- data/lib/ruboty/google/spreadsheet/version.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62e903f42f156c78d0558f9e82868505b9e79d6f
|
4
|
+
data.tar.gz: a2fd5ab101c51ad916fee33c8ef84df9eb645c80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9ae4cd1a6650c1567e50db2a2c4a76e8e749ed5fae388163b87539716e4afb7f53b5b20f735d8b9a4cb8ca06d4d879dcba579d96d7cff46e9f3e9130e709373
|
7
|
+
data.tar.gz: b951e91792bedb48faec821d0946e99c196e9ce83b25bf72f5b6d4851b6352870beb29902beb58db4a862f24e20350d737fc50fa293b8bcac1015db74c8e0494
|
data/README.md
CHANGED
@@ -2,9 +2,46 @@
|
|
2
2
|
|
3
3
|
Store [Ruboty](https://github.com/r7kamura/ruboty/)'s memory in Google Spreadsheet.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Installation
|
6
6
|
|
7
7
|
```ruby
|
8
8
|
# Gemfile
|
9
|
-
gem "ruboty-
|
9
|
+
gem "ruboty-google_spreadsheet"
|
10
|
+
```
|
11
|
+
|
12
|
+
## ENV
|
13
|
+
|
14
|
+
```bash
|
15
|
+
GOOGLE_CLIENT_ID - Client ID
|
16
|
+
GOOGLE_CLIENT_SECRET - Client secret
|
17
|
+
GOOGLE_REDIRECT_URI - Redirect URI
|
18
|
+
GOOGLE_REFRESH_TOKEN - Refresh token issued with access token
|
19
|
+
GOOGLE_SPREADSHEET_KEY - Spreadsheet key (e.g. https://docs.google.com/spreadsheets/d/<key>/edit#gid=0)
|
20
|
+
```
|
21
|
+
|
22
|
+
## Refresh token
|
23
|
+
|
24
|
+
```bash
|
25
|
+
% open "https://accounts.google.com/o/oauth2/auth\
|
26
|
+
?access_type=offline\
|
27
|
+
&client_id=${CLIENT_ID}\
|
28
|
+
&redirect_uri=${REDIRECT_URI}\
|
29
|
+
&response_type=code\
|
30
|
+
&scope=https://www.googleapis.com/auth/drive"
|
31
|
+
```
|
32
|
+
|
33
|
+
```bash
|
34
|
+
% curl \
|
35
|
+
> -d "client_id=${CLIENT_ID}" \
|
36
|
+
> -d "client_secret=${CLIENT_SECRET}" \
|
37
|
+
> -d "redirect_uri=${REDIRECT_URI}" \
|
38
|
+
> -d "grant_type=authorization_code" \
|
39
|
+
> -d "code=${CODE}" \
|
40
|
+
> "https://accounts.google.com/o/oauth2/token"
|
41
|
+
{
|
42
|
+
"access_token" : "...",
|
43
|
+
"token_type" : "Bearer",
|
44
|
+
"expires_in" : 3600,
|
45
|
+
"refresh_token" : "..."
|
46
|
+
}
|
10
47
|
```
|
@@ -1,19 +1,31 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module Brains
|
3
3
|
class GoogleSpreadsheet < Base
|
4
|
-
env :
|
4
|
+
env :GOOGLE_CLIENT_ID, "Client ID"
|
5
|
+
env :GOOGLE_CLIENT_SECRET, "Client secret"
|
6
|
+
env :GOOGLE_REDIRECT_URI, "Redirect URI"
|
7
|
+
env :GOOGLE_REFRESH_TOKEN, "Refresh token issued with access token"
|
5
8
|
env :GOOGLE_SPREADSHEET_KEY, "Spreadsheet key (e.g. https://docs.google.com/spreadsheets/d/<key>/edit#gid=0)"
|
6
9
|
|
7
10
|
def initialize
|
8
11
|
super
|
12
|
+
|
9
13
|
@thread = Thread.new { sync }
|
10
14
|
@thread.abort_on_exception = true
|
15
|
+
|
16
|
+
@client = Ruboty::GoogleSpreadsheet::Client.new(
|
17
|
+
client_id: ENV["GOOGLE_CLIENT_ID"],
|
18
|
+
client_secret: ENV["GOOGLE_CLIENT_SECRET"],
|
19
|
+
redirect_uri: ENV["GOOGLE_REDIRECT_URI"],
|
20
|
+
refresh_token: ENV["GOOGLE_REFRESH_TOKEN"]
|
21
|
+
)
|
22
|
+
@client.authenticate!
|
11
23
|
end
|
12
24
|
|
13
25
|
def data
|
14
26
|
@data ||= Ruboty::GoogleSpreadsheet::Spreadsheet.new(
|
15
|
-
|
16
|
-
ENV["GOOGLE_SPREADSHEET_KEY"]
|
27
|
+
access_token: @client.access_token,
|
28
|
+
spreadsheet_key: ENV["GOOGLE_SPREADSHEET_KEY"]
|
17
29
|
)
|
18
30
|
end
|
19
31
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "google/api_client"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module GoogleSpreadsheet
|
5
|
+
class Client
|
6
|
+
SCOPE = "https://www.googleapis.com/auth/drive"
|
7
|
+
|
8
|
+
def initialize(attrs = {})
|
9
|
+
@authorization = api_client.authorization
|
10
|
+
@authorization.client_id = attrs[:client_id]
|
11
|
+
@authorization.client_secret = attrs[:client_secret]
|
12
|
+
@authorization.scope = SCOPE
|
13
|
+
@authorization.redirect_uri = attrs[:redirect_uri]
|
14
|
+
@authorization.refresh_token = attrs[:refresh_token]
|
15
|
+
end
|
16
|
+
|
17
|
+
def authenticate!
|
18
|
+
@authorization.fetch_access_token!
|
19
|
+
end
|
20
|
+
|
21
|
+
def access_token
|
22
|
+
@authorization.access_token
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def api_client
|
28
|
+
@api_client ||= Google::APIClient.new(
|
29
|
+
application_name: "ruboty-google_spreadsheet",
|
30
|
+
application_version: VERSION
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -3,9 +3,9 @@ require "google_drive"
|
|
3
3
|
module Ruboty
|
4
4
|
module GoogleSpreadsheet
|
5
5
|
class Spreadsheet
|
6
|
-
def initialize(
|
7
|
-
@access_token = access_token
|
8
|
-
@key =
|
6
|
+
def initialize(attrs = {})
|
7
|
+
@access_token = attrs[:access_token]
|
8
|
+
@key = attrs[:spreadsheet_key]
|
9
9
|
@worksheets = []
|
10
10
|
end
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-google_spreadsheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoto Kaneko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -94,9 +94,8 @@ files:
|
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
96
|
- lib/ruboty/brains/google_spreadsheet.rb
|
97
|
-
- lib/ruboty/google/spreadsheet.rb
|
98
|
-
- lib/ruboty/google/spreadsheet/version.rb
|
99
97
|
- lib/ruboty/google_spreadsheet.rb
|
98
|
+
- lib/ruboty/google_spreadsheet/client.rb
|
100
99
|
- lib/ruboty/google_spreadsheet/spreadsheet.rb
|
101
100
|
- lib/ruboty/google_spreadsheet/version.rb
|
102
101
|
- ruboty-google_spreadsheet.gemspec
|
@@ -122,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
121
|
version: '0'
|
123
122
|
requirements: []
|
124
123
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.2.2
|
126
125
|
signing_key:
|
127
126
|
specification_version: 4
|
128
127
|
summary: Store Ruboty's memory in Google Spreadsheet.
|