Class: GoogleAppsApi::Calendar::Api
- Inherits:
-
BaseApi
- Object
- BaseApi
- GoogleAppsApi::Calendar::Api
- Defined in:
- lib/google_apps_api/calendar.rb
Instance Attribute Summary (collapse)
-
- (Object) token
readonly
Returns the value of attribute token.
Attributes inherited from BaseApi
Instance Method Summary (collapse)
- - (Object) add_calendar_to_user(calendar, user, *args)
-
- (Object) create_calendar_acl(acl, *args)
generally, use set_calendar_acl, it works for both creates and updates this will throw an exception "Version Conflict" if it already exists.
-
- (Api) initialize(*args)
constructor
A new instance of Api.
-
- (Object) remove_calendar_acl(acl, *args)
you can substitute set_calendar_acl with role set to none.
- - (Object) remove_calendar_from_user(calendar, user, *args)
-
- (Object) retrieve_acls_for_calendar(calendar, *args)
returns array of acls for a given calendar.
-
- (Object) retrieve_calendar_for_user(calendar, user, *args)
lists all calendards for a user.
-
- (Object) retrieve_calendars_for_user(user, *args)
lists all calendards for a user.
-
- (Object) set_calendar_acl(acl, *args)
updates a given acl for a given scope.
- - (Object) set_calendar_for_user(calendar, user, *args)
- - (Object) update_calendar_for_user(calendar, user, *args)
Methods inherited from BaseApi
Constructor Details
- (Api) initialize(*args)
A new instance of Api
9 10 11 |
# File 'lib/google_apps_api/calendar.rb', line 9 def initialize(*args) super(:calendar, *args) end |
Instance Attribute Details
- (Object) token (readonly)
Returns the value of attribute token
7 8 9 |
# File 'lib/google_apps_api/calendar.rb', line 7 def token @token end |
Instance Method Details
- (Object) add_calendar_to_user(calendar, user, *args)
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/google_apps_api/calendar.rb', line 48 def add_calendar_to_user(calendar, user, *args) req = <<-DESCXML <entry xmlns='http://www.w3.org/2005/Atom'> <id>#{calendar.full_id_escaped}</id> </entry> DESCXML = args..merge(:username => user.full_id_escaped, :body => req.strip) request(:add_calendar_to_user, ) end |
- (Object) create_calendar_acl(acl, *args)
generally, use set_calendar_acl, it works for both creates and updates this will throw an exception "Version Conflict" if it already exists
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/google_apps_api/calendar.rb', line 132 def create_calendar_acl(acl, *args) req = <<-DESCXML <?xml version="1.0" encoding="UTF-8"?> <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gAcl='http://schemas.google.com/acl/2007'> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/acl/2007#accessRule'/> <gAcl:scope type='#{acl.scope.kind}' value='#{acl.scope.full_id}'></gAcl:scope> <gAcl:role value='http://schemas.google.com/gCal/2005##{acl.role}'> </gAcl:role> </entry> DESCXML = args..merge(:calendar => acl.calendar.full_id_escaped, :body => req.strip) request(:create_calendar_acl, ) end |
- (Object) remove_calendar_acl(acl, *args)
you can substitute set_calendar_acl with role set to none
149 150 151 152 |
# File 'lib/google_apps_api/calendar.rb', line 149 def remove_calendar_acl(acl, *args) = args..merge(:calendar => acl.calendar.full_id_escaped, :scope => acl.scope.qualified_id_escaped) request(:remove_calendar_acl, ) end |
- (Object) remove_calendar_from_user(calendar, user, *args)
60 61 62 63 |
# File 'lib/google_apps_api/calendar.rb', line 60 def remove_calendar_from_user(calendar, user, *args) = args..merge(:username => user.full_id_escaped, :calendar => calendar.full_id_escaped) request(:remove_calendar_from_user, ) end |
- (Object) retrieve_acls_for_calendar(calendar, *args)
returns array of acls for a given calendar
124 125 126 127 |
# File 'lib/google_apps_api/calendar.rb', line 124 def retrieve_acls_for_calendar(calendar, *args) = args..merge(:calendar => calendar.full_id_escaped) request(:retrieve_acls_for_calendar, ) end |
- (Object) retrieve_calendar_for_user(calendar, user, *args)
lists all calendards for a user
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/google_apps_api/calendar.rb', line 106 def retrieve_calendar_for_user(calendar, user, *args) = args..merge(:calendar => calendar.full_id_escaped, :username => user.full_id_escaped) retries = [:retries] || 5 while (retries > 0) begin return request(:retrieve_calendar_for_user, ) rescue GDataError => g retries -= 1 sleep 0.5 end end return nil end |
- (Object) retrieve_calendars_for_user(user, *args)
lists all calendards for a user
100 101 102 103 |
# File 'lib/google_apps_api/calendar.rb', line 100 def retrieve_calendars_for_user(user, *args) = args..merge(:username => user.full_id_escaped) request(:retrieve_calendars_for_user, ) end |
- (Object) set_calendar_acl(acl, *args)
updates a given acl for a given scope
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/google_apps_api/calendar.rb', line 156 def set_calendar_acl(acl, *args) req = <<-DESCXML <?xml version="1.0" encoding="UTF-8"?> <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gAcl='http://schemas.google.com/acl/2007' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"DU4ERH47eCp7ImA9WxRVEkQ."'> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/acl/2007#accessRule'/> <gAcl:scope type='#{acl.scope.kind}' value='#{acl.scope.full_id}'></gAcl:scope> <gAcl:role value='#{acl.role_schema}'> </gAcl:role> </entry> DESCXML = args..merge(:calendar => acl.calendar.full_id_escaped, :scope => acl.scope.qualified_id_escaped, :body => req.strip) request(:set_calendar_acl, ) end |
- (Object) set_calendar_for_user(calendar, user, *args)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/google_apps_api/calendar.rb', line 13 def set_calendar_for_user(calendar, user, *args) = args. existing_acl = "none" need_to_create = false cal = retrieve_calendar_for_user(calendar, user) if cal existing_acl = cal.details[:accesslevel] else need_to_create = true end acl = .delete(:accesslevel) || existing_acl if need_to_create raise "Must set accesslevel for a newly added calendar" unless acl owner_acl = CalendarAcl.new(:calendar => calendar, :scope => user, :role => "owner") set_calendar_acl(owner_acl) add_calendar_to_user(calendar, user) end if acl == "none" remove_calendar_from_user(calendar, user) unless existing_acl == "none" else if acl != existing_acl set_calendar_acl(CalendarAcl.new(:calendar => calendar, :scope => user, :role => acl)) end update_calendar_for_user(calendar, user, ) unless .empty? end end |
- (Object) update_calendar_for_user(calendar, user, *args)
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/google_apps_api/calendar.rb', line 66 def update_calendar_for_user(calendar, user, *args) username = user.full_id_escaped cal = nil cal = retrieve_calendar_for_user(calendar, user) cal_id = cal.full_id_escaped = args..merge(:username => username, :calendar => cal_id) details = cal.details.merge() req = <<-DESCXML <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gCal='http://schemas.google.com/gCal/2005' xmlns:gd='http://schemas.google.com/g/2005'> <id>http://www.google.com/calendar/feeds/#{username}/allcalendars/full/#{cal_id}</id> <title type='text'>#{details[:title]}</title> <summary type='text'>#{details[:summary]}</summary> <gCal:timezone value='#{details[:timezone]}'/> <gCal:hidden value='#{details[:hidden].to_s}'/> <gCal:color value='#{details[:color]}'/> <gCal:selected value='#{details[:selected].to_s}'/> <gd:where valueString='#{details[:where]}'/> </entry> DESCXML [:body] = req.strip request(:update_calendar_for_user, ) end |