Atom Publishing Protocol
From PixyWiki
Contents |
Overview
PixyBlog supports the Atom Publishing Protocol (APP). The API is currently in beta release and as it is still under development is considered experimental. The documentation is also in the process of being written-up, so if you have questions about using the API either post it in our API discussion forum or contact us.
You can find more information on the API on the following websites:
- Atom Publishing Protocol (APP)
- Getting to know the Atom Publishing Protocol, Part 1: Create and edit Web resources with the Atom Publishing Protocol
- Getting to know the Atom Publishing Protocol, Part 2: Put the Atom Publishing Protocol (APP) to work
The API
The APP end-point for PixyBlog is:
http://www.pixyblog.com/roller-services/app
Examples
The following showcases some examples on using the API.
Posting to PixyBlog via APP and OAuth
Adapted from example Posting to Roller via AtomPub and OAuth.
Below is a Groovy example that shows how to post a blog entry to PixyBlog via AtomPub and OAuth. You can get the consumer key, secret and URLs you need to call your instance of PixyBlog from the OAuth Credentials page in the PixyBlog admin interface.
import com.sun.syndication.propono.atom.client.*
import com.sun.syndication.feed.atom.*
def authStrategy = new OAuthStrategy(
"roller", // username
"55132608a2fb68816bcd3d1caeafc933", // consumer key
"bb420783-fdea-4270-ab83-36445c18c307", // consumer secret
"HMAC-SHA1", // key type
"http://blogs.example.com/roller-services/oauth/requestToken",
"http://blogs.example.com/roller-services/oauth/authorize",
"http://blogs.example.com/roller-services/oauth/accessToken")
// get the AtomPub service
def appService = AtomClientFactory.getAtomService(
"http://blogs.example.com/roller-services/app", authStrategy)
// find workspace of my blog
def blog = appService.findWorkspace("Blogging Roller")
// find collecton that will accept entries
def entries = blog.findCollection(null, "application/atom+xml;type=entry")
// create and post an entry
def entry = entries.createEntry()
entry.title = "TestPost"
def content = new Content()
content.setValue("This is a test post. w00t!")
entry.setContent([content])
entries.addEntry(entry)
Posting an Entry
In Java, a good library to use for this is Abdera (which has dependencies on a number of other libraries).
String start = "http://demo.pixyblog.com";
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
Entry entry = factory.newEntry();
entry.setId(FOMHelper.generateUuid());
entry.setUpdated(new java.util.Date());
entry.addAuthor("John");
entry.setTitle("Posting to PixyBlog");
entry.setContentAsHtml("<p>This is an example post to PixyBlog</p>");
Client client = new CommonsClient(abdera);
client.addCredentials(
start, null, null,
new UsernamePasswordCredentials(
"username", "password"));
// Get the collection URI from the service document
Document<Service> service_doc = client.get(start).getDocument();
Service service = service_doc.getRoot();
Collection collection =
service.getWorkspaces().get(0)
.getCollections().get(0);
String uri = collection.getHref().toString();
Response response = client.post(uri, entry);
if (response.getStatus() == 201)
System.out.println("Success!");
else
System.out.println("Failed!");
Posting media resources
Another feature of PixyBlog's Atom Publishing implementation is support for uploading arbitrary media resources. For instance, to upload a photos or podcasts, you simply replace the entry in the previous post with a request entity representing the JPEG or MP3 to be uploaded:
Posting resources to PixyBlog
FileInputStream fis = new FileInputStream(
"mypodcast.mp3");
InputStreamRequestEntity re =
new InputStreamRequestEntity(fis, "audio/mp3");
Client client = // init the client
String uri = // get the collection uri
RequestOptions options = client.getDefaultRequestOptions();
options.setHeader("Title", "mypodcast.mp3");
Response response = client.post(uri, re, options);
if (response.getStatus() == 201)
System.out.println("Success!");
else
System.out.println("Failed!");
You can also use the Atom Publishing Protocol operations to update, delete, and list all of the resources that were uploaded to the server.


