ruboty-google_calendar 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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -0
- data/Rakefile +2 -0
- data/lib/ruboty/google_calendar.rb +2 -0
- data/lib/ruboty/google_calendar/version.rb +5 -0
- data/lib/ruboty/handlers/google_calendar.rb +145 -0
- data/ruboty-google_calendar.gemspec +24 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5f3a854c1253222b9ca27fa1503f13b667961f23
|
4
|
+
data.tar.gz: 94db08488268b25acfdeb66ebf1cd79823dcf01e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc137e9fb3885e1d66def6d1fcbe246e74697557f47a6fcfcff8d71d18852cf96c882c4fdf64e60e139c12919d456bc9c75efa622317864efb3bdd7fe5571927
|
7
|
+
data.tar.gz: 19404895f65ff0b819dd12cb2d5f246936d30d081671288ea5f9225364454d8892979eea6192e6bd56bbb21388fe528653fa4fe3d2450ac6f2d0fba1f6226cc6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ryo Nakamura
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Ruboty::GoogleCalendar
|
2
|
+
[Ruboty](https://github.com/r7kamura/ruboty) plug-in to read schedule from Google Calendar.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
```
|
6
|
+
> @ruboty list events
|
7
|
+
2015-03-04 09:30 - 09:40 Stand-up meeting
|
8
|
+
2015-03-04 14:00 - 15:00 Engineering meeting
|
9
|
+
```
|
10
|
+
|
11
|
+
## ENV
|
12
|
+
Note: You need to register a native application client on
|
13
|
+
[Google Developers Console](https://console.developers.google.com),
|
14
|
+
then issue an access token (with a refresh token) by yourself.
|
15
|
+
|
16
|
+
```
|
17
|
+
GOOGLE_CALENDAR_ID - Google Calendar ID (default: primary)
|
18
|
+
GOOGLE_CLIENT_ID - Client ID
|
19
|
+
GOOGLE_CLIENT_SECRET - Client Secret
|
20
|
+
GOOGLE_REDIRECT_URI - Redirect URI (http://localhost in most cases)
|
21
|
+
GOOGLE_REFRESH_TOKEN - Refresh token issued with access token
|
22
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
require "active_support/core_ext/date/calculations"
|
2
|
+
require "active_support/core_ext/numeric/time"
|
3
|
+
require "google/api_client"
|
4
|
+
require "google/api_client/client_secrets"
|
5
|
+
require "ruboty"
|
6
|
+
require "time"
|
7
|
+
|
8
|
+
module Ruboty
|
9
|
+
module Handlers
|
10
|
+
class GoogleCalendar < Base
|
11
|
+
DEFAULT_CALENDAR_ID = "primary"
|
12
|
+
|
13
|
+
env :GOOGLE_CALENDAR_ID, "Google Calendar ID (default: primary)", optional: true
|
14
|
+
env :GOOGLE_CLIENT_ID, "Client ID"
|
15
|
+
env :GOOGLE_CLIENT_SECRET, "Client Secret"
|
16
|
+
env :GOOGLE_REDIRECT_URI, "Redirect URI (http://localhost in most cases)"
|
17
|
+
env :GOOGLE_REFRESH_TOKEN, "Refresh token issued with access token"
|
18
|
+
|
19
|
+
on(
|
20
|
+
/list events\z/,
|
21
|
+
description: "List events from Google Calendar",
|
22
|
+
name: "list_events",
|
23
|
+
)
|
24
|
+
|
25
|
+
def list_events(message)
|
26
|
+
text = client.list_events(calendar_id: calendar_id).items.map do |item|
|
27
|
+
ItemView.new(item)
|
28
|
+
end.join("\n")
|
29
|
+
message.reply(text, code: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def calendar_id
|
35
|
+
ENV["GOOGLE_CALENDAR_ID"] || DEFAULT_CALENDAR_ID
|
36
|
+
end
|
37
|
+
|
38
|
+
def client
|
39
|
+
@client ||= Client.new(
|
40
|
+
client_id: ENV["GOOGLE_CLIENT_ID"],
|
41
|
+
client_secret: ENV["GOOGLE_CLIENT_SECRET"],
|
42
|
+
redirect_uri: ENV["GOOGLE_REDIRECT_URI"],
|
43
|
+
refresh_token: ENV["GOOGLE_REFRESH_TOKEN"],
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
class Client
|
48
|
+
APPLICATION_NAME = "ruboty-google_calendar"
|
49
|
+
AUTH_URI = "https://accounts.google.com/o/oauth2/auth"
|
50
|
+
SCOPE = "https://www.googleapis.com/auth/calendar"
|
51
|
+
TOKEN_URI = "https://accounts.google.com/o/oauth2/token"
|
52
|
+
|
53
|
+
def initialize(client_id: nil, client_secret: nil, redirect_uri: nil, refresh_token: nil)
|
54
|
+
@client_id = client_id
|
55
|
+
@client_secret = client_secret
|
56
|
+
@redirect_uri = redirect_uri
|
57
|
+
@refresh_token = refresh_token
|
58
|
+
authenticate!
|
59
|
+
end
|
60
|
+
|
61
|
+
def list_events(calendar_id: nil)
|
62
|
+
api_client.execute(
|
63
|
+
api_method: calendar.events.list,
|
64
|
+
parameters: {
|
65
|
+
calendarId: calendar_id,
|
66
|
+
singleEvents: true,
|
67
|
+
orderBy: "startTime",
|
68
|
+
timeMin: Time.now.iso8601,
|
69
|
+
timeMax: 1.day.since.iso8601
|
70
|
+
}
|
71
|
+
).data
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def api_client
|
77
|
+
@api_client ||= begin
|
78
|
+
_api_client = Google::APIClient.new(
|
79
|
+
application_name: APPLICATION_NAME,
|
80
|
+
application_version: Ruboty::GoogleCalendar::VERSION,
|
81
|
+
)
|
82
|
+
_api_client.authorization = authorization
|
83
|
+
_api_client.authorization.scope = SCOPE
|
84
|
+
_api_client
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# @todo Support access token expiration.
|
89
|
+
def authenticate!
|
90
|
+
api_client.authorization.fetch_access_token!
|
91
|
+
end
|
92
|
+
|
93
|
+
def authorization
|
94
|
+
client_secrets.to_authorization
|
95
|
+
end
|
96
|
+
|
97
|
+
def client_secrets
|
98
|
+
Google::APIClient::ClientSecrets.new(
|
99
|
+
flow: :installed,
|
100
|
+
installed: {
|
101
|
+
auth_uri: AUTH_URI,
|
102
|
+
client_id: @client_id,
|
103
|
+
client_secret: @client_secret,
|
104
|
+
redirect_uris: [@redirect_uri],
|
105
|
+
refresh_token: @refresh_token,
|
106
|
+
token_uri: TOKEN_URI,
|
107
|
+
},
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
def calendar
|
112
|
+
@calendar ||= api_client.discovered_api("calendar", "v3")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class ItemView
|
117
|
+
def initialize(item)
|
118
|
+
@item = item
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_s
|
122
|
+
"#{started_at} - #{finished_at} #{summary}"
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def finished_at
|
128
|
+
if @item.start.date_time.localtime.day == @item.end.date_time.localtime.day
|
129
|
+
@item.end.date_time.localtime.strftime("%H:%M")
|
130
|
+
else
|
131
|
+
@item.end.date_time.localtime.strftime("%Y-%m-%d %H:%M")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def started_at
|
136
|
+
@item.start.date_time.localtime.strftime("%Y-%m-%d %H:%M")
|
137
|
+
end
|
138
|
+
|
139
|
+
def summary
|
140
|
+
@item.summary
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "ruboty/google_calendar/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ruboty-google_calendar"
|
7
|
+
spec.version = Ruboty::GoogleCalendar::VERSION
|
8
|
+
spec.authors = ["Ryo Nakamura"]
|
9
|
+
spec.email = ["r7kamura@gmail.com"]
|
10
|
+
spec.summary = "Ruboty plug-in to read schedule from Google Calendar."
|
11
|
+
spec.homepage = "https://github.com/r7kamura/ruboty-google_calendar"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "activesupport"
|
20
|
+
spec.add_runtime_dependency "google-api-client"
|
21
|
+
spec.add_runtime_dependency "ruboty"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-google_calendar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryo Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: google-api-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruboty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- r7kamura@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/ruboty/google_calendar.rb
|
96
|
+
- lib/ruboty/google_calendar/version.rb
|
97
|
+
- lib/ruboty/handlers/google_calendar.rb
|
98
|
+
- ruboty-google_calendar.gemspec
|
99
|
+
homepage: https://github.com/r7kamura/ruboty-google_calendar
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.4.5
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Ruboty plug-in to read schedule from Google Calendar.
|
123
|
+
test_files: []
|
124
|
+
has_rdoc:
|