gdata.apps.service
index
/home/jscudder/svn/gdata-python-client/src/gdata/apps/service.py

# Copyright (C) 2007 SIOS Technology, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

 
Modules
       
cElementTree
atom
gdata
urllib

 
Classes
       
exceptions.Exception
Error
AppsForYourDomainException
gdata.service.GDataService(atom.service.AtomService)
AppsService

 
class AppsForYourDomainException(Error)
    
Method resolution order:
AppsForYourDomainException
Error
exceptions.Exception

Methods defined here:
__init__(self, response)

Methods inherited from exceptions.Exception:
__getitem__(...)
__str__(...)

 
class AppsService(gdata.service.GDataService)
    Client for the Google Apps Provisioning service.
 
 
Method resolution order:
AppsService
gdata.service.GDataService
atom.service.AtomService
__builtin__.object

Methods defined here:
AddAllElementsFromAllPages(self, link_finder, func)
retrieve all pages and add all elements
AddRecipientToEmailList(self, recipient, list_name)
Add a recipient to a email list.
CreateEmailList(self, list_name)
Create a email list.
CreateNickname(self, user_name, nickname)
Create a nickname
CreateUser(self, user_name, family_name, given_name, password, suspended='false', quota_limit=None, password_hash_function=None)
Create a user account.
DeleteEmailList(self, list_name)
Delete a email list
DeleteNickname(self, nickname)
Delete a nickname
DeleteUser(self, user_name)
Delete a user account
RemoveRecipientFromEmailList(self, recipient, list_name)
Remove recipient from email list.
RestoreUser(self, user_name)
RetrieveAllEmailLists(self)
Retrieve all email list of a domain.
RetrieveAllNicknames(self)
Retrieve all nicknames in the domain
RetrieveAllRecipients(self, list_name)
Retrieve all recipient of an email list.
RetrieveAllUsers(self)
Retrieve all users in this domain.
RetrieveEmailList(self, list_name)
Retreive a single email list by the list's name.
RetrieveEmailLists(self, recipient)
Retrieve All Email List Subscriptions for an Email Address.
RetrieveNickname(self, nickname)
Retrieve a nickname.
 
Args:
  nickname: string The nickname to retrieve
 
Returns:
  gdata.apps.NicknameEntry
RetrieveNicknames(self, user_name)
Retrieve nicknames of the user
RetrievePageOfEmailLists(self, start_email_list_name=None)
Retrieve one page of email list
RetrievePageOfNicknames(self, start_nickname=None)
Retrieve one page of nicknames in the domain
RetrievePageOfRecipients(self, list_name, start_recipient=None)
Retrieve one page of recipient of an email list.
RetrievePageOfUsers(self, start_username=None)
Retrieve one page of users in this domain.
RetrieveUser(self, user_name)
Retrieve an user account.
 
Args:
  user_name: string The user name to retrieve
 
Returns:
  gdata.apps.UserEntry
SuspendUser(self, user_name)
UpdateUser(self, user_name, user_entry)
Update a user account.
__init__(self, email=None, password=None, domain=None, source=None, server='www.google.com', additional_headers=None)

Methods inherited from gdata.service.GDataService:
ClientLogin(self, username, password, account_type=None, service=None, source=None, captcha_token=None, captcha_response=None)
Convenience method for authenticating using ProgrammaticLogin. 
 
Sets values for email, password, and other optional members.
 
Args:
  username:
  password:
  account_type: string (optional)
  service: string (optional)
  captcha_token: string (optional)
  captcha_response: string (optional)
Delete(self, uri, extra_headers=None, url_params=None, escape_params=True, redirects_remaining=4)
Deletes the entry at the given URI.
 
Args:
  uri: string The URI of the entry to be deleted. Example: 
       '/base/feeds/items/ITEM-ID'
  extra_headers: dict (optional) HTTP headers which are to be included.
                 The client automatically sets the Content-Type and
                 Authorization headers.
  url_params: dict (optional) Additional URL parameters to be included
              in the URI. These are translated into query arguments
              in the form '&dict_key=value&...'.
              Example: {'max-results': '250'} becomes &max-results=250
  escape_params: boolean (optional) If false, the calling code has already
                 ensured that the query will form a valid URL (all
                 reserved characters have been escaped). If true, this
                 method will escape the query and any URL parameters
                 provided.
 
Returns:
  True if the entry was deleted.
GenerateAuthSubURL(self, next, scope, secure=False, session=True)
Generate a URL at which the user will login and be redirected back.
 
Users enter their credentials on a Google login page and a token is sent
to the URL specified in next. See documentation for AuthSub login at:
http://code.google.com/apis/accounts/AuthForWebApps.html
 
Args:
  next: string The URL user will be sent to after logging in.
  scope: string The URL of the service to be accessed.
  secure: boolean (optional) Determines whether or not the issued token
          is a secure token.
  session: boolean (optional) Determines whether or not the issued token
           can be upgraded to a session token.
Get(self, uri, extra_headers=None, redirects_remaining=4, encoding='UTF-8', converter=None)
Query the GData API with the given URI
 
The uri is the portion of the URI after the server value 
(ex: www.google.com).
 
To perform a query against Google Base, set the server to 
'base.google.com' and set the uri to '/base/feeds/...', where ... is 
your query. For example, to find snippets for all digital cameras uri 
should be set to: '/base/feeds/snippets?bq=digital+camera'
 
Args:
  uri: string The query in the form of a URI. Example:
       '/base/feeds/snippets?bq=digital+camera'.
  extra_headers: dictionary (optional) Extra HTTP headers to be included
                 in the GET request. These headers are in addition to 
                 those stored in the client's additional_headers property.
                 The client automatically sets the Content-Type and 
                 Authorization headers.
  redirects_remaining: int (optional) Tracks the number of additional
      redirects this method will allow. If the service object receives
      a redirect and remaining is 0, it will not follow the redirect. 
      This was added to avoid infinite redirect loops.
  encoding: string (optional) The character encoding for the server's
      response. Default is UTF-8
  converter: func (optional) A function which will transform
      the server's results before it is returned. Example: use 
      GDataFeedFromString to parse the server response as if it
      were a GDataFeed.
 
Returns:
  If there is no ResultsTransformer specified in the call, a GDataFeed 
  or GDataEntry depending on which is sent from the server. If the 
  response is niether a feed or entry and there is no ResultsTransformer,
  return a string. If there is a ResultsTransformer, the returned value 
  will be that of the ResultsTransformer function.
GetAuthSubToken(self)
GetClientLoginToken(self)
GetEntry(self, uri, extra_headers=None)
Query the GData API with the given URI and receive an Entry.
 
See also documentation for gdata.service.Get
 
Args:
  uri: string The query in the form of a URI. Example:
       '/base/feeds/snippets?bq=digital+camera'.
  extra_headers: dictionary (optional) Extra HTTP headers to be included
                 in the GET request. These headers are in addition to
                 those stored in the client's additional_headers property.
                 The client automatically sets the Content-Type and
                 Authorization headers.
 
Returns:
  A GDataEntry built from the XML in the server's response.
GetFeed(self, uri, extra_headers=None, converter=<function GDataFeedFromString>)
Query the GData API with the given URI and receive a Feed.
 
See also documentation for gdata.service.Get
 
Args:
  uri: string The query in the form of a URI. Example:
       '/base/feeds/snippets?bq=digital+camera'.
  extra_headers: dictionary (optional) Extra HTTP headers to be included
                 in the GET request. These headers are in addition to
                 those stored in the client's additional_headers property.
                 The client automatically sets the Content-Type and
                 Authorization headers.
 
Returns:
  A GDataFeed built from the XML in the server's response.
GetMedia(self, uri, extra_headers=None)
Returns a MediaSource containing media and its metadata from the given
URI string.
GetNext(self, feed)
Requests the next 'page' of results in the feed.
 
This method uses the feed's next link to request an additional feed
and uses the class of the feed to convert the results of the GET request.
 
Args:
  feed: atom.Feed or a subclass. The feed should contain a next link and
      the type of the feed will be applied to the results from the 
      server. The new feed which is returned will be of the same class
      as this feed which was passed in.
 
Returns:
  A new feed representing the next set of results in the server's feed.
  The type of this feed will match that of the feed argument.
Post(self, data, uri, extra_headers=None, url_params=None, escape_params=True, redirects_remaining=4, media_source=None, converter=None)
Insert data into a GData service at the given URI.
 
Args:
  data: string, ElementTree._Element, atom.Entry, or gdata.GDataEntry The
        XML to be sent to the uri. 
  uri: string The location (feed) to which the data should be inserted. 
       Example: '/base/feeds/items'. 
  extra_headers: dict (optional) HTTP headers which are to be included. 
                 The client automatically sets the Content-Type,
                 Authorization, and Content-Length headers.
  url_params: dict (optional) Additional URL parameters to be included
              in the URI. These are translated into query arguments
              in the form '&dict_key=value&...'.
              Example: {'max-results': '250'} becomes &max-results=250
  escape_params: boolean (optional) If false, the calling code has already
                 ensured that the query will form a valid URL (all
                 reserved characters have been escaped). If true, this
                 method will escape the query and any URL parameters
                 provided.
  media_source: MediaSource (optional) Container for the media to be sent
      along with the entry, if provided.
  converter: func (optional) A function which will be executed on the 
      server's response. Often this is a function like 
      GDataEntryFromString which will parse the body of the server's 
      response and return a GDataEntry.
 
Returns:
  If the post succeeded, this method will return a GDataFeed, GDataEntry,
  or the results of running converter on the server's result body (if
  converter was specified).
ProgrammaticLogin(self, captcha_token=None, captcha_response=None)
Authenticates the user and sets the GData Auth token.
 
Login retreives a temporary auth token which must be used with all
requests to GData services. The auth token is stored in the GData client
object.
 
Login is also used to respond to a captcha challenge. If the user's login
attempt failed with a CaptchaRequired error, the user can respond by
calling Login with the captcha token and the answer to the challenge.
 
Args:
  captcha_token: string (optional) The identifier for the captcha challenge
                 which was presented to the user.
  captcha_response: string (optional) The user's answer to the captch 
                    challenge.
 
Raises:
  CaptchaRequired if the login service will require a captcha response
  BadAuthentication if the login service rejected the username or password
  Error if the login service responded with a 403 different from the above
Put(self, data, uri, extra_headers=None, url_params=None, escape_params=True, redirects_remaining=3, media_source=None, converter=None)
Updates an entry at the given URI.
 
Args:
  data: string, ElementTree._Element, or xml_wrapper.ElementWrapper The 
        XML containing the updated data.
  uri: string A URI indicating entry to which the update will be applied.
       Example: '/base/feeds/items/ITEM-ID'
  extra_headers: dict (optional) HTTP headers which are to be included.
                 The client automatically sets the Content-Type,
                 Authorization, and Content-Length headers.
  url_params: dict (optional) Additional URL parameters to be included
              in the URI. These are translated into query arguments
              in the form '&dict_key=value&...'.
              Example: {'max-results': '250'} becomes &max-results=250
  escape_params: boolean (optional) If false, the calling code has already
                 ensured that the query will form a valid URL (all
                 reserved characters have been escaped). If true, this
                 method will escape the query and any URL parameters
                 provided.
  converter: func (optional) A function which will be executed on the 
      server's response. Often this is a function like 
      GDataEntryFromString which will parse the body of the server's 
      response and return a GDataEntry.
 
Returns:
  If the put succeeded, this method will return a GDataFeed, GDataEntry,
  or the results of running converter on the server's result body (if
  converter was specified).
RevokeAuthSubToken(self)
Revokes an existing AuthSub token.
 
Raises:
  NonAuthSubToken if the user's auth token is not an AuthSub token
SetAuthSubToken(self, token)
SetClientLoginToken(self, token)
UpgradeToSessionToken(self)
Upgrades a single use AuthSub token to a session token.
 
Raises:
  NonAuthSubToken if the user's auth token is not an AuthSub token

Properties inherited from gdata.service.GDataService:
auth_token
Get or set the token used for authentication.
get = __GetAuthToken(self)
set = __SetAuthSubToken(self, auth_token)
captcha_token
Get the captcha token for a login request.
get = __GetCaptchaToken(self)
captcha_url
Get the captcha URL for a login request.
get = __GetCaptchaURL(self)
source
The source is the name of the application making the request. 
It should be in the form company_id-app_name-app_version
get = __GetSource(self)
# Private methods to create the source property.
set = __SetSource(self, new_source)

Methods inherited from atom.service.AtomService:
UseBasicAuth(self, username, password, for_proxy=False)
Sets an Authenticaiton: Basic HTTP header containing plaintext.
 
The username and password are base64 encoded and added to an HTTP header
which will be included in each request. Note that your username and 
password are sent in plaintext.
 
Args:
  username: str
  password: str

Data and other attributes inherited from atom.service.AtomService:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'AtomService' objects>
list of weak references to the object (if defined)
debug = False
port = 80
ssl = False

 
class Error(exceptions.Exception)
     Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
Data
        API_VER = '2.0'
DEFAULT_QUOTA_LIMIT = '2048'
DOMAIN_ALIAS_LIMIT_EXCEEDED = 1201
DOMAIN_FEATURE_UNAVAILABLE = 1203
DOMAIN_SUSPENDED = 1202
DOMAIN_USER_LIMIT_EXCEEDED = 1200
ENTITY_DOES_NOT_EXIST = 1301
ENTITY_EXISTS = 1300
ENTITY_NAME_IS_RESERVED = 1302
ENTITY_NAME_NOT_VALID = 1303
HTTP_OK = 200
INVALID_EMAIL_ADDRESS = 1406
INVALID_FAMILY_NAME = 1401
INVALID_GIVEN_NAME = 1400
INVALID_HASH_DIGGEST_LENGTH = 1405
INVALID_HASH_FUNCTION_NAME = 1404
INVALID_PASSWORD = 1402
INVALID_QUERY_PARAMETER_VALUE = 1407
INVALID_USERNAME = 1403
TOO_MANY_RECIPIENTS_ON_EMAIL_LIST = 1500
UNKOWN_ERROR = 1000
USER_DELETED_RECENTLY = 1100
USER_SUSPENDED = 1101
__author__ = 'tmatsuo@sios.com (Takashi MATSUO)'

 
Author
        tmatsuo@sios.com (Takashi MATSUO)