google_apps 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,15 @@ module GoogleApps
8
8
  add_header
9
9
  end
10
10
 
11
+ # new_user adds the nodes necessary to create a new
12
+ # user in Google Apps. new_user requires a username,
13
+ # first name, last name and password. You can also
14
+ # provide an optional quota argument, this will override
15
+ # the default quota in Google Apps.
16
+ #
17
+ # new_user 'username', 'first_name', 'last_name', 'password', 1024
18
+ #
19
+ # new_user returns the full XML document.
11
20
  def new_user(user_name, first, last, password, quota=nil)
12
21
  new_doc
13
22
  add_header
@@ -18,20 +27,39 @@ module GoogleApps
18
27
  @document
19
28
  end
20
29
 
30
+ # new_doc re-initializes the XML document.
21
31
  def new_doc
22
32
  @document = Atom::XML::Document.new
23
33
  end
24
34
 
25
- def login_node(user_name, password)
35
+ # login_node adds an apps:login attribute to @document.
36
+ # login_node takes a username and password as arguments
37
+ # it is also possible to specify that the account be
38
+ # suspended.
39
+ #
40
+ # login_node 'username', 'password', suspended
41
+ #
42
+ # login_node returns an 'apps:login' LibXML::XML::Node
43
+ def login_node(user_name, password, suspended="false")
44
+ suspended = "true" unless suspended == "false"
26
45
  login = Atom::XML::Node.new('apps:login')
27
46
  login['userName'] = user_name
28
47
  login['password'] = OpenSSL::Digest::SHA1.hexdigest password
29
48
  login['hashFunctionName'] = Atom::HASH_FUNCTION
30
- login['suspended'] = "false"
49
+ login['suspended'] = suspended
31
50
 
32
51
  login
33
52
  end
34
53
 
54
+
55
+ # quota_node adds an apps:quota attribute to @document.
56
+ # quota_node takes an integer value as an argument. This
57
+ # argument translates to the number of megabytes available
58
+ # on the Google side.
59
+ #
60
+ # quota_node 1024
61
+ #
62
+ # quota_node returns an 'apps:quota' LibXML::XML::Node
35
63
  def quota_node(limit)
36
64
  quota = Atom::XML::Node.new('apps:quota')
37
65
  quota['limit'] = limit.to_s
@@ -39,6 +67,12 @@ module GoogleApps
39
67
  quota
40
68
  end
41
69
 
70
+ # name_node adds an apps:name attribute to @document.
71
+ # name_node takes the first and last names as arguments.
72
+ #
73
+ # name_node 'first name', 'last name'
74
+ #
75
+ # name_node returns an apps:name LibXML::XML::Node
42
76
  def name_node(first, last)
43
77
  name = Atom::XML::Node.new('apps:name')
44
78
  name['familyName'] = last
@@ -47,6 +81,7 @@ module GoogleApps
47
81
  name
48
82
  end
49
83
 
84
+ # to_s returns @document as a string
50
85
  def to_s
51
86
  @document.to_s
52
87
  end
@@ -109,6 +109,22 @@ module GoogleApps
109
109
  end
110
110
  end
111
111
 
112
+ # get is a generic target for method_missing. It is
113
+ # intended to handle the general case of retrieving a
114
+ # record from the Google Apps Domain. It takes an API
115
+ # endpoint and an id as arguments.
116
+ #
117
+ # get 'endpoint', 'username'
118
+ #
119
+ # get returns the HTTP response received from Google.
120
+ def get(endpoint, id)
121
+ uri = URI(instance_variable_get("@#{endpoint.to_s}") + "/#{id}")
122
+ @request = Net::HTTP::Get.new(uri.path)
123
+ set_headers :user
124
+
125
+ @response = request(uri)
126
+ end
127
+
112
128
  # add is a generic target for method_missing. It is
113
129
  # intended to handle the general case of adding
114
130
  # to the GoogleApps Domain. It takes an API endpoint
@@ -181,6 +197,8 @@ module GoogleApps
181
197
  self.send(:add, $2, *args)
182
198
  when "delete"
183
199
  self.send(:delete, $2, *args)
200
+ when "get"
201
+ self.send(:get, $2, *args)
184
202
  else
185
203
  super
186
204
  end
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.3.3
4
+ version: 0.3.4
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-03-05 00:00:00.000000000 Z
12
+ date: 2012-03-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Library for interfacing with Google Apps' Domain and Application APIs
15
15
  email: