google-oauth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +2 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +20 -0
- data/README.md +53 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/google-oauth.gemspec +79 -0
- data/lib/google_oauth.rb +20 -0
- data/lib/google_oauth/calendar.rb +98 -0
- data/lib/google_oauth/calendar/acl.rb +6 -0
- data/lib/google_oauth/calendar/calendar.rb +16 -0
- data/lib/google_oauth/calendar/calendar_list.rb +19 -0
- data/lib/google_oauth/calendar/color.rb +6 -0
- data/lib/google_oauth/calendar/event.rb +7 -0
- data/lib/google_oauth/calendar/free_busy.rb +6 -0
- data/lib/google_oauth/calendar/setting.rb +6 -0
- data/lib/google_oauth/client.rb +60 -0
- data/lib/google_oauth/contacts.rb +4 -0
- data/lib/google_oauth/document.rb +4 -0
- data/lib/google_oauth/mail.rb +4 -0
- data/spec/google-oauth_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +171 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'google-api-client'
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec", "~> 2.8.0"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", "~> 1.1"
|
13
|
+
gem "jeweler", "~> 1.8.3"
|
14
|
+
gem "simplecov"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.8)
|
5
|
+
autoparse (0.3.1)
|
6
|
+
addressable (~> 2.2.3)
|
7
|
+
extlib (>= 0.9.15)
|
8
|
+
multi_json (>= 1.0.0)
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
extlib (0.9.15)
|
11
|
+
faraday (0.7.6)
|
12
|
+
addressable (~> 2.2)
|
13
|
+
multipart-post (~> 1.1)
|
14
|
+
rack (~> 1.1)
|
15
|
+
git (1.2.5)
|
16
|
+
google-api-client (0.4.4)
|
17
|
+
addressable (>= 2.2.3)
|
18
|
+
autoparse (>= 0.3.1)
|
19
|
+
extlib (>= 0.9.15)
|
20
|
+
faraday (~> 0.7.0)
|
21
|
+
launchy (>= 2.0.0)
|
22
|
+
multi_json (>= 1.3.0)
|
23
|
+
signet (>= 0.3.4)
|
24
|
+
uuidtools (>= 2.1.0)
|
25
|
+
jeweler (1.8.3)
|
26
|
+
bundler (~> 1.0)
|
27
|
+
git (>= 1.2.5)
|
28
|
+
rake
|
29
|
+
rdoc
|
30
|
+
json (1.7.3)
|
31
|
+
jwt (0.1.4)
|
32
|
+
json (>= 1.2.4)
|
33
|
+
launchy (2.1.0)
|
34
|
+
addressable (~> 2.2.6)
|
35
|
+
multi_json (1.3.6)
|
36
|
+
multipart-post (1.1.5)
|
37
|
+
rack (1.4.1)
|
38
|
+
rake (0.9.2.2)
|
39
|
+
rdoc (3.12)
|
40
|
+
json (~> 1.4)
|
41
|
+
rspec (2.8.0)
|
42
|
+
rspec-core (~> 2.8.0)
|
43
|
+
rspec-expectations (~> 2.8.0)
|
44
|
+
rspec-mocks (~> 2.8.0)
|
45
|
+
rspec-core (2.8.0)
|
46
|
+
rspec-expectations (2.8.0)
|
47
|
+
diff-lcs (~> 1.1.2)
|
48
|
+
rspec-mocks (2.8.0)
|
49
|
+
signet (0.3.4)
|
50
|
+
addressable (~> 2.2.3)
|
51
|
+
faraday (~> 0.7.0)
|
52
|
+
jwt (>= 0.1.4)
|
53
|
+
multi_json (>= 1.0.0)
|
54
|
+
simplecov (0.6.4)
|
55
|
+
multi_json (~> 1.0)
|
56
|
+
simplecov-html (~> 0.5.3)
|
57
|
+
simplecov-html (0.5.3)
|
58
|
+
uuidtools (2.1.2)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
bundler (~> 1.1)
|
65
|
+
google-api-client
|
66
|
+
jeweler (~> 1.8.3)
|
67
|
+
rdoc (~> 3.12)
|
68
|
+
rspec (~> 2.8.0)
|
69
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Kang Chen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# google-oauth
|
2
|
+
|
3
|
+
Thin ruby wrapper for the various Google OAuth 2 APIs
|
4
|
+
|
5
|
+
## Notice
|
6
|
+
I created this for use in a school project. It's still very raw and not ready for general public consumptions yet.
|
7
|
+
|
8
|
+
## Install
|
9
|
+
```
|
10
|
+
gem install google-oauth
|
11
|
+
```
|
12
|
+
|
13
|
+
## Examples
|
14
|
+
```ruby
|
15
|
+
# set up the connection
|
16
|
+
require 'google_oauth'
|
17
|
+
GoogleOAuth.configure do |s|
|
18
|
+
s.client_id = CLIENT_ID
|
19
|
+
s.client_secret = CLIENT_SECRET
|
20
|
+
s.scope = 'userinfo.email,userinfo.profile,http://www.google.com/calendar/feeds/,http://www.google.com/m8/feeds/'
|
21
|
+
s.host = "http://localhost:3000"
|
22
|
+
end
|
23
|
+
user = User.first
|
24
|
+
oauth = u.authentications.first
|
25
|
+
# you can manually pass in the tokens here but passing in
|
26
|
+
# the oauth activerecord object is a convenient shortcut
|
27
|
+
# This also supports updating of your refresh token
|
28
|
+
client = GoogleOAuth::Client.new(:authentication => oauth)
|
29
|
+
|
30
|
+
# Getting a list of calendars
|
31
|
+
client.calendar_list
|
32
|
+
|
33
|
+
# Getting data from your primary calendar
|
34
|
+
client.get_calendar
|
35
|
+
```
|
36
|
+
|
37
|
+
## Future work
|
38
|
+
I hope to rewrite most of this so that there's a much nicer DSL for general consumption with tests and better documentation.
|
39
|
+
|
40
|
+
## Contributing to google-oauth
|
41
|
+
|
42
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
43
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
44
|
+
* Fork the project.
|
45
|
+
* Start a feature/bugfix branch.
|
46
|
+
* Commit and push until you are happy with your contribution.
|
47
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
48
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
49
|
+
|
50
|
+
## Copyright
|
51
|
+
|
52
|
+
Copyright (c) 2012 Kang Chen. See LICENSE.txt for
|
53
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "google-oauth"
|
18
|
+
gem.homepage = "http://github.com/kimyoutora/google-oauth"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby wrapper for the various Google OAuth 2 APIs}
|
21
|
+
gem.description = gem.summary
|
22
|
+
gem.email = "kangchen614@gmail.com"
|
23
|
+
gem.authors = ["Kang Chen"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "google-oauth #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "google-oauth"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kang Chen"]
|
12
|
+
s.date = "2012-06-30"
|
13
|
+
s.description = "Ruby wrapper for the various Google OAuth 2 APIs"
|
14
|
+
s.email = "kangchen614@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
".rvmrc",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"google-oauth.gemspec",
|
30
|
+
"lib/google_oauth.rb",
|
31
|
+
"lib/google_oauth/calendar.rb",
|
32
|
+
"lib/google_oauth/calendar/acl.rb",
|
33
|
+
"lib/google_oauth/calendar/calendar.rb",
|
34
|
+
"lib/google_oauth/calendar/calendar_list.rb",
|
35
|
+
"lib/google_oauth/calendar/color.rb",
|
36
|
+
"lib/google_oauth/calendar/event.rb",
|
37
|
+
"lib/google_oauth/calendar/free_busy.rb",
|
38
|
+
"lib/google_oauth/calendar/setting.rb",
|
39
|
+
"lib/google_oauth/client.rb",
|
40
|
+
"lib/google_oauth/contacts.rb",
|
41
|
+
"lib/google_oauth/document.rb",
|
42
|
+
"lib/google_oauth/mail.rb",
|
43
|
+
"spec/google-oauth_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = "http://github.com/kimyoutora/google-oauth"
|
47
|
+
s.licenses = ["MIT"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = "1.8.24"
|
50
|
+
s.summary = "Ruby wrapper for the various Google OAuth 2 APIs"
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<google-api-client>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
58
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
61
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<google-api-client>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
65
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.1"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
68
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<google-api-client>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
73
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.1"])
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
76
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
data/lib/google_oauth.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# require "google_oauth/calendar"
|
2
|
+
require "google_oauth/client"
|
3
|
+
# require "google_oauth/document"
|
4
|
+
# require "google_oauth/contacts"
|
5
|
+
# require "google_oauth/mail"
|
6
|
+
|
7
|
+
module GoogleOAuth
|
8
|
+
class << self
|
9
|
+
attr_accessor :client_id, :client_secret, :scope, :host
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield self
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def client(opts)
|
17
|
+
client.new(opts)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require "google_oauth/calendar/acl"
|
2
|
+
require "google_oauth/calendar/calendar"
|
3
|
+
require "google_oauth/calendar/calendar_list"
|
4
|
+
require "google_oauth/calendar/color"
|
5
|
+
require "google_oauth/calendar/event"
|
6
|
+
require "google_oauth/calendar/free_busy"
|
7
|
+
require "google_oauth/calendar/setting"
|
8
|
+
|
9
|
+
module GoogleOAuth
|
10
|
+
module Calendar
|
11
|
+
# Deletes an entry on the user's calendar list.
|
12
|
+
def delete_calendar_list(calendar_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
# # Returns an entry on the user's calendar list.
|
16
|
+
# def get_calendar_list(calendar_id)
|
17
|
+
# end
|
18
|
+
|
19
|
+
# Adds an entry to the user's calendar list.
|
20
|
+
def insert_calendar_list(opts = {})
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns entries on the user's calendar list.
|
24
|
+
# CalendarList#list
|
25
|
+
def calendar_list
|
26
|
+
page_token = nil
|
27
|
+
result = execute(:api_method => service.calendar_list.list)
|
28
|
+
entries = []
|
29
|
+
while true
|
30
|
+
entries += result.data.items
|
31
|
+
if !(page_token = result.data.next_page_token)
|
32
|
+
break
|
33
|
+
end
|
34
|
+
result = execute(:api_method => service.calendar_list.list,
|
35
|
+
:parameters => {'pageToken' => page_token})
|
36
|
+
end
|
37
|
+
|
38
|
+
entries
|
39
|
+
end
|
40
|
+
|
41
|
+
# Updates an entry on the user's calendar list.
|
42
|
+
def update_calendar_list(opts = {})
|
43
|
+
end
|
44
|
+
|
45
|
+
# Updates an entry on the user's calendar list. This method supports patch semantics
|
46
|
+
def patch_calendar_list(opts = {})
|
47
|
+
update_calendar_list
|
48
|
+
end
|
49
|
+
|
50
|
+
# Clears a primary calendar. This operation deletes all data associated with the primary calendar of an account and cannot be undone.
|
51
|
+
def clear_calendar
|
52
|
+
end
|
53
|
+
|
54
|
+
# Deletes a secondary calendar.
|
55
|
+
def delete_calendar(calendar_id)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns metadata for a calendar
|
59
|
+
def get_calendar(calendar_id = 'primary')
|
60
|
+
execute(:api_method => service.calendars.get, :parameters => { 'calendarId' => calendar_id }).data
|
61
|
+
end
|
62
|
+
|
63
|
+
# Creates a secondary calendar.
|
64
|
+
def insert_calendar(opts = {})
|
65
|
+
end
|
66
|
+
|
67
|
+
# Updates metadata for a calendar.
|
68
|
+
def update_calendar(opts = {})
|
69
|
+
end
|
70
|
+
|
71
|
+
# Updates metadata for a calendar. This method supports patch semantics.
|
72
|
+
def patch_calendar(opts = {})
|
73
|
+
update_calendar(opts)
|
74
|
+
end
|
75
|
+
|
76
|
+
def events_list(calendar_id = 'primary', options = {})
|
77
|
+
%w(timeMin timeMax).each do |time|
|
78
|
+
options[time] = options[time].xmlschema if options[time]
|
79
|
+
end
|
80
|
+
|
81
|
+
params = { 'calendarId' => calendar_id }
|
82
|
+
params.merge!(options)
|
83
|
+
result = execute(:api_method => service.events.list,
|
84
|
+
:parameters => params)
|
85
|
+
events = []
|
86
|
+
while true
|
87
|
+
events += result.data.items
|
88
|
+
if !(params[:page_token] = result.data.next_page_token)
|
89
|
+
break
|
90
|
+
end
|
91
|
+
result = execute(:api_method => service.events.list,
|
92
|
+
:parameters => params)
|
93
|
+
end
|
94
|
+
|
95
|
+
events
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GoogleOAuth
|
2
|
+
module Calendar
|
3
|
+
# https://developers.google.com/google-apps/calendar/v3/reference/calendars
|
4
|
+
|
5
|
+
class Calendar
|
6
|
+
attr_accessor :etag, :time_zone, :color_id, :id, :access_role, :summary, :description
|
7
|
+
|
8
|
+
def initialize(opts = {})
|
9
|
+
opts.each_pair do |key, value|
|
10
|
+
send "#{key}=".to_sym, value
|
11
|
+
end
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GoogleOAuth
|
2
|
+
module Calendar
|
3
|
+
# https://developers.google.com/google-apps/calendar/v3/reference/calendarList
|
4
|
+
# Google needs better naming schemes for this stuff. What is calling list on calendar list???
|
5
|
+
|
6
|
+
class CalendarList
|
7
|
+
attr_accessor :kind, :etag, :id, :summary, :description, :location,
|
8
|
+
:time_zone, :summary_override, :color_id, :hidden, :selected,
|
9
|
+
:access_role, :default_reminders
|
10
|
+
|
11
|
+
def initialize(opts = {})
|
12
|
+
opts.each_pair do |key, value|
|
13
|
+
send "#{key}=".to_sym, value
|
14
|
+
end
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'google/api_client'
|
2
|
+
require 'google_oauth/calendar'
|
3
|
+
|
4
|
+
module GoogleOAuth
|
5
|
+
class Client
|
6
|
+
include Calendar
|
7
|
+
|
8
|
+
attr_accessor :refresh_token, :access_token, :google_client, :expires_at, :authentication
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
[:refresh_token, :access_token, :expires_at].each do |attr|
|
12
|
+
instance_variable_set("@#{attr}".to_sym, options[:authentication].send(attr))
|
13
|
+
end
|
14
|
+
|
15
|
+
@authentication = options[:authentication]
|
16
|
+
|
17
|
+
setup_google_client!
|
18
|
+
end
|
19
|
+
|
20
|
+
# Delegate to Google OAuth Client
|
21
|
+
def method_missing(method, *args, &block)
|
22
|
+
google_client.send(method, *args, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def setup_google_client!
|
28
|
+
@google_client = Google::APIClient.new
|
29
|
+
@google_client.authorization.client_id = GoogleOAuth.client_id
|
30
|
+
@google_client.authorization.client_secret = GoogleOAuth.client_secret
|
31
|
+
@google_client.authorization.scope = GoogleOAuth.scope
|
32
|
+
@google_client.authorization.refresh_token = refresh_token
|
33
|
+
@google_client.authorization.access_token = access_token
|
34
|
+
|
35
|
+
puts "@google_client: #{@google_client.authorization.inspect}"
|
36
|
+
|
37
|
+
# Google OAuth API is a big liar!
|
38
|
+
# Their API does not seem to respect the expiration time they specify
|
39
|
+
# in their initial response
|
40
|
+
if @google_client.authorization.refresh_token && oauth_expired?
|
41
|
+
new_tokens = @google_client.authorization.fetch_access_token!
|
42
|
+
|
43
|
+
expires_at = 10.minutes.from_now
|
44
|
+
if authentication
|
45
|
+
authentication.access_token = new_tokens["access_token"]
|
46
|
+
authentication.expires_at = 10.minutes.from_now
|
47
|
+
authentication.save
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def oauth_expired?
|
53
|
+
expires_at < Time.now
|
54
|
+
end
|
55
|
+
|
56
|
+
def service
|
57
|
+
@service ||= google_client.discovered_api('calendar', 'v3')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'google-oauth'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google-oauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kang Chen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: google-api-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.1'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.1'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.3
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.3
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: simplecov
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Ruby wrapper for the various Google OAuth 2 APIs
|
111
|
+
email: kangchen614@gmail.com
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files:
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.md
|
117
|
+
files:
|
118
|
+
- .document
|
119
|
+
- .rspec
|
120
|
+
- .rvmrc
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- VERSION
|
127
|
+
- google-oauth.gemspec
|
128
|
+
- lib/google_oauth.rb
|
129
|
+
- lib/google_oauth/calendar.rb
|
130
|
+
- lib/google_oauth/calendar/acl.rb
|
131
|
+
- lib/google_oauth/calendar/calendar.rb
|
132
|
+
- lib/google_oauth/calendar/calendar_list.rb
|
133
|
+
- lib/google_oauth/calendar/color.rb
|
134
|
+
- lib/google_oauth/calendar/event.rb
|
135
|
+
- lib/google_oauth/calendar/free_busy.rb
|
136
|
+
- lib/google_oauth/calendar/setting.rb
|
137
|
+
- lib/google_oauth/client.rb
|
138
|
+
- lib/google_oauth/contacts.rb
|
139
|
+
- lib/google_oauth/document.rb
|
140
|
+
- lib/google_oauth/mail.rb
|
141
|
+
- spec/google-oauth_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
homepage: http://github.com/kimyoutora/google-oauth
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ! '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
hash: -4368882402596796900
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 1.8.24
|
168
|
+
signing_key:
|
169
|
+
specification_version: 3
|
170
|
+
summary: Ruby wrapper for the various Google OAuth 2 APIs
|
171
|
+
test_files: []
|