google_apps_api 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{google_apps_api}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Stuart"]
@@ -13,6 +13,11 @@ module GoogleAppsApi #:nodoc:
13
13
  def set_calendar_for_user(calendar, user, *args)
14
14
  options = args.extract_options!
15
15
 
16
+ acl_ranking = ["none", "freebusy", "read", "editor", "owner", "root"]
17
+ acl_comparison = options.delete(:acl_comparison) || :set
18
+
19
+ do_not_subscribe = options.delete(:do_not_subscribe) || false
20
+
16
21
  existing_acl = "none"
17
22
  need_to_create = false
18
23
 
@@ -23,13 +28,16 @@ module GoogleAppsApi #:nodoc:
23
28
  need_to_create = true
24
29
  end
25
30
 
31
+ existing_acl_rank = acl_ranking.index(existing_acl) || raise("invalid existing acl")
32
+
26
33
  acl = options.delete(:accesslevel) || existing_acl
27
-
34
+ acl_rank = acl_ranking.index(acl) || raise("new acl invalid")
35
+
28
36
  if need_to_create
29
37
  raise "Must set accesslevel for a newly added calendar" unless acl
30
38
  owner_acl = CalendarAcl.new(:calendar => calendar, :scope => user, :role => "owner")
31
39
  set_calendar_acl(owner_acl)
32
- add_calendar_to_user(calendar, user)
40
+ add_calendar_to_user(calendar, user) unless do_not_subscribe
33
41
 
34
42
  end
35
43
 
@@ -37,10 +45,19 @@ module GoogleAppsApi #:nodoc:
37
45
  remove_calendar_from_user(calendar, user) unless existing_acl == "none"
38
46
  else
39
47
 
40
- if acl != existing_acl
41
- set_calendar_acl(CalendarAcl.new(:calendar => calendar, :scope => user, :role => acl))
48
+ set_acl = case acl_comparison
49
+ when :set
50
+ true
51
+ when :set_if_higher
52
+ acl_rank > existing_acl_rank
53
+ when :set_if_lower
54
+ acl_rank < existing_acl_rank
42
55
  end
43
- update_calendar_for_user(calendar, user, options) unless options.empty?
56
+
57
+
58
+ set_calendar_acl(CalendarAcl.new(:calendar => calendar, :scope => user, :role => acl)) if set_acl
59
+
60
+ update_calendar_for_user(calendar, user, options) unless options.empty? unless do_not_subscribe && need_to_create
44
61
 
45
62
  end
46
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_apps_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stuart