google_apps 0.4.9.2 → 0.4.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/google_apps.rb +0 -1
- data/lib/google_apps/atom/atom.rb +6 -0
- data/lib/google_apps/atom/document.rb +53 -5
- data/lib/google_apps/atom/feed.rb +10 -4
- data/lib/google_apps/atom/group.rb +1 -12
- data/lib/google_apps/atom/group_member.rb +45 -20
- data/lib/google_apps/atom/message_attributes.rb +3 -1
- data/lib/google_apps/atom/node.rb +19 -0
- data/lib/google_apps/atom/user.rb +0 -12
- data/lib/google_apps/transport.rb +27 -2
- metadata +2 -3
- data/lib/google_apps/atom/message.rb +0 -21
data/lib/google_apps.rb
CHANGED
@@ -9,7 +9,6 @@ require 'google_apps/atom/user'
|
|
9
9
|
require 'google_apps/atom/group'
|
10
10
|
require 'google_apps/atom/public_key'
|
11
11
|
require 'google_apps/atom/export'
|
12
|
-
require 'google_apps/atom/message'
|
13
12
|
require 'google_apps/atom/message_attributes'
|
14
13
|
require 'google_apps/atom/group_member'
|
15
14
|
require 'google_apps/atom/nickname'
|
@@ -44,16 +44,49 @@ module GoogleApps
|
|
44
44
|
# internal consistency in the object.
|
45
45
|
#
|
46
46
|
# find_values
|
47
|
-
def find_values
|
47
|
+
def find_values
|
48
48
|
map_key = self.class.to_s.split(':').last.downcase.to_sym
|
49
49
|
map = Atom::MAPS[map_key]
|
50
50
|
|
51
51
|
@document.root.each do |entry|
|
52
52
|
intersect = map.keys & entry.attributes.to_h.keys.map(&:to_sym)
|
53
|
-
unless intersect.empty?
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
set_instances(intersect, entry, map) unless intersect.empty?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# Sets instance variables in the current object based on
|
59
|
+
# values found in the XML document and the mapping specified
|
60
|
+
# in GoogleApps::Atom::MAPS
|
61
|
+
|
62
|
+
#
|
63
|
+
# @param [Array] intersect
|
64
|
+
# @param [LibXML::XML::Node] node
|
65
|
+
# @param [Hash] map
|
66
|
+
#
|
67
|
+
# @visibility public
|
68
|
+
# @return
|
69
|
+
def set_instances(intersect, node, map)
|
70
|
+
intersect.each do |attribute|
|
71
|
+
instance_variable_set "@#{map[attribute]}", check_value(node.attributes[attribute])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
#
|
77
|
+
|
78
|
+
# Sets instance variables for property list type documents.
|
79
|
+
#
|
80
|
+
# @visibility public
|
81
|
+
# @return
|
82
|
+
def attrs_from_props
|
83
|
+
map_key = self.class.to_s.split(':').last.downcase.to_sym
|
84
|
+
map = Atom::MAPS[map_key]
|
85
|
+
|
86
|
+
@document.find('//apps:property').each do |entry|
|
87
|
+
prop_name = entry.attributes['name'].to_sym
|
88
|
+
if map.keys.include?(prop_name)
|
89
|
+
instance_variable_set "@#{map[prop_name]}", check_value(entry.attributes['value'])
|
57
90
|
end
|
58
91
|
end
|
59
92
|
end
|
@@ -115,6 +148,21 @@ module GoogleApps
|
|
115
148
|
|
116
149
|
ns
|
117
150
|
end
|
151
|
+
|
152
|
+
|
153
|
+
#
|
154
|
+
# Delete a node from the document
|
155
|
+
#
|
156
|
+
# @param [String] xpath is a node identifier in Xpath format
|
157
|
+
# @param [Array] attrs is an array of attr, value pairs
|
158
|
+
#
|
159
|
+
# @visibility public
|
160
|
+
# @return
|
161
|
+
def delete_node(xpath, attrs)
|
162
|
+
@document.find(xpath).each do |node|
|
163
|
+
node.remove! if node_match?(node, attrs)
|
164
|
+
end
|
165
|
+
end
|
118
166
|
end
|
119
167
|
end
|
120
168
|
end
|
@@ -8,12 +8,18 @@ module GoogleApps
|
|
8
8
|
|
9
9
|
attr_reader :xml, :items, :next_page
|
10
10
|
|
11
|
-
|
12
|
-
#
|
11
|
+
# TODO: Figure out how to handle Group Members. The regex below
|
12
|
+
# doesn't work in that case as group members also have group in
|
13
|
+
# the id url.
|
14
|
+
TYPE_MATCH = /<id.*(user|group.*member|nickname|group).*?<\/id/
|
15
|
+
|
13
16
|
|
14
17
|
def initialize(xml)
|
18
|
+
type = xml.match(TYPE_MATCH).captures[0]
|
19
|
+
type.sub!(/\//, '_')
|
20
|
+
|
15
21
|
@xml = parse(xml)
|
16
|
-
@items = entries_from document: @xml, type:
|
22
|
+
@items = entries_from document: @xml, type: type, entry_tag: 'entry'
|
17
23
|
end
|
18
24
|
|
19
25
|
# TODO: Need to make sure this works for feeds other than user.
|
@@ -74,7 +80,7 @@ module GoogleApps
|
|
74
80
|
#
|
75
81
|
# add_category returns the modified content_array
|
76
82
|
def add_category(content_array, type)
|
77
|
-
content_array.unshift(create_node(type: 'atom:category', attrs: Atom::CATEGORY[type.to_sym]).to_s)
|
83
|
+
content_array.unshift(create_node(type: 'atom:category', attrs: Atom::CATEGORY[type.to_sym]).to_s) if Atom::CATEGORY[type.to_sym]
|
78
84
|
end
|
79
85
|
|
80
86
|
|
@@ -11,6 +11,7 @@ module GoogleApps
|
|
11
11
|
def initialize(xml = nil)
|
12
12
|
if xml
|
13
13
|
@document = parse(xml)
|
14
|
+
attrs_from_props
|
14
15
|
else
|
15
16
|
@document = Atom::XML::Document.new
|
16
17
|
@document.root = build_root
|
@@ -97,18 +98,6 @@ module GoogleApps
|
|
97
98
|
private
|
98
99
|
|
99
100
|
|
100
|
-
def check_value(value)
|
101
|
-
case value
|
102
|
-
when 'true'
|
103
|
-
true
|
104
|
-
when 'false'
|
105
|
-
false
|
106
|
-
else
|
107
|
-
value
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
101
|
# prop_name takes a LibXML::XML::Node object and
|
113
102
|
# sets the name attribute based on the provided
|
114
103
|
# key.
|
@@ -4,11 +4,16 @@ module GoogleApps
|
|
4
4
|
include Atom::Node
|
5
5
|
include Atom::Document
|
6
6
|
|
7
|
-
attr_accessor :member
|
7
|
+
attr_accessor :member, :type
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
|
11
|
-
|
9
|
+
def initialize(xml = nil)
|
10
|
+
if xml
|
11
|
+
@document = parse(xml)
|
12
|
+
populate_self
|
13
|
+
else
|
14
|
+
@document = Atom::XML::Document.new
|
15
|
+
@document.root = build_root
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
|
@@ -20,10 +25,21 @@ module GoogleApps
|
|
20
25
|
#
|
21
26
|
# member= returns the value of @member
|
22
27
|
def member=(member)
|
23
|
-
@member.nil? ?
|
28
|
+
@member.nil? ? add_node('memberId', member) : change_node('memberId', member)
|
29
|
+
|
30
|
+
@document = parse(@document)
|
31
|
+
@member = member
|
24
32
|
end
|
25
33
|
|
26
34
|
|
35
|
+
def type=(type)
|
36
|
+
@type.nil? ? add_node('memberType', type) : change_node('memberType', type)
|
37
|
+
|
38
|
+
@document = parse(@document)
|
39
|
+
@type = type
|
40
|
+
end
|
41
|
+
|
42
|
+
|
27
43
|
# to_s returns @document as a string.
|
28
44
|
def to_s
|
29
45
|
@document.to_s
|
@@ -32,20 +48,23 @@ module GoogleApps
|
|
32
48
|
|
33
49
|
private
|
34
50
|
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# value
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
@document.root << create_node(type: 'apps:property', attrs: [['name', 'memberId'], ['value', member]])
|
44
|
-
|
45
|
-
@member = member
|
51
|
+
#
|
52
|
+
# @param [] type
|
53
|
+
# @param [] value
|
54
|
+
#
|
55
|
+
# @visibility private
|
56
|
+
# @return
|
57
|
+
def add_node(type, value)
|
58
|
+
@document.root << create_node(type: 'apps:property', attrs: [['name', type], ['value', value]])
|
46
59
|
end
|
47
60
|
|
48
61
|
|
62
|
+
def change_node(type, value)
|
63
|
+
@document.find('//apps:property').each do |node|
|
64
|
+
node.attributes['value'] = value if node.attributes['name'] == type
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
49
68
|
# change_member changes the value attribute of the
|
50
69
|
# apps:property element in @document to the value
|
51
70
|
# of the provided argument. It also sets @member
|
@@ -64,10 +83,16 @@ module GoogleApps
|
|
64
83
|
@member = member
|
65
84
|
end
|
66
85
|
|
67
|
-
|
68
|
-
#
|
69
|
-
|
70
|
-
|
86
|
+
|
87
|
+
#
|
88
|
+
#
|
89
|
+
# @visibility private
|
90
|
+
# @return
|
91
|
+
def populate_self
|
92
|
+
@document.find('//apps:property').each do |node|
|
93
|
+
@member = node.attributes['value'] if node.attributes['name'] == 'memberId'
|
94
|
+
@type = node.attributes['value'] if node.attributes['name'] == 'memberType'
|
95
|
+
end
|
71
96
|
end
|
72
97
|
end
|
73
98
|
end
|
@@ -24,6 +24,7 @@ module GoogleApps
|
|
24
24
|
property['value'] = prop
|
25
25
|
|
26
26
|
@document.root << property
|
27
|
+
@document = parse(@document)
|
27
28
|
end
|
28
29
|
|
29
30
|
def property=(value)
|
@@ -36,6 +37,7 @@ module GoogleApps
|
|
36
37
|
|
37
38
|
@document.root << label
|
38
39
|
@labels << name
|
40
|
+
@document = parse(@document)
|
39
41
|
end
|
40
42
|
|
41
43
|
def <<(value)
|
@@ -44,7 +46,7 @@ module GoogleApps
|
|
44
46
|
|
45
47
|
def remove_label(value)
|
46
48
|
@labels.delete(value)
|
47
|
-
|
49
|
+
delete_node('//apps:label', labelName: [value])
|
48
50
|
end
|
49
51
|
|
50
52
|
def to_s
|
@@ -104,6 +104,25 @@ module GoogleApps
|
|
104
104
|
values
|
105
105
|
end
|
106
106
|
end
|
107
|
+
|
108
|
+
|
109
|
+
# Returns true if "true" and false if "false"
|
110
|
+
|
111
|
+
#
|
112
|
+
# @param [String] value
|
113
|
+
#
|
114
|
+
# @visibility public
|
115
|
+
# @return
|
116
|
+
def check_value(value)
|
117
|
+
case value
|
118
|
+
when 'true'
|
119
|
+
true
|
120
|
+
when 'false'
|
121
|
+
false
|
122
|
+
else
|
123
|
+
value
|
124
|
+
end
|
125
|
+
end
|
107
126
|
end
|
108
127
|
end
|
109
128
|
end
|
@@ -164,18 +164,6 @@ module GoogleApps
|
|
164
164
|
def new_doc
|
165
165
|
@document = Atom::XML::Document.new
|
166
166
|
end
|
167
|
-
|
168
|
-
|
169
|
-
def check_value(value)
|
170
|
-
case value
|
171
|
-
when 'true'
|
172
|
-
true
|
173
|
-
when 'false'
|
174
|
-
false
|
175
|
-
else
|
176
|
-
value
|
177
|
-
end
|
178
|
-
end
|
179
167
|
end
|
180
168
|
end
|
181
169
|
end
|
@@ -184,11 +184,24 @@ module GoogleApps
|
|
184
184
|
type = normalize_type type
|
185
185
|
|
186
186
|
options[:limit] ? limit = options[:limit] : limit = 1000000
|
187
|
-
options[:start] ? get(instance_variable_get("@#{type}") + "?#{start_query(type)}=#{options[:start]}", :feed) : get(instance_variable_get("@#{type}"), :feed)
|
187
|
+
options[:start] ? get(instance_variable_get("@#{type}") + "#{options[:extra]}" + "?#{start_query(type)}=#{options[:start]}", :feed) : get(instance_variable_get("@#{type}") + "#{options[:extra]}", :feed)
|
188
188
|
|
189
189
|
fetch_feed(page, limit, :feed)
|
190
190
|
|
191
|
-
|
191
|
+
#@response
|
192
|
+
return_all
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
# Retrieves the members of the requested group.
|
197
|
+
#
|
198
|
+
# @param [String] group_id the Group ID in the Google Apps Environment
|
199
|
+
#
|
200
|
+
# @visibility public
|
201
|
+
# @return
|
202
|
+
def get_members_of(group_id, options = {})
|
203
|
+
options[:extra] = "/#{group_id}/member"
|
204
|
+
get_all :groups, options
|
192
205
|
end
|
193
206
|
|
194
207
|
|
@@ -373,6 +386,18 @@ module GoogleApps
|
|
373
386
|
SUCCESS_CODES.include?(@response.code.to_i)
|
374
387
|
end
|
375
388
|
|
389
|
+
|
390
|
+
#
|
391
|
+
# Takes all the items in each feed and puts them into one array.
|
392
|
+
#
|
393
|
+
# @visibility private
|
394
|
+
# @return Array of Documents
|
395
|
+
def return_all
|
396
|
+
@feeds.inject([]) do |results, feed|
|
397
|
+
results | feed.items
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
376
401
|
|
377
402
|
# Grab the auth token from the response body
|
378
403
|
def set_auth_token
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_apps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.9.
|
4
|
+
version: 0.4.9.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: libxml-ruby
|
@@ -40,7 +40,6 @@ files:
|
|
40
40
|
- lib/google_apps/atom/feed.rb
|
41
41
|
- lib/google_apps/atom/group.rb
|
42
42
|
- lib/google_apps/atom/group_member.rb
|
43
|
-
- lib/google_apps/atom/message.rb
|
44
43
|
- lib/google_apps/atom/message_attributes.rb
|
45
44
|
- lib/google_apps/atom/nickname.rb
|
46
45
|
- lib/google_apps/atom/node.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module GoogleApps
|
2
|
-
module Atom
|
3
|
-
class Message
|
4
|
-
def initialize
|
5
|
-
@document = Atom::XML::Document.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def from(filename)
|
9
|
-
message = File.read(filename)
|
10
|
-
@document.root = Atom::XML::Node.new('apps:rfc822Msg', message)
|
11
|
-
Atom::XML::Namespace.new(@document.root, 'apps', 'http://schemas.google.com/apps/2006')
|
12
|
-
|
13
|
-
@document
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
@document.to_s
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|