FileDocCategorySizeDatePackage
GDataServiceClient.javaAPI DocAndroid 1.5 API8792Wed May 06 22:41:16 BST 2009com.google.wireless.gdata.client

GDataServiceClient

public abstract class GDataServiceClient extends Object
Abstract base class for service-specific clients to access GData feeds.

Fields Summary
private final GDataClient
gDataClient
private final GDataParserFactory
gDataParserFactory
Constructors Summary
public GDataServiceClient(GDataClient gDataClient, GDataParserFactory gDataParserFactory)

        this.gDataClient = gDataClient;
        this.gDataParserFactory = gDataParserFactory;
    
Methods Summary
public com.google.wireless.gdata.data.EntrycreateEntry(java.lang.String feedUrl, java.lang.String authToken, com.google.wireless.gdata.data.Entry entry)
Creates a new entry at the provided feed. Parses the server response into the version of the entry stored on the server.

param
feedUrl The feed where the entry should be created.
param
authToken The authentication token for this user.
param
entry The entry that should be created.
return
The entry returned by the server as a result of creating the provided entry.
throws
ParseException Thrown if the server response cannot be parsed.
throws
IOException Thrown if an error occurs while communicating with the GData service.
throws
HttpException if the service returns an error response

        GDataSerializer serializer = gDataParserFactory.createSerializer(entry);
        InputStream is = gDataClient.createEntry(feedUrl, authToken, serializer);
        return parseEntry(entry.getClass(), is);
    
public QueryParamscreateQueryParams()
Creates {@link QueryParams} that can be used to restrict the feed contents that are fetched.

return
The QueryParams that can be used with this client.

        return gDataClient.createQueryParams();
    
public voiddeleteEntry(java.lang.String editUri, java.lang.String authToken)
Deletes an existing entry.

param
editUri The editUri for the entry that should be deleted.
param
authToken The authentication token for this user.
throws
IOException Thrown if an error occurs while communicating with the GData service.
throws
HttpException if the service returns an error response

        gDataClient.deleteEntry(editUri, authToken);
    
public com.google.wireless.gdata.data.EntrygetEntry(java.lang.Class entryClass, java.lang.String id, java.lang.String authToken)
Fetches an existing entry.

param
entryClass the type of entry to expect
param
id of the entry to fetch.
param
authToken The authentication token for this user. @return The entry returned by the server.
throws
ParseException Thrown if the server response cannot be parsed.
throws
HttpException if the service returns an error response
throws
IOException Thrown if an error occurs while communicating with the GData service.
return
The entry returned by the server

        InputStream is = getGDataClient().getFeedAsStream(id, authToken);
        return parseEntry(entryClass, is);
    
protected GDataClientgetGDataClient()
Returns the {@link GDataClient} being used by this GDataServiceClient.

return
The {@link GDataClient} being used by this GDataServiceClient.

        return gDataClient;
    
protected GDataParserFactorygetGDataParserFactory()
Returns the {@link GDataParserFactory} being used by this GDataServiceClient.

return
The {@link GDataParserFactory} being used by this GDataServiceClient.

        return gDataParserFactory;
    
public java.io.InputStreamgetMediaEntryAsStream(java.lang.String mediaEntryUrl, java.lang.String authToken)
Fetches a media entry as an InputStream. The caller is responsible for closing the returned {@link InputStream}.

param
mediaEntryUrl The URL of the media entry that should be fetched.
param
authToken The authentication token for this user.
return
A {@link InputStream} for the requested media entry.
throws
IOException Thrown if an error occurs while communicating with the GData service.

        return gDataClient.getMediaEntryAsStream(mediaEntryUrl, authToken);
    
public com.google.wireless.gdata.parser.GDataParsergetParserForFeed(java.lang.Class feedEntryClass, java.lang.String feedUrl, java.lang.String authToken)
Fetches a feed for this user. The caller is responsible for closing the returned {@link GDataParser}.

param
feedEntryClass the class of Entry that is contained in the feed
param
feedUrl ThAe URL of the feed that should be fetched.
param
authToken The authentication token for this user.
return
A {@link GDataParser} for the requested feed.
throws
ParseException Thrown if the server response cannot be parsed.
throws
IOException Thrown if an error occurs while communicating with the GData service.
throws
HttpException Thrown if the http response contains a result other than 2xx

        InputStream is = gDataClient.getFeedAsStream(feedUrl, authToken);
        return gDataParserFactory.createParser(feedEntryClass, is);
    
public abstract java.lang.StringgetServiceName()
Returns the name of the service. Used for authentication.

return
The name of the service.

private com.google.wireless.gdata.data.EntryparseEntry(java.lang.Class entryClass, java.io.InputStream is)

        GDataParser parser = null;
        try {
            parser = gDataParserFactory.createParser(entryClass, is);
            return parser.parseStandaloneEntry();
        } finally {
            if (parser != null) {
                parser.close();
            }
        }
    
public com.google.wireless.gdata.data.EntryupdateEntry(com.google.wireless.gdata.data.Entry entry, java.lang.String authToken)
Updates an existing entry. Parses the server response into the version of the entry stored on the server.

param
entry The entry that should be updated.
param
authToken The authentication token for this user.
return
The entry returned by the server as a result of updating the provided entry.
throws
ParseException Thrown if the server response cannot be parsed.
throws
IOException Thrown if an error occurs while communicating with the GData service.
throws
HttpException if the service returns an error response

        String editUri = entry.getEditUri();
        if (StringUtils.isEmpty(editUri)) {
            throw new ParseException("No edit URI -- cannot update.");
        }

        GDataSerializer serializer = gDataParserFactory.createSerializer(entry);
        InputStream is = gDataClient.updateEntry(editUri, authToken, serializer);
        return parseEntry(entry.getClass(), is);
    
public com.google.wireless.gdata.data.MediaEntryupdateMediaEntry(java.lang.String editUri, java.io.InputStream inputStream, java.lang.String contentType, java.lang.String authToken)
Updates an existing entry. Parses the server response into the metadata of the entry stored on the server.

param
editUri The URI of the resource that should be updated.
param
inputStream The {@link java.io.InputStream} that contains the new value of the media entry
param
contentType The content type of the new media entry
param
authToken The authentication token for this user.
return
The entry returned by the server as a result of updating the provided entry.
throws
HttpException if the service returns an error response
throws
ParseException Thrown if the server response cannot be parsed.
throws
IOException Thrown if an error occurs while communicating with the GData service.

        if (StringUtils.isEmpty(editUri)) {
            throw new IllegalArgumentException("No edit URI -- cannot update.");
        }

        InputStream is = gDataClient.updateMediaEntry(editUri, authToken, inputStream, contentType);
        return (MediaEntry)parseEntry(MediaEntry.class, is);