Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ gem 'devise'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'devise_invitable'

gem 'googleauth'
gem 'google-api-client'
197 changes: 121 additions & 76 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,84 +27,113 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.4.0)
arel (5.0.1.20140414130214)
autodoc (0.5.2)
autodoc (0.6.0)
actionpack
activesupport (>= 3.0.0)
rspec
awesome_nested_set (3.0.2)
activerecord (>= 4.0.0, < 5)
awesome_nested_set (3.1.1)
activerecord (>= 4.0.0, < 5.1)
bcrypt (3.1.11)
bootstrap3-datetimepicker-rails (4.0.0)
bootstrap3-datetimepicker-rails (4.17.42)
momentjs-rails (>= 2.8.1)
builder (3.2.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.3.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.8.0)
coffee-script-source (1.10.0)
commonjs (0.2.7)
devise (4.2.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.1)
responders
warden (~> 1.2.3)
devise_invitable (1.6.0)
actionmailer (>= 3.2.6)
devise (>= 3.2.0)
devise_invitable (1.7.0)
actionmailer (>= 4.0.0)
devise (>= 4.0.0)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.2.2)
factory_girl (4.5.0)
execjs (2.7.0)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
railties (>= 3.0.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
fullcalendar-rails (2.2.2.0)
fullcalendar-rails (2.4.0.0)
jquery-rails (>= 3.1.1, < 5.0.0)
momentjs-rails (~> 2.8, >= 2.8.3)
hashie (3.4.4)
momentjs-rails (>= 2.9.0)
google-api-client (0.9.15)
addressable (~> 2.3)
googleauth (~> 0.5)
httpclient (~> 2.7)
hurley (~> 0.1)
memoist (~> 0.11)
mime-types (>= 1.6)
representable (~> 2.3.0)
retriable (~> 2.0)
googleauth (0.5.1)
faraday (~> 0.9)
jwt (~> 1.4)
logging (~> 2.0)
memoist (~> 0.12)
multi_json (~> 1.11)
os (~> 0.9)
signet (~> 0.7)
hashie (3.4.6)
hike (1.2.3)
i18n (0.6.11)
icalendar (2.2.2)
jbuilder (2.2.5)
activesupport (>= 3.0.0, < 5)
httpclient (2.8.2.4)
hurley (0.2)
i18n (0.7.0)
icalendar (2.4.1)
jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jquery-rails (3.1.2)
jquery-rails (3.1.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.3)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
json (1.8.1)
jwt (1.5.4)
kaminari (0.16.3)
json (1.8.3)
jwt (1.5.6)
kaminari (0.17.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
knockoutjs-rails (3.3.0.1)
railties (>= 3.1, < 5)
knockoutjs-rails (3.4.0.1)
railties (>= 3.1, < 6)
less (2.6.0)
commonjs (~> 0.2.7)
less-rails (2.6.0)
actionpack (>= 3.1)
less-rails (2.7.1)
actionpack (>= 4.0)
less (~> 2.6.0)
libv8 (3.16.14.7)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
mini_portile (0.6.2)
minitest (5.4.3)
momentjs-rails (2.8.3)
sprockets (> 2, < 4)
tilt
libv8 (3.16.14.15)
little-plugger (1.1.4)
logging (2.1.0)
little-plugger (~> 1.1)
multi_json (~> 1.10)
mail (2.6.4)
mime-types (>= 1.16, < 4)
memoist (0.15.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.1)
momentjs-rails (2.15.1)
railties (>= 3.1)
multi_json (1.10.1)
multi_json (1.12.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
oauth2 (1.2.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
Expand All @@ -123,8 +152,9 @@ GEM
oauth2 (~> 1.0)
omniauth (~> 1.2)
orm_adapter (0.5.0)
rack (1.5.2)
rack-test (0.6.2)
os (0.9.6)
rack (1.5.5)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.1.8)
actionmailer (= 4.1.8)
Expand All @@ -141,32 +171,36 @@ GEM
activesupport (= 4.1.8)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.0)
rdoc (4.1.2)
rake (11.3.0)
rdoc (4.2.2)
json (~> 1.4)
ref (1.0.5)
ref (2.0.0)
representable (2.3.0)
uber (~> 0.0.7)
responders (1.1.2)
railties (>= 3.2, < 4.2)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
retriable (2.1.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
rspec-support (~> 3.5.0)
rspec-rails (3.5.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
sass (3.2.19)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
Expand All @@ -177,35 +211,41 @@ GEM
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
settingslogic (2.0.9)
spring (1.2.0)
sprockets (2.12.3)
signet (0.7.3)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (~> 1.5)
multi_json (~> 1.10)
spring (1.7.2)
sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.1)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10)
therubyracer (0.12.1)
sqlite3 (1.3.11)
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thor (0.19.1)
thread_safe (0.3.4)
thread_safe (0.3.5)
tilt (1.4.1)
turbolinks (2.5.2)
coffee-rails
twitter-bootstrap-rails (3.2.0)
actionpack (~> 4.1)
execjs (~> 2.2)
rails (~> 4.1)
railties (~> 4.1)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.0)
twitter-bootstrap-rails (3.2.2)
actionpack (>= 3.1)
execjs (>= 2.2.2, >= 2.2)
less-rails (>= 2.5.0)
railties (>= 3.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
uber (0.0.15)
uglifier (3.0.2)
execjs (>= 0.3.0, < 3)
warden (1.2.6)
rack (>= 1.0)

Expand All @@ -221,6 +261,8 @@ DEPENDENCIES
devise_invitable
factory_girl_rails
fullcalendar-rails
google-api-client
googleauth
icalendar
jbuilder (~> 2.0)
jquery-rails
Expand All @@ -242,3 +284,6 @@ DEPENDENCIES
turbolinks
twitter-bootstrap-rails
uglifier (>= 1.3.0)

BUNDLED WITH
1.12.5
2 changes: 1 addition & 1 deletion app/assets/javascripts/events.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fullCalendar = ->
month: 'HH:mm'
week: 'HH:mm'
day: 'HH:mm'
events: '/events.json'
events: '/events/fetch'

eventClick:
(calEvent) ->
Expand Down
63 changes: 63 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
require 'date'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'google/api_client/client_secrets'
require 'google/apis/calendar_v3'
require 'json'
require 'yaml'

class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy]
Expand Down Expand Up @@ -116,7 +122,64 @@ def ajax_create_event_from_old_event
end
end

def fetch
#config = YML.load_file('~/.config/camome/config.yml')
@user_id = "*************"
@calendar_ids = [@user_id]
@client_id = ApplicationSettings.oauth.google.application_id
@client_secret = ApplicationSettings.oauth.google.application_secret
@oob_url = 'urn:ietf:wg:oauth:2.0:oob'

collection = []
timeMax = Time.parse(params["end"]).iso8601
timeMin = Time.parse(params["start"]).iso8601
@calendar_ids.each do |calendar_id|
response = get_events(timeMax, timeMin, calendar_id)
response.items.each do |item|
collection << {title: item.summary, start: item.start.date, end: item.end.date}
end
end
render json: collection
end

private

def get_events(timeMax, timeMin, calendar_id)
params = {:order_by => "startTime", :single_events => "true", :show_deleted => "false", :time_max => timeMax, :time_min => timeMin}
return google_calendar_api(params, calendar_id)
end

def authorize
dir_path = "~/.config/camome"
client_id = Google::Auth::ClientId.new(@client_id, @client_secret)
token_store = Google::Auth::Stores::FileTokenStore.new(
file: File.expand_path("#{dir_path}/google_access_tokens.yml", __FILE__))
scope = 'https://www.googleapis.com/auth/calendar'
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)

credentials = authorizer.get_credentials(@user_id)
if credentials.nil?
url = authorizer.get_authorization_url(
base_url: @oob_url)
puts "Open the following URL in the browser and enter the " +
"resulting code after authorization"
puts url
code = STDIN.gets.chomp
credentials = authorizer.get_and_store_credentials_from_code(
user_id: @user_id, code: code, base_url: @oob_url)
end
return credentials
end

def google_calendar_api(params, calendar_id)
service = Google::Apis::CalendarV3::CalendarService.new
service.client_options.application_name = @application_name
service.authorization = authorize()
service.authorization.refresh!
response = service.list_events(calendar_id, order_by: params[:order_by], show_deleted: params[:show_deleted], single_events: params[:single_events], time_max: params[:time_max], time_min: params[:time_min])
return response
end

# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find(params[:id])
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_calendar_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="external-calendars">
<% User.current.calendars.each do |c| %>
<% current_user.calendars.each do |c| %>
<div>
<font color=<%= c.color %>>■</font><%= c.displayname %>
</div>
Expand Down
Loading