Hi Everyone, Im trying to create an application in ruby that can
create events and documents in a google account, so im using devise +
omniauth and google hybrid protocol to get the token so i can use
gcal4ruby gem but i keep coming with this error : "undefined method
`GData4RubyService=' for #<GCal4Ruby::Service:0xaaec748
@gdata_version="2.1"> " my code is like this :
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
and my calendar gcal controller is like this :
class GcalController < ApplicationController
include GCal4Ruby
def index
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@account.check_public = false
@calendars = @account.calendars
@events = @account.events
@account.check_public = true
end
def events
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@calendar = Calendar.find(@account, {:id => params[:calendar_id]})
@calendars = []
@events = @calendar.events
end
def view
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = Event.find(@account, {:id => params[:event_id]})
@minutes = 5.upto(200).collect{|m| [m.to_s] }
end
def edit
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = Event.find(@account, {:id => params[:event_id]})
end
def new
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = Event.new(@account)
end
def save
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = (params[:event_id] and params[:event_id] != '') ?
Event.find(@account, {:id => params[:event_id]}) : Event.new(@account)
if not @event.calendar
@event.calendar = Calendar.find(@account, {:id =>
params[:calendar_id]})
end
if params[:recurrence] == '1'
@event.recurrence = Recurrence.new
@event.recurrence.start_time =
Time.parse(params[:recurrence_start])
@event.recurrence.end_time = Time.parse(params[:recurrence_end])
@event.recurrence.frequency = {params[:recurrence_freq] =>
[params[:recurrence_on]]}
@event.recurrence.repeat_until =
(Date.parse(params[:recurrence_until]))
end
params[:event].each do |key, value|
@event.send("#{key}=", value)
end
if @event.save
flash[:notice] = "Event updated"
else
flash[:warning] = "Could not update event"
end
redirect_to :action => :view, :event_id => @
event.id
end
def delete_event
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = Event.find(@account, {:id => params[:event_id]})
if @event.delete
flash[:notice] = 'Event successfully deleted'
else
flash[:warning] = 'Could not delete event!'
end
redirect_to request.referer
end
def remove_reminder
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = Event.find(@account, {:id => params[:event_id]})
@event.reminder.delete_if do |r|
if r[:method] == params[:method]
if r[:method] == 'none' or r[:minutes] == params[:minutes]
true
else
false
end
end
end
if @event.save
flash[:notice] = 'Reminder deleted'
else
flash[:warning] = 'Could not delete reminder'
end
redirect_to :action => :view, :event_id => @
event.id
end
def add_recurrence
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = Event.find(@account, {:id => params[:event_id]})
@event.reminder << if params[:method] != 'none'
{:method => params[:method], :minutes => params[:minutes]}
else
{:method => 'none'}
end
if @event.save
flash[:notice] = 'Reminder added'
else
flash[:warning] = 'Could not add reminder'
end
redirect_to :action => :view, :event_id => @
event.id
end
def remove_attendee
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = Event.find(@account, {:id => params[:event_id]})
@event.attendees.delete_if do |a|
if a[:email] == params[:email]
logger.info 'deleting attendee'
true
else
logger.info "dont delete attendee #{a[:email]} !=
#{params[:email]}"
false
end
end
if @event.save
flash[:notice] = 'Attendee deleted'
else
flash[:warning] = 'Could not delete attendee'
end
redirect_to :action => :view, :event_id => @
event.id
end
def add_attendee
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@event = Event.find(@account, {:id => params[:event_id]})
@event.attendees << {:email => params[:email], :name =>
params[:name]}
if @event.save
flash[:notice] = 'Attendee added'
else
flash[:warning] = 'Could not add attendee'
end
redirect_to :action => :view, :event_id => @
event.id
end
def save_calendar
cal = Calendar.new(@account, {:title => params[:title]})
if cal.save
flash[:notice] = 'Calendar saved!'
else
flash[:warning] = 'Could not save calendar!'
end
redirect_to :action => :index
end
def delete_calendar
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@calendar = Calendar.find(@account, {:id => params[:calendar_id]})
if @calendar.delete
flash[:notice] = 'Calendar Deleted'
else
flash[:warning] = 'Couldn\'t delete calendar'
end
redirect_to request.referer
end
def search
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
if params[:search]
@account.check_public = false
@events = []
args = {}
args['start-min'] = Time.parse(params[:start]).utc.xmlschema if
params[:start] and params[:start] != ''
args['start-max'] = Time.parse(params[:end]).utc.xmlschema if
params[:end] and params[:end] != ''
args[:calendar] = params[:calendar_id] if params[:calendar_id] !
= 'All'
@events = Event.find(@account, params[:term], args)
@account.check_public = true
render :action => :search_results and return
else
@account.check_public = false
@calendars = @account.calendars
@account.check_public = true
end
end
def iframe_test
@account = Service.new({:GData4RubyService => :OAuthService})
my_oauth_token = omniauth['user_info']['token']
@account.authenticate({:access_token=>my_oauth_token})
@calendar = @account.calendars.first
end
end
please help me im stuck with this like two weeks now, thank you in
advance.