lib/google_apps/transport.rb in google_apps-0.4.1 vs lib/google_apps/transport.rb in google_apps-0.4.2
- old
+ new
@@ -3,11 +3,11 @@
require 'openssl'
require 'rexml/document'
module GoogleApps
class Transport
- attr_reader :request, :response
+ attr_reader :request, :response, :domain
attr_accessor :auth, :user, :group, :nickname
BOUNDARY = "=AaB03xDFHT8xgg"
def initialize(domain, targets = {})
@@ -16,16 +16,17 @@
@pubkey = targets[:pubkey] || "https://apps-apis.google.com/a/feeds/compliance/audit/publickey/#{domain}"
@migration = targets[:migration] || "https://apps-apis.google.com/a/feeds/migration/2.0/#{domain}"
@group = targets[:group] || "https://apps-apis.google.com/a/feeds/group/2.0/#{domain}"
@nickname = targets[:nickname]
@export = targets[:export] || "https://apps-apis.google.com/a/feeds/compliance/audit/mail/export/#{domain}"
+ @domain = domain
@token = nil
@response = nil
@request = nil
end
-
+
# authenticate will take the provided account and
# password and attempt to authenticate them with
# Google
#
# authenticate 'username@domain', 'password'
@@ -124,10 +125,24 @@
set_headers :user
@response = request(uri)
end
+
+ # add_member_to adds a member to a group in the domain.
+ # It takes a group_id and a GoogleApps::Atom::GroupMember
+ # document as arguments.
+ #
+ # add_member_to 'test', document
+ #
+ # add_member_to returns the response received from Google.
+ def add_member_to(group_id, document)
+ puts @group + "/#{group_id}/member"
+ add(@group + "/#{group_id}/member", document)
+ end
+
+
# add is a generic target for method_missing. It is
# intended to handle the general case of adding
# to the GoogleApps Domain. It takes an API endpoint
# and a GoogleApps::Atom document as arguments.
#
@@ -172,17 +187,17 @@
# delete returns the HTTP response received from Google.
def delete(endpoint, id)
uri = URI(endpoint + "/#{id}")
@request = Net::HTTP::Delete.new(uri.path)
set_headers :user
-
+
@response = request(uri)
end
# migration performs mail migration from a local
# mail environment to GoogleApps. migrate takes a
- # username a GoogleApps::Atom::Properties dcoument
+ # username a GoogleApps::Atom::Properties dcoument
# and the message as plain text (String) as arguments.
#
# migrate 'user', properties, message
#
# migrate returns the HTTP response received from Google.
@@ -250,9 +265,13 @@
case request_type
when :auth
@request['content-type'] = "application/x-www-form-urlencoded"
when :migrate
@request['content-type'] = "multipart/related; boundary=\"#{BOUNDARY}\""
+ @request['authorization'] = "GoogleLogin auth=#{@token}"
+ when :member
+ @request['content-type'] = "application/x-www-form-urlencoded"
+ @request['content-length'] = 0
@request['authorization'] = "GoogleLogin auth=#{@token}"
else
@request['content-type'] = "application/atom+xml"
@request['authorization'] = "GoogleLogin auth=#{@token}"
end
\ No newline at end of file