lib/google_apps/transport.rb in google_apps-0.4.5 vs lib/google_apps/transport.rb in google_apps-0.4.6
- old
+ new
@@ -4,21 +4,21 @@
require 'rexml/document'
module GoogleApps
class Transport
attr_reader :request, :response, :domain
- attr_accessor :auth, :user, :group, :nickname
+ attr_accessor :auth, :user, :group, :nickname, :export
BOUNDARY = "=AaB03xDFHT8xgg"
def initialize(domain, targets = {})
@auth = targets[:auth] || "https://www.google.com/accounts/ClientLogin"
@user = targets[:user] || "https://apps-apis.google.com/a/feeds/#{domain}/user/2.0"
@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]
+ @nickname = targets[:nickname] || "https://apps-apis.google.com/a/feeds/#{domain}/nickname/2.0"
@export = targets[:export] || "https://apps-apis.google.com/a/feeds/compliance/audit/mail/export/#{domain}"
@domain = domain
@token = nil
@response = nil
@request = nil
@@ -37,11 +37,11 @@
uri = URI(@auth)
@request = Net::HTTP::Post.new(uri.path)
@request.body = auth_body(account, pass)
set_headers :auth
- @response = request(uri)
+ @response = request uri
set_auth_token
@response
end
@@ -54,33 +54,23 @@
# request_export 'username', document
#
# request_export returns the HTTP response received
# from Google.
def request_export(username, document)
- uri = URI(@export + "/#{username}")
- @request = Net::HTTP::Post.new uri.path
- @request.body = document.to_s
- set_headers :user
-
- @response = request(uri)
+ add(@export + "/#{username}", document)
end
# export_status checks the status of a mailbox export
# request. It takes the username and the request_id
# as arguments
#
# export_status 'username', 847576
#
- # export_status will return the body of the HTTP
+ # export_status will return the status of the HTTP
# response from Google
def export_status(username, req_id)
- uri = URI(@export + "/#{username}/#{req_id}")
- @request = Net::HTTP::Get.new uri.path
- set_headers :user
-
- # TODO: Return actual status not whole body.
- (@response = request(uri)).body
+ get(@export + "/#{username}", req_id)
end
def fetch_export(username, req_id, filename) # :nodoc:
# TODO: Shouldn't rely on export_status being run first. Self, this is lazy and stupid.
export_status(username, req_id)
@@ -122,11 +112,11 @@
id ? uri = URI(endpoint + "/#{id}") : uri = URI(endpoint)
#uri = URI(instance_variable_get("@#{endpoint.to_s}") + "/#{id}")
@request = Net::HTTP::Get.new(uri.path)
set_headers :user
- @response = request(uri)
+ @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
@@ -163,11 +153,11 @@
uri = URI(endpoint)
@request = Net::HTTP::Post.new(uri.path)
@request.body = document.to_s
set_headers :user
- @response = request(uri)
+ @response = request uri
end
# update is a generic target for method_missing. It is
# intended to handle the general case of updating an
# item that already exists in your GoogleApps Domain.
@@ -182,11 +172,11 @@
uri = URI(endpoint + "/#{target}")
@request = Net::HTTP::Put.new(uri.path)
@request.body = document.to_s
set_headers :user
- @response = request(uri)
+ @response = request uri
end
# delete is a generic target for method_missing. It is
# intended to handle the general case of deleting an
# item from your GoogleApps Domain. delete takes an
@@ -198,11 +188,11 @@
def delete(endpoint, id)
uri = URI(endpoint + "/#{id}")
@request = Net::HTTP::Delete.new(uri.path)
set_headers :user
- @response = request(uri)
+ @response = request uri
end
# migration performs mail migration from a local
# mail environment to GoogleApps. migrate takes a
# username a GoogleApps::Atom::Properties dcoument
@@ -215,10 +205,10 @@
uri = URI(@migration + "/#{username}/mail")
@request = Net::HTTP::Post.new(uri.path)
@request.body = multi_part(properties.to_s, message)
set_headers :migrate
- @response = request(uri)
+ @response = request uri
end
# TODO: This should perform the instance_variable_get and pass the value to the appropriate method.
def method_missing(name, *args)
\ No newline at end of file