The TypePad Object

The typepad.tpobject module houses the TypePadObject class and related classes, providing a RemoteObject based implementation of the generic TypePad API.

The module contains:

  • the TypePadObject class, a RemoteObject subclass that enforces batch requesting and objectTypes behavior
  • the Link class, implementing the TypePad API’s common link object
  • the ListObject class and ListOf metaclass, providing an interface for working with the TypePad API’s list endpoints
class typepad.tpobject.ListObject(**kwargs)

A TypePadObject representing a list of other TypePadObject instances.

Endpoints in the TypePad API can be either objects themselves or sets of objects, which are represented in the client library as ListObject instances. As the API lists are homogeneous, all ListObject instances you’ll use in practice are configured for particular TypePadObject classes (their “entry classes”). A ListObject instance will hold only instances of its configured class.

The primary way to reference a ListObject class is to call its metaclass, ListOf, with a reference to or name of that class.

>>> ListOfEntry = ListOf(Entry)

For an Entry list you then fetch with the ListOfEntry class’s get() method, all the entities in the list resource’s entries member will be decoded into Entry instances.

count()
Returns the number of items in the overall list resource, of which this ListObject instance may be only a segment.
entries
A list of items in this list resource.
filter(**kwargs)

Returns a new ListObject instance representing the same endpoint as this ListObject instance with the additional filtering applied.

This method filters the ListObject as does RemoteObject.filter(), but specially treats filters defined in the TypePad API. These special filters are not added in as query parameters but as path components.

start_index

The index in the overall list resource of the first item in this ListObject instance.

The first item in the list has index 1.

total_results
The total number of items in the overall list resource (of which this ListObject instance may be only a segment).
class typepad.tpobject.TypePadObject(**kwargs)

A RemoteObject representing an object in the TypePad API.

All HTTP requests made for a TypePadObject are made through the typepad.client user agent instance. Unlike other PromiseObject instances, TypePadObject instances cannot be independently delivered; they must be delivered by an outside object (namely typepad.client).

delete(http=None)

Deletes the remote resource represented by this TypePadObject instance through an HTTP DELETE request.

Regardless of the http parameter, the request is performed with the typepad.client user agent.

deliver()

Prevents self-delivery of this instance if batch requests are enabled for TypePadObject instances.

If batch requests are not enabled, delivers the object as by PromiseObject.deliver().

classmethod get(url, *args, **kwargs)

Promises a new TypePadObject instance for the named resource.

If parameter url is not an absolute URL, the resulting instance will reference the given URL relative to the TypePad API’s base address.

If batch requests are enabled, the request that delivers the resulting TypePadObject instance will be added to the typepad.client BatchClient instance’s batch request. If typepad.client has no active batch request, a PromiseError will be raised. The batch parameter can be used to force a non-batch request if batch requests are enabled.

Builds the API URL for this TypePadObject instance from its data.

This method returns either the fully absolute URL at which this TypePadObject instance can be found in the API, or None if the TypePadObject instance has no API URL. (A TypePadObject instance may have no URL if it has not been saved to the API, or if it is an instance of a TypePadObject subclass that is only ever used as a field in another class and so cannot be requested by itself.)

This implementation returns None. As different API objects use different URL schemes, all TypePadObject subclasses that can have self links must implement this method themselves.

object_types
A list of URIs that identify the type of TypePad content object this is.
post(obj, http=None)

Adds another TypePadObject to this remote resource through an HTTP POST request, as in HttpObject.post().

Regardless of the http parameter, the request is performed with the typepad.client user agent.

put(http=None)

Saves a previously requested TypePadObject back to its remote resource through an HTTP PUT request, as in HttpObject.put().

Regardless of the http parameter, the request is performed with the typepad.client user agent.

reclass_for_data(data)

Modifies this TypePadObject instance to be an instance of the specific TypePadObject subclass specified in data.

If the data specify a different TypePadObject subclass than the one of which self is an instance, self will be modified to be an instance of the described class. That is, if:

  • the data parameter is a dictionary containing an objectTypes item,
  • that objectTypes item is a list of object type identifiers, and
  • the object type identifiers describe a different TypePadObject subclass besides the one self belongs to,

self will be turned into an instance of the class specified in the data parameter’s objectTypes list.

This method returns True if the instance was changed to be a different class, or False if it was not modified.

to_dict()
Encodes the TypePadObject instance to a dictionary.
update_from_dict(data)

Updates this object with the given data, transforming it into an instance of a different TypePadObject subclass if necessary.

This implementation fills this TypePadObject instance with the data in parameter data, as in RemoteObject.update_from_dict().

If the data specify a different TypePadObject subclass than the one of which self is an instance, self will be modified to be an instance of the described class. That is, if:

  • this is the first time update_from_dict() is called on the instance,
  • the data parameter is a dictionary containing an objectTypes item,
  • that objectTypes item is a list of object type identifiers, and
  • the object type identifiers describe a different TypePadObject subclass besides the one self belongs to,

self will be turned into an instance of the class specified in the data parameter’s objectTypes list.

Override the reclass_for_data() method to change when an instance is modified to be of a different subclass.

class typepad.tpobject.TypePadObjectMetaclass

A metaclass for creating new TypePadObject classes.

In addition to the normal behavior of RemoteObject class creation, classes created by TypePadObjectMetaclass are classified by their object_type members, so their instances can be reclassified based on object_types data in API responses.

Previous topic

typepad

Next topic

TypePad Content Objects

This Page