Rocomotion pplog2のAtomAPIの実装についての解説です。
比べやすいかと思い、livedoorさんのソースを借りました。問題があれば書き直します。
my credentials
X-WSSE: UsernameToken Username="name", PasswordDigest="digest", Nonce="nonce"
, Created="timestamp"(順番遵守)
自分のBlogについて、service.post, service.feed, service.categories,
service.uploadを返す。
Endpoint はhttp://***.com/pplog2/atomapi
GET /atomapi X-WSSE: my credentials
200 OK Content-Type: application/x.atom+xml <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://purl.org/atom/ns#"> <link xmlns="http://purl.org/atom/ns#" type="application/x.atom+xml" rel="service.post" href="http://***.com/atomapi/blog_id=1" title="Blog Test"/> <link xmlns="http://purl.org/atom/ns#" type="application/x.atom+xml" rel="service.feed" href="http://***.com/atomapi/blog_id=1" title="Blog Test"/> <link xmlns="http://purl.org/atom/ns#" type="application/x.atom+xml" rel="service.categories" href="http://***.com/atomapi/blog_id=1/svc=categories" title="Blog Test"/> <link xmlns="http://purl.org/atom/ns#" type="application/x.atom+xml" rel="service.upload" href="http://***.com/atomapi/blog_id=1/svc=upload" title="Blog Test"/> </feed>
entry の全件データを取得
GET /atomapi/blog_id=1 X-WSSE: my credentials
200 OK
Content-Type: application/x.atom+xml
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://purl.org/atom/ns#">
<link rel="alternate" type="text/html" href="http://***.com/pplog2/" />
<title>Blog Test</title>
<link rel="service.post" type="application/x.atom+xml" href="http://***.com/pplog2/atomapi/blog_id=1/entry_id=16" title="test"/>
<entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>test</title>
<link rel="service.edit" type="application/x.atom+xml" href="http://***.com/pplog2/atomapi/blog_id=1/entry_id=16" title="test"/>
<modified>Y-m-d\TH:i:s\Z</modified>
<issued>Y-m-d\TH:i:s+09:00</issued>
<id>tag:***.com/16.html</id>
<summary>・・・</summary>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://***.com/pplog2/">
<![CDATA[
・・・
</content>
$lt;dc:subject>category</subject>
<author>
<name>UG</name>
</author>
</entry>
<entry>
...
</entry>
</feed>
entry の指定件数分データを取得
GET /atomapi/blog_id=1/entry_cnt=XXXXX X-WSSE: my credentials
200 OK
Content-Type: application/x.atom+xml
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://purl.org/atom/ns#">
<link rel="alternate" type="text/html" href="http://***.com/pplog2/" />
<title>Blog Test</title>
<link rel="service.post" type="application/x.atom+xml" href="http://***.com/pplog2/atomapi/blog_id=1/entry_id=16" title="test"/>
<entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>test</title>
<link rel="service.edit" type="application/x.atom+xml" href="http://***.com/pplog2/atomapi/blog_id=1/entry_id=16" title="test"/>
<modified>Y-m-d\TH:i:s\Z</modified>
<issued>Y-m-d\TH:i:s+09:00</issued>
<id>tag:***/16.html</id>
<summary>・・・</summary>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://***.com/pplog2/">
<![CDATA[
・・・
</content>
$lt;dc:subject>category</subject>
<author>
<name>UG</name>
</author>
</entry>
<entry>
...
</entry>
</feed>
entry の1件データを取得
GET /atomapi/blog_id=1/entry_id=XXXXXXXXX X-WSSE: my credentials
200 OK
Content-Type: application/x.atom+xml
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://purl.org/atom/ns#">
<link rel="alternate" type="text/html" href="http://***.com/pplog2/" />
<title>Blog Test</title>
<link rel="service.post" type="application/x.atom+xml" href="http://***.com/pplog2/atomapi/blog_id=1/entry_id=16" title="test"/>
<entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>test</title>
<link rel="service.edit" type="application/x.atom+xml" href="http://***.com/pplog2/atomapi/blog_id=1/entry_id=16" title="test"/>
<modified>Y-m-d\TH:i:s\Z</modified>
<issued>Y-m-d\TH:i:s+09:00</issued>
<id>tag:***.com/16.html</id>
<summary>・・・</summary>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://***.com/pplog2/">
<![CDATA[
・・・
</content>
$lt;dc:subject>category</subject>
<author>
<name>UG</name>
</author>
</entry>
</feed>
エントリーを作成し 201 Created を返す。 レスポンスの Location: には service.edit が入る。
POST /atomapi/blog_id=1 X-WSSE: my credentials <?xml version="1.0" encoding="utf-8"?> <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> <title>Go to Rocomotion</title> <dc:subject>Vacation</dc:subject> <content type="application/xhtml+xml" mode="xml">・・・</content> </entry>
201 Created Content-Type: application/x.atom+xml Location: http://***.com/pplog2/atomapi/blog_id=1/entry_id=XXXX <?xml version="1.0" encoding="UTF-8" ?> <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> <title>Test</title> <link rel="alternate" type="text/html" href="http://***.com/pplog2/17.html" /> <link rel="service.edit" type="application/x.atom+xml" href="http://***.com/pplog2/atomapi/blog_id=1/entry_id=17" title="Test" /> <modified>2004-04-26T12:20:40Z</modified> <issued>2004-04-26T21:20:40+09:00</issued> <id>tag:***.com/pplog2/displog/17.html</id> <summary type="text/plain">・・・</summary> <content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://***.com/pplog2/"> <![CDATA[ ・・・ </content> $lt;dc:subject>category</subject> <author> <name>UG</name> </author> </entry>
投稿したentryを修正する
PUT /atomapi/blog_id=1/entry_id=XXXX X-WSSE: my credentials <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> <title xmlns="http://purl.org/atom/ns#">Test</title> <dc:subject>Vacation</dc:subject> <content xmlns="http://purl.org/atom/ns#" mode="xml">・・・</content> </entry>
200 OK
投稿したentryを削除する
DELETE /atomapi/blog_id=1/entry_id=XXXXX X-WSSE: my credentials
200 OK
カテゴリ一覧を取得する実験的API。正式な仕様ではないため SixApart の名前空間を使用。
GET /atomapi/blog_id=XXXX/svc=categories X-WSSE: my credentials
200 OK Content-Type: application/x.atom+xml
<?xml version="1.0" encoding="utf-8"?> <categories xmlns="http://sixapart.com/atom/category#"> <subject xmlns="http://purl.org/dc/elements/1.1/">A</subject> <subject xmlns="http://purl.org/dc/elements/1.1/">B</subject> <subject xmlns="http://purl.org/dc/elements/1.1/">C</subject> </categories>
画像をアップロードする。
POST /atomapi/blog_id=1/svc=upload X-WSSE: my credentials <?xml version="1.0" encoding="utf-8"?> <entry xmlns="http://purl.org/atom/ns#"> <title xmlns="http://purl.org/atom/ns#">filename.jpg</title> <content xmlns="http://purl.org/atom/ns#" mode="base64">・・・</content> </entry>
200 OK Content-Type: application/x.atom+xml
<?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://purl.org/atom/ns#"> <link rel="alternate" type="image/jpeg" href="http://***.com/pplog2/sam/t-123456.jpg" /> </feed>