Skip to content

Commit

Permalink
Work on debugging and check_public
Browse files Browse the repository at this point in the history
  • Loading branch information
edave committed Dec 11, 2010
1 parent dbd6976 commit 8453ccf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
13 changes: 7 additions & 6 deletions lib/gcal4ruby/calendar.rb
Expand Up @@ -97,10 +97,11 @@ def initialize(service, attributes = {})
@color ||= "#2952A3"
@where ||= ""
attributes.each do |key, value|
if self.respond_to("#{key}=")
if self.respond_to?("#{key}=")
self.send("#{key}=", value)
end
end
@debug ||= false
return true
end

Expand All @@ -118,7 +119,7 @@ def public?
#Returns an array of Event objects corresponding to each event in the calendar.
def events
events = []
ret = @service.send_request(GData4Ruby::Request.new(:get, @content_uri))
ret = service.send_request(GData4Ruby::Request.new(:get, @content_uri))
REXML::Document.new(ret.body).root.elements.each("entry"){}.map do |entry|
entry = GData4Ruby::Utils.add_namespaces(entry)
e = Event.new(service)
Expand All @@ -136,12 +137,12 @@ def save
ret = super
return ret if public == @public
if public
puts 'setting calendar to public' if service.debug
rule = GData4Ruby::ACL::AccessRule.new(service, self)
log('setting calendar to public')
rule = GData4Ruby::ACL::AccessRule.new(service.gdata_service, self)
rule.role = 'http://schemas.google.com/gCal/2005#read'
rule.save
else
rule = GData4Ruby::ACL::AccessRule.find(service, self, {:user => 'default'})
rule = GData4Ruby::ACL::AccessRule.find(service.gdata_service, self, {:user => 'default'})
rule.delete if rule
end
reload
Expand Down Expand Up @@ -259,7 +260,7 @@ def load(string)
end
end

if @service.check_public
if service.check_public
log("Getting ACL Feed")

# If the ACL URI doesn't exist, then its definitely not public
Expand Down
15 changes: 9 additions & 6 deletions lib/gcal4ruby/service.rb
Expand Up @@ -61,13 +61,12 @@ def initialize(attributes = {}, service = nil)
# Otherwise use the default service
@gdata_service ||= GData4Ruby::Service.new(attributes)
attributes.each do |key, value|
if self.respond_to?(key)
if self.respond_to?("#{key}=")
self.send("#{key}=", value)
end
end
@check_public ||= true
@account ||= "default"
@debug ||= false
log("Check Public: #{check_public}")
end

def debug
Expand All @@ -79,6 +78,10 @@ def debug=(value)
@gdata_service.debug = value
end

def log(string)
puts string if self.debug
end

def default_event_feed
return create_url("www.google.com/calendar/feeds/#{@account}/private/full")
end
Expand Down Expand Up @@ -111,11 +114,11 @@ def send_request(request)
#Returns an array of Calendar objects for each calendar associated with
#the authenticated account.
def calendars
ret = @gdata_service.send_request(GData4Ruby::Request.new(:get, create_url(@@calendar_list_feed), nil, {"max-results" => "10000"}))
ret = send_request(GData4Ruby::Request.new(:get, create_url(@@calendar_list_feed), nil, {"max-results" => "10000"}))
cals = []
REXML::Document.new(ret.body).root.elements.each("entry"){}.map do |entry|
entry = GData4Ruby::Utils.add_namespaces(entry)
cal = Calendar.new(self)
cal = Calendar.new(self, {:debug => debug})
cal.load(entry.to_s)
cals << cal
end
Expand All @@ -128,7 +131,7 @@ def events
events = []
REXML::Document.new(ret.body).root.elements.each("entry"){}.map do |entry|
entry = GData4Ruby::Utils.add_namespaces(entry)
event = Event.new(self)
event = Event.new(self, {:debug => debug})
event.load(entry.to_s)
events << event
end
Expand Down

0 comments on commit 8453ccf

Please sign in to comment.