| |
- __builtin__.object
-
- Query
- ResumableUploader
- atom.client.AtomPubClient(__builtin__.object)
-
- GDClient
- atom.http_core.Uri(__builtin__.object)
-
- GDQuery
- exceptions.Exception(exceptions.BaseException)
-
- Error
-
- ClientLoginTokenMissing
- MissingOAuthParameters
- RequestError
-
- BadAuthentication
- CaptchaChallenge
- ClientLoginFailed
- NotImplemented
- NotModified
- RedirectError
-
- BadAuthenticationServiceURL
- UnableToUpgradeToken
- Unauthorized
class GDClient(atom.client.AtomPubClient) |
|
Communicates with Google Data servers to perform CRUD operations.
This class is currently experimental and may change in backwards
incompatible ways.
This class exists to simplify the following three areas involved in using
the Google Data APIs.
CRUD Operations:
The client provides a generic 'request' method for making HTTP requests.
There are a number of convenience methods which are built on top of
request, which include get_feed, get_entry, get_next, post, update, and
delete. These methods contact the Google Data servers.
Auth:
Reading user-specific private data requires authorization from the user as
do any changes to user data. An auth_token object can be passed into any
of the HTTP requests to set the Authorization header in the request.
You may also want to set the auth_token member to a an object which can
use modify_request to set the Authorization header in the HTTP request.
If you are authenticating using the email address and password, you can
use the client_login method to obtain an auth token and set the
auth_token member.
If you are using browser redirects, specifically AuthSub, you will want
to use gdata.gauth.AuthSubToken.from_url to obtain the token after the
redirect, and you will probably want to updgrade this since use token
to a multiple use (session) token using the upgrade_token method.
API Versions:
This client is multi-version capable and can be used with Google Data API
version 1 and version 2. The version should be specified by setting the
api_version member to a string, either '1' or '2'. |
|
- Method resolution order:
- GDClient
- atom.client.AtomPubClient
- __builtin__.object
Methods defined here:
- Batch = batch(self, feed, uri=None, force=False, auth_token=None, **kwargs)
- ClientLogin = client_login(self, email, password, source, service=None, account_type='HOSTED_OR_GOOGLE', auth_url=<atom.http_core.Uri object>, captcha_token=None, captcha_response=None)
- Delete = delete(self, entry_or_uri, auth_token=None, force=False, **kwargs)
- GetAccessToken = get_access_token(self, request_token, url='https://www.google.com/accounts/OAuthGetAccessToken')
- GetEntry = get_entry(self, uri, auth_token=None, converter=None, desired_class=<class 'gdata.data.GDEntry'>, etag=None, **kwargs)
- GetFeed = get_feed(self, uri, auth_token=None, converter=None, desired_class=<class 'gdata.data.GDFeed'>, **kwargs)
- GetNext = get_next(self, feed, auth_token=None, converter=None, desired_class=None, **kwargs)
- GetOAuthToken = get_oauth_token(self, scopes, next, consumer_key, consumer_secret=None, rsa_private_key=None, url='https://www.google.com/accounts/OAuthGetRequestToken')
- ModifyRequest = modify_request(self, http_request)
- Post = post(self, entry, uri, auth_token=None, converter=None, desired_class=None, **kwargs)
- Request = request(self, method=None, uri=None, auth_token=None, http_request=None, converter=None, desired_class=None, redirects_remaining=4, **kwargs)
- RequestClientLoginToken = request_client_login_token(self, email, password, source, service=None, account_type='HOSTED_OR_GOOGLE', auth_url=<atom.http_core.Uri object>, captcha_token=None, captcha_response=None)
- RevokeToken = revoke_token(self, token=None, url=<atom.http_core.Uri object>)
- Update = update(self, entry, auth_token=None, force=False, uri=None, **kwargs)
- UpgradeToken = upgrade_token(self, token=None, url=<atom.http_core.Uri object>)
- batch(self, feed, uri=None, force=False, auth_token=None, **kwargs)
- Sends a batch request to the server to execute operation entries.
Args:
feed: A batch feed containing batch entries, each is an operation.
uri: (optional) The uri to which the batch request feed should be POSTed.
If none is provided, then the feed's edit link will be used.
force: (optional) boolean set to True if you want the batch update to
clobber all data. If False, the version in the information in the
feed object will cause the server to check to see that no changes
intervened between when you fetched the data and when you sent the
changes.
auth_token: (optional) An object which sets the Authorization HTTP header
in its modify_request method. Recommended classes include
gdata.gauth.ClientLoginToken and gdata.gauth.AuthSubToken
among others.
- client_login(self, email, password, source, service=None, account_type='HOSTED_OR_GOOGLE', auth_url=<atom.http_core.Uri object>, captcha_token=None, captcha_response=None)
- Performs an auth request using the user's email address and password.
In order to modify user specific data and read user private data, your
application must be authorized by the user. One way to demonstrage
authorization is by including a Client Login token in the Authorization
HTTP header of all requests. This method requests the Client Login token
by sending the user's email address, password, the name of the
application, and the service code for the service which will be accessed
by the application. If the username and password are correct, the server
will respond with the client login code and a new ClientLoginToken
object will be set in the client's auth_token member. With the auth_token
set, future requests from this client will include the Client Login
token.
For a list of service names, see
http://code.google.com/apis/gdata/faq.html#clientlogin
For more information on Client Login, see:
http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
Args:
email: str The user's email address or username.
password: str The password for the user's account.
source: str The name of your application. This can be anything you
like but should should give some indication of which app is
making the request.
service: str The service code for the service you would like to access.
For example, 'cp' for contacts, 'cl' for calendar. For a full
list see
http://code.google.com/apis/gdata/faq.html#clientlogin
If you are using a subclass of the gdata.client.GDClient, the
service will usually be filled in for you so you do not need
to specify it. For example see BloggerClient,
SpreadsheetsClient, etc.
account_type: str (optional) The type of account which is being
authenticated. This can be either 'GOOGLE' for a Google
Account, 'HOSTED' for a Google Apps Account, or the
default 'HOSTED_OR_GOOGLE' which will select the Google
Apps Account if the same email address is used for both
a Google Account and a Google Apps Account.
auth_url: str (optional) The URL to which the login request should be
sent.
captcha_token: str (optional) If a previous login attempt was reponded
to with a CAPTCHA challenge, this is the token which
identifies the challenge (from the CAPTCHA's URL).
captcha_response: str (optional) If a previous login attempt was
reponded to with a CAPTCHA challenge, this is the
response text which was contained in the challenge.
Returns:
Generated token, which is also stored in this object.
Raises:
A RequestError or one of its suclasses: BadAuthentication,
BadAuthenticationServiceURL, ClientLoginFailed,
ClientLoginTokenMissing, or CaptchaChallenge
- delete(self, entry_or_uri, auth_token=None, force=False, **kwargs)
- get_access_token(self, request_token, url='https://www.google.com/accounts/OAuthGetAccessToken')
- Exchanges an authorized OAuth request token for an access token.
Contacts the Google OAuth server to upgrade a previously authorized
request token. Once the request token is upgraded to an access token,
the access token may be used to access the user's data.
For more details, see the Google Accounts OAuth documentation:
http://code.google.com/apis/accounts/docs/OAuth.html#AccessToken
Args:
request_token: An OAuth token which has been authorized by the user.
url: (optional) The URL to which the upgrade request should be sent.
Defaults to: https://www.google.com/accounts/OAuthAuthorizeToken
- get_entry(self, uri, auth_token=None, converter=None, desired_class=<class 'gdata.data.GDEntry'>, etag=None, **kwargs)
- get_feed(self, uri, auth_token=None, converter=None, desired_class=<class 'gdata.data.GDFeed'>, **kwargs)
- get_next(self, feed, auth_token=None, converter=None, desired_class=None, **kwargs)
- Fetches the next set of results from the feed.
When requesting a feed, the number of entries returned is capped at a
service specific default limit (often 25 entries). You can specify your
own entry-count cap using the max-results URL query parameter. If there
are more results than could fit under max-results, the feed will contain
a next link. This method performs a GET against this next results URL.
Returns:
A new feed object containing the next set of entries in this feed.
- get_oauth_token(self, scopes, next, consumer_key, consumer_secret=None, rsa_private_key=None, url='https://www.google.com/accounts/OAuthGetRequestToken')
- Obtains an OAuth request token to allow the user to authorize this app.
Once this client has a request token, the user can authorize the request
token by visiting the authorization URL in their browser. After being
redirected back to this app at the 'next' URL, this app can then exchange
the authorized request token for an access token.
For more information see the documentation on Google Accounts with OAuth:
http://code.google.com/apis/accounts/docs/OAuth.html#AuthProcess
Args:
scopes: list of strings or atom.http_core.Uri objects which specify the
URL prefixes which this app will be accessing. For example, to access
the Google Calendar API, you would want to use scopes:
['https://www.google.com/calendar/feeds/',
'http://www.google.com/calendar/feeds/']
next: str or atom.http_core.Uri object, The URL which the user's browser
should be sent to after they authorize access to their data. This
should be a URL in your application which will read the token
information from the URL and upgrade the request token to an access
token.
consumer_key: str This is the identifier for this application which you
should have received when you registered your application with Google
to use OAuth.
consumer_secret: str (optional) The shared secret between your app and
Google which provides evidence that this request is coming from you
application and not another app. If present, this libraries assumes
you want to use an HMAC signature to verify requests. Keep this data
a secret.
rsa_private_key: str (optional) The RSA private key which is used to
generate a digital signature which is checked by Google's server. If
present, this library assumes that you want to use an RSA signature
to verify requests. Keep this data a secret.
url: The URL to which a request for a token should be made. The default
is Google's OAuth request token provider.
- modify_request(self, http_request)
- Adds or changes request before making the HTTP request.
This client will add the API version if it is specified.
Subclasses may override this method to add their own request
modifications before the request is made.
- post(self, entry, uri, auth_token=None, converter=None, desired_class=None, **kwargs)
- request(self, method=None, uri=None, auth_token=None, http_request=None, converter=None, desired_class=None, redirects_remaining=4, **kwargs)
- Make an HTTP request to the server.
See also documentation for atom.client.AtomPubClient.request.
If a 302 redirect is sent from the server to the client, this client
assumes that the redirect is in the form used by the Google Calendar API.
The same request URI and method will be used as in the original request,
but a gsessionid URL parameter will be added to the request URI with
the value provided in the server's 302 redirect response. If the 302
redirect is not in the format specified by the Google Calendar API, a
RedirectError will be raised containing the body of the server's
response.
The method calls the client's modify_request method to make any changes
required by the client before the request is made. For example, a
version 2 client could add a GData-Version: 2 header to the request in
its modify_request method.
Args:
method: str The HTTP verb for this request, usually 'GET', 'POST',
'PUT', or 'DELETE'
uri: atom.http_core.Uri, str, or unicode The URL being requested.
auth_token: An object which sets the Authorization HTTP header in its
modify_request method. Recommended classes include
gdata.gauth.ClientLoginToken and gdata.gauth.AuthSubToken
among others.
http_request: (optional) atom.http_core.HttpRequest
converter: function which takes the body of the response as its only
argument and returns the desired object.
desired_class: class descended from atom.core.XmlElement to which a
successful response should be converted. If there is no
converter function specified (converter=None) then the
desired_class will be used in calling the
atom.core.parse function. If neither
the desired_class nor the converter is specified, an
HTTP reponse object will be returned.
redirects_remaining: (optional) int, if this number is 0 and the
server sends a 302 redirect, the request method
will raise an exception. This parameter is used in
recursive request calls to avoid an infinite loop.
Any additional arguments are passed through to
atom.client.AtomPubClient.request.
Returns:
An HTTP response object (see atom.http_core.HttpResponse for a
description of the object's interface) if no converter was
specified and no desired_class was specified. If a converter function
was provided, the results of calling the converter are returned. If no
converter was specified but a desired_class was provided, the response
body will be converted to the class using
atom.core.parse.
- request_client_login_token(self, email, password, source, service=None, account_type='HOSTED_OR_GOOGLE', auth_url=<atom.http_core.Uri object>, captcha_token=None, captcha_response=None)
- revoke_token(self, token=None, url=<atom.http_core.Uri object>)
- Requests that the token be invalidated.
This method can be used for both AuthSub and OAuth tokens (to invalidate
a ClientLogin token, the user must change their password).
Returns:
True if the server responded with a 200.
Raises:
A RequestError if the server responds with a non-200 status.
- update(self, entry, auth_token=None, force=False, uri=None, **kwargs)
- Edits the entry on the server by sending the XML for this entry.
Performs a PUT and converts the response to a new entry object with a
matching class to the entry passed in.
Args:
entry:
auth_token:
force: boolean stating whether an update should be forced. Defaults to
False. Normally, if a change has been made since the passed in
entry was obtained, the server will not overwrite the entry since
the changes were based on an obsolete version of the entry.
Setting force to True will cause the update to silently
overwrite whatever version is present.
uri: The uri to put to. If provided, this uri is PUT to rather than the
inferred uri from the entry's edit link.
Returns:
A new Entry object of a matching type to the entry which was passed in.
- upgrade_token(self, token=None, url=<atom.http_core.Uri object>)
- Asks the Google auth server for a multi-use AuthSub token.
For details on AuthSub, see:
http://code.google.com/apis/accounts/docs/AuthSub.html
Args:
token: gdata.gauth.AuthSubToken or gdata.gauth.SecureAuthSubToken
(optional) If no token is passed in, the client's auth_token member
is used to request the new token. The token object will be modified
to contain the new session token string.
url: str or atom.http_core.Uri (optional) The URL to which the token
upgrade request should be sent. Defaults to:
https://www.google.com/accounts/AuthSubSessionToken
Returns:
The upgraded gdata.gauth.AuthSubToken object.
Data and other attributes defined here:
- alt_auth_service = None
- api_version = None
- auth_scopes = None
- auth_service = None
Methods inherited from atom.client.AtomPubClient:
- Get = get(self, uri=None, auth_token=None, http_request=None, **kwargs)
- Performs a request using the GET method, returns an HTTP response.
- Put = put(self, uri=None, data=None, auth_token=None, http_request=None, **kwargs)
- Sends data using the PUT method, returns an HTTP response.
- __init__(self, http_client=None, host=None, auth_token=None, source=None, xoauth_requestor_id=None, **kwargs)
- Creates a new AtomPubClient instance.
Args:
source: The name of your application.
http_client: An object capable of performing HTTP requests through a
request method. This object is used to perform the request
when the AtomPubClient's request method is called. Used to
allow HTTP requests to be directed to a mock server, or use
an alternate library instead of the default of httplib to
make HTTP requests.
host: str The default host name to use if a host is not specified in the
requested URI.
auth_token: An object which sets the HTTP Authorization header when its
modify_request method is called.
- get(self, uri=None, auth_token=None, http_request=None, **kwargs)
- Performs a request using the GET method, returns an HTTP response.
- put(self, uri=None, data=None, auth_token=None, http_request=None, **kwargs)
- Sends data using the PUT method, returns an HTTP response.
Data descriptors inherited from atom.client.AtomPubClient:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from atom.client.AtomPubClient:
- auth_token = None
- host = None
- ssl = False
- xoauth_requestor_id = None
|
class GDQuery(atom.http_core.Uri) |
| |
- Method resolution order:
- GDQuery
- atom.http_core.Uri
- __builtin__.object
Data descriptors defined here:
- text_query
- The q parameter for searching for an exact text match on content
Methods inherited from atom.http_core.Uri:
- ModifyRequest = modify_request(self, http_request=None)
- Sets HTTP request components based on the URI.
- __init__(self, scheme=None, host=None, port=None, path=None, query=None)
- Constructor for a URI.
Args:
scheme: str This is usually 'http' or 'https'.
host: str The host name or IP address of the desired server.
post: int The server's port number.
path: str The path of the resource following the host. This begins with
a /, example: '/calendar/feeds/default/allcalendars/full'
query: dict of strings The URL query parameters. The keys and values are
both escaped so this dict should contain the unescaped values.
For example {'my key': 'val', 'second': '!!!'} will become
'?my+key=val&second=%21%21%21' which is appended to the path.
- __str__(self)
- modify_request(self, http_request=None)
- Sets HTTP request components based on the URI.
Static methods inherited from atom.http_core.Uri:
- ParseUri = parse_uri(uri_string)
- Creates a Uri object which corresponds to the URI string.
This method can accept partial URIs, but it will leave missing
members of the Uri unset.
- parse_uri(uri_string)
- Creates a Uri object which corresponds to the URI string.
This method can accept partial URIs, but it will leave missing
members of the Uri unset.
Data descriptors inherited from atom.http_core.Uri:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from atom.http_core.Uri:
- host = None
- path = None
- port = None
- scheme = None
|
class Query(__builtin__.object) |
| |
Methods defined here:
- AddCustomParameter = add_custom_parameter(self, key, value)
- ModifyRequest = modify_request(self, http_request)
- __init__(self, text_query=None, categories=None, author=None, alt=None, updated_min=None, updated_max=None, pretty_print=False, published_min=None, published_max=None, start_index=None, max_results=None, strict=False, **custom_parameters)
- Constructs a Google Data Query to filter feed contents serverside.
Args:
text_query: Full text search str (optional)
categories: list of strings (optional). Each string is a required
category. To include an 'or' query, put a | in the string between
terms. For example, to find everything in the Fitz category and
the Laurie or Jane category (Fitz and (Laurie or Jane)) you would
set categories to ['Fitz', 'Laurie|Jane'].
author: str (optional) The service returns entries where the author
name and/or email address match your query string.
alt: str (optional) for the Alternative representation type you'd like
the feed in. If you don't specify an alt parameter, the service
returns an Atom feed. This is equivalent to alt='atom'.
alt='rss' returns an RSS 2.0 result feed.
alt='json' returns a JSON representation of the feed.
alt='json-in-script' Requests a response that wraps JSON in a script
tag.
alt='atom-in-script' Requests an Atom response that wraps an XML
string in a script tag.
alt='rss-in-script' Requests an RSS response that wraps an XML
string in a script tag.
updated_min: str (optional), RFC 3339 timestamp format, lower bounds.
For example: 2005-08-09T10:57:00-08:00
updated_max: str (optional) updated time must be earlier than timestamp.
pretty_print: boolean (optional) If True the server's XML response will
be indented to make it more human readable. Defaults to False.
published_min: str (optional), Similar to updated_min but for published
time.
published_max: str (optional), Similar to updated_max but for published
time.
start_index: int or str (optional) 1-based index of the first result to
be retrieved. Note that this isn't a general cursoring mechanism.
If you first send a query with ?start-index=1&max-results=10 and
then send another query with ?start-index=11&max-results=10, the
service cannot guarantee that the results are equivalent to
?start-index=1&max-results=20, because insertions and deletions
could have taken place in between the two queries.
max_results: int or str (optional) Maximum number of results to be
retrieved. Each service has a default max (usually 25) which can
vary from service to service. There is also a service-specific
limit to the max_results you can fetch in a request.
strict: boolean (optional) If True, the server will return an error if
the server does not recognize any of the parameters in the request
URL. Defaults to False.
custom_parameters: other query parameters that are not explicitly defined.
- add_custom_parameter(self, key, value)
- modify_request(self, http_request)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class ResumableUploader(__builtin__.object) |
|
Resumable upload helper for the Google Data protocol. |
|
Methods defined here:
- QueryUploadStatus = query_upload_status(self, uri=None)
- UpdateFile = update_file(self, entry_or_resumable_edit_link, headers=None, force=False, auth_token=None, update_metadata=False, uri_params=None)
- UploadChunk = upload_chunk(self, start_byte, content_bytes)
- UploadFile = upload_file(self, resumable_media_link, entry=None, headers=None, auth_token=None, **kwargs)
- __init__(self, client, file_handle, content_type, total_file_size, chunk_size=None, desired_class=None)
- Starts a resumable upload to a service that supports the protocol.
Args:
client: gdata.client.GDClient A Google Data API service.
file_handle: object A file-like object containing the file to upload.
content_type: str The mimetype of the file to upload.
total_file_size: int The file's total size in bytes.
chunk_size: int The size of each upload chunk. If None, the
DEFAULT_CHUNK_SIZE will be used.
desired_class: object (optional) The type of gdata.data.GDEntry to parse
the completed entry as. This should be specific to the API.
- query_upload_status(self, uri=None)
- Queries the current status of a resumable upload request.
Args:
uri: str (optional) A resumable upload uri to query and override the one
that is set in this object.
Returns:
An integer representing the file position (byte) to resume the upload from
or True if the upload is complete.
Raises:
RequestError if anything other than a HTTP 308 is returned
when the request raises an exception.
- update_file(self, entry_or_resumable_edit_link, headers=None, force=False, auth_token=None, update_metadata=False, uri_params=None)
- Updates the contents of an existing file using the resumable protocol.
If you are interested in pausing an upload or controlling the chunking
yourself, use the upload_chunk() method instead.
Args:
entry_or_resumable_edit_link: object or string A gdata.data.GDEntry for
the entry/file to update or the full uri of the link with rel
#resumable-edit-media.
headers: dict Additional headers to send in the initial request to create
the resumable upload request. These headers will override any default
headers sent in the request. For example: headers={'Slug': 'MyTitle'}.
force boolean (optional) True to force an update and set the If-Match
header to '*'. If False and entry_or_resumable_edit_link is a
gdata.data.GDEntry object, its etag value is used. Otherwise this
parameter should be set to True to force the update.
auth_token: (optional) An object which sets the Authorization HTTP header
in its modify_request method. Recommended classes include
gdata.gauth.ClientLoginToken and gdata.gauth.AuthSubToken
among others.
update_metadata: (optional) True to also update the entry's metadata
with that in the given GDEntry object in entry_or_resumable_edit_link.
uri_params: (optional) Dict of additional parameters to attach to the URI.
Some non-dict types are valid here, too, like list of tuple pairs.
Returns:
The final Atom entry created on the server. The entry object's type will
be the class specified in self.desired_class.
Raises:
RequestError if anything other than a HTTP 308 is returned when the
request raises an exception.
- upload_chunk(self, start_byte, content_bytes)
- Uploads a byte range (chunk) to the resumable upload server.
Args:
start_byte: int The byte offset of the total file where the byte range
passed in lives.
content_bytes: str The file contents of this chunk.
Returns:
The final Atom entry created on the server. The entry object's type will
be the class specified in self.desired_class.
Raises:
RequestError if the unique upload uri is not set or the
server returns something other than an HTTP 308 when the upload is
incomplete.
- upload_file(self, resumable_media_link, entry=None, headers=None, auth_token=None, **kwargs)
- Uploads an entire file in chunks using the resumable upload protocol.
If you are interested in pausing an upload or controlling the chunking
yourself, use the upload_chunk() method instead.
Args:
resumable_media_link: str The full URL for the #resumable-create-media for
starting a resumable upload request.
entry: A (optional) gdata.data.GDEntry containging metadata to create the
upload from.
headers: dict Additional headers to send in the initial request to create
the resumable upload request. These headers will override any default
headers sent in the request. For example: headers={'Slug': 'MyTitle'}.
auth_token: (optional) An object which sets the Authorization HTTP header
in its modify_request method. Recommended classes include
gdata.gauth.ClientLoginToken and gdata.gauth.AuthSubToken
among others.
kwargs: (optional) Other args to pass to self._init_session.
Returns:
The final Atom entry created on the server. The entry object's type will
be the class specified in self.desired_class.
Raises:
RequestError if anything other than a HTTP 308 is returned
when the request raises an exception.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes defined here:
- DEFAULT_CHUNK_SIZE = 5242880
- MIN_CHUNK_SIZE = 262144
|
|