Evolution of API With Blogging
-
Upload
takatsugu-shigeta -
Category
Technology
-
view
1.524 -
download
2
description
Transcript of Evolution of API With Blogging
Evolution of API With Blogging
YAPC::Asia Tokyo 2011Takatsugu Shigeta
YAPC::Asia Tokyo 2011 by Japan Perl Association is licensed under a Creative Commons Display - Non-Commercial 2.1 Japan License.
Before starting my talk...
I deeply apologize for not realizing to write some code.
I mentioned below in a description of my talk.
“I'll show you implementations of starman, Twiggy and TheSchwartz”
But that didn't match my thoughts.I don't show you that in my talk.
Yeah...
That's NOT stateless.I think that API should be stateless as REST.
That pattern is asynchronized.I couldn't use that pattern in API.
Please don't throw a chairlike Steve Ballmer or kazeburo!
Evolution of API With Blogging
YAPC::Asia Tokyo 2011Takatsugu Shigeta
YAPC::Asia Tokyo 2011 by Japan Perl Association is licensed under a Creative Commons Display - Non-Commercial 2.1 Japan License.
Takatsugu Shigeta
comewalk
Some icons from http://icondock.com/
google-api-perl-client
A moderator of gearman/MogileFS/Perlbal mailing lists
http://blog.comewalk.com
Perl::Evolution
Movable Type 10th Anniversary!
Let's talk about blogging API!
Contents1 1983–19932 1994–20013 2001–2004
4 2004–present5 References
http://en.wikipedia.org/wiki/History_of_blogging
History Of Blogging
1994-2001
The term "weblog" was coined by Jorn Barger on 17 Dec 1997.
The short form, "blog," was coined by Peter Merholz in April or May 1999.
LiveJournal was launched in Mar 1999.
Blogger was launched in Aug 1999.
http://en.wikipedia.org/wiki/History_of_blogging
2001-2004
Movable Type was released in Oct 2001.
By 2001, blogging community increased rapidly.
http://en.wikipedia.org/wiki/History_of_blogging
2004
2011
YAPC::Asia Tokyo 2011
Evolution of API With Blogging
“Learn from yesterday, live for today, hope for tomorrow. The important thing is not
to stop questioning.”
- Albert Einstein
温故知新
- 孔子
Why?
Here we go!
Sample
use Data::Dumper;use Net::Trackback::Client;use Net::Trackback::Ping;
my $ping = Net::Trackback::Ping->new({ ping_url => 'http://example.com/trackback/1234/5678', url => 'http://example.com/blog/2011/10/post-1.html', title => 'Yet Another Trackback Test', description => 'This trackback which is generated by Net::Trackback.',});my $client = Net::Trackback::Client->new;my $msg = $client->send_ping($ping);say Dumper($msg);
Sample
use URI;use XML::Feed;
my $uri = URI->new('http://example.com/rss.xml');my $parser = XML::Feed->parse($uri);say $parser->as_xml;
Sample
use Data::Dumper;use XML::Feed;
my $uri = 'http://example.com';my @urls = XML::Feed->find_feeds($uri);say Dumper(@urls);
use URI;use XML::FOAF;
my $uri = URI->new('http://example.com');my $foaf = XML::FOAF->new($uri);say $foaf->person->nick;
Sample
Auto-Discovery<link rel="alternate" type="application/atom+xml"
title="Atom" href="http://example.com/atom.xml" /><link rel="alternate" type="application/rss+xml"
title="RSS 1.0" href="http://example.com/index.rdf" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://example.com/rss.xml" />
<link rel="openid.server" href="http://example.com/openid/server" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://example.com/rsd/123" />
<link rel="meta" type="application/rdf+xml" title="FOAF" href="http://example.com/foaf.rdf" />
Sample
use Data::Dumper;use WWW::Blog::Metadata;
# seealso: perldoc WWW::Blog::Metadatause WWW::Blog::Metadata::RSD;
My $uri = 'http://example.com';my $meta = WWW::Blog::Metadata->extract_from_uri($uri);say Dumper($meta->feeds);say Dumper($meta->rsd_uri);
Mobile Link Discovery
<link rel="alternate" media="handheld" type="application/xhtml+xml"
href="http://example.com/mobile" />
WWW::Blog::Metadata::MobileLinkDiscovery
http://www.sixapart.jp/docs/tech/mobile_link_discovery_en.html
XMLRPC
use Data::Dumper;use RPC::XML::Client;
my $client = RPC::XML::Client->new('http://www.typepad.jp/t/api');
my $request = RPC::XML::request->new( 'mt.supportedMethods',);my $response = $client->send_request($request);say Dumper($response);
XMLRPC
use Data::Dumper;use XMLRPC::Lite;
my @result = XMLRPC::Lite ->proxy('http://www.typepad.com/t/api') ->call('mt.supportedMethods') ->result;say Dumper(@result);
AtomPub
use XML::Atom::Client;use XML::Atom::Entry;
my $entry = XML::Atom::Entry->new;
$entry->title('This entry is posted by Atom.');$entry->content('Atom Atom Atom Atom');
my $api = XML::Atom::Client->new;$api->username('YourUserName');$api->password('YourPassword');
my $PostURI = "http://example.com/atom/weblog/blog_id=YourBlogID";
my $EditURI = $api->createEntry($PostURI, $entry);
WSSE
my $nonce = $client->make_nonce;my $nonce_enc = encode_base64($nonce, '');my $now = DateTime->now->iso8601 . 'Z';my $digest = encode_base64(sha1($nonce . $now .
($client->password || '')), '');$req->header('X-WSSE', sprintf qq(UsernameToken Username="%s",
PasswordDigest="%s", Nonce="%s", Created="%s"), $client->username || '', $digest, $nonce_enc,
$now);$req->header('Authorization', 'WSSE
profile="UsernameToken"');
Code From XML::Atom::Client
RSD<?xml version="1.0"?><rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> <service> <engineName>TypePad</engineName> <engineLink>http://www.typepad.com/</engineLink><homePageLink>http://blog.comewalk.com/</homePageLink> <apis> <api name="Atom" preferred="false"
apiLink="http://www.typepad.com/services/atom/svc=blogs/blog_id=123" />
<api name="MetaWeblog" preferred="true" apiLink="http://www.typepad.com/services/xmlrpc" blogID="123" />
<api name="Blogger" preferred="false" apiLink="http://www.typepad.com/services/xmlrpc" blogID="123" />
<api name="MovableType" preferred="false" apiLink="http://www.typepad.com/services/xmlrpc" blogID="123" />
</apis> </service></rsd>
weblogUpdates Pingmy $url = 'http://rpc.weblogs.com/RPC2';my $req = HTTP::Request->new('POST', $url);$req->header('Content-Type' => 'text/xml');my $text = <<XML;<?xml version="1.0"?><methodCall> <methodName>weblogUpdates.ping</methodName> <params> <param><value>Foo::Bar</value></param> <param><value>http://example.com</value></param> </params></methodCall>XML$req->content($text);my $ua = LWP::UserAgent->new;my $res = $ua->request($req);
OpenSearch
<link rel="search" type="application/opensearchdescription+xml" href="http://example.com/opensearch/search.xml" title="" />
seealso WWW::OpenSearch
OpenID
seealso Net::OpenID::Consumer
PubSubHubbub
http://code.google.com/p/pubsubhubbub/
PubSubHubbub
Implementations
Publisherhttp://pubsubhubbub.googlecode.com/svn/trunk/
Hubhttp://pubsubhubbub.appspot.com/
Subscriberttp://d.hatena.ne.jp/tokuhirom/20100307/push
Trackback
XMLRPCAtomPub
Comment
RSD
weblogUpdates Ping
Update Stream
RSS Atom
Activity Streams
OpenSearch
JSON
PubSubHubbub
OpenID
OAuthWSSE
FOAF
oEmbed
OPML
Auto-DiscoveryMobile Link Discoverymicroformats
Full view
Anyway,
Are you enjoying YAPC::Asia?
This is very precious to me in YAPC::Asia Tokyo 2011!
Did you have anything like this?
You should talk with ROCK STARS!
Okay,
back to my talk
Further Progress of API
JSON
XML is still used as structured data/representation like HTML
But response of API is moving to JSON.
With Document
Your service should provide API explorerwith API documentation
http://explorer.metacpan.org/
http://code.google.com/apis/explorer/
https://developer.foursquare.com/docs/explore.html
PATCH Method
PATCH method allows us to apply partial modifications to a resource.
RFC5789 PATCH Method for HTTPhttp://www.ietf.org/rfc/rfc5789.txt
e.g.)http://developer.github.com/v3/#http-verbs
PATCH MethodPATCH /gists/:id
{ "description": "the description for this gist", "files": { "file1.txt": { "content": "updated file contents" }, "old_name.txt": { "filename": "new_name.txt", "content": "modified contents" }, "new_file.txt": { "content": "a new file" }, "delete_this_file.txt": null }}
http://developer.github.com/v3/gists/
And Also ...
REST (HTTP verbs, Resource, URI)Authentication (OAuth2)
Rate Limiting
And more...
Performance Tips
Using gzip
Working with partial response
http://code.google.com/apis/discovery/v1/performance.html
Working With Partial Resourcehttps://www.googleapis.com/demo/v1?key=YOUR-API-KEY
200 OK
{ "kind": "demo", ... "items": [ { "title": "First title", "comment": "First comment.", "characteristics": { "length": "short", "accuracy": "high", "followers": ["Jo", "Will"], }, "status": "active", ... }, { "title": "Second title", "comment": "Second comment.", "characteristics": { "length": "long", "accuracy": "medium" "followers": [ ], }, "status": "pending", ... }, ... ]}}
https://www.googleapis.com/demo/v1?key=YOUR-API-KEY&fields=kind,items(title,characteristics/length)
200 OK
{ "kind": "demo", "items": [ { "title": "First title", "characteristics": { "length": "short" } }, { "title": "Second title", "characteristics": { "length": "long" } }, ... ]}
Think New Specifications
Think Data Portability
These formats couldn't resolveto clone our data completely
Movable Type Import/Export Format
WordPress eXtended RSS Format
Atom (Blogger)
Import/Export
Import/Export
Next Future?
Camlistore is a way to store, sync, share, model and back up content
http://camlistore.org/
Semantic Web
Which tools?
Blogging World Is Still Fun,Let's Hack Together!
Kudos To CPAN Authors!
Data::Dumper Net::Trackback HTTP::Request Plagger LWP::UserAgent WWW::Search XML::Feed WWW::Blog::Metadata (Web::Scraper) XML::Atom
RPC::XML XMLRPC::Lite
Especially,miyagawa++
Perl Modules I Mentioned
Finally,
I would like to introduce a module for you
google-api-perl-client
Google APIs Client Library for Perl
http://code.google.com/p/google-api-perl-client/
https://github.com/comewalk/google-api-perl-client/
use URI;use Google::API::Client;
my $client = Google::API::Client->new;My $service = $client->build('urlshortener', 'v1');
# Create a shortened URL by inserting the URL into the url collection.my $body = { 'longUrl' => 'http://code.google.com/apis/urlshortener/',};
my $res = $service->url->insert(body => $body)->execute;say 'short url is' . $res->{'id'};
I WAS VERY VERY EXCITED!
Joe Gregorio mentioned the module in his Google+ stream.
Brad Fitzpatrick directly emailed me that he can help me the module by code review or something like that.
I'll keep updating the module.
And,if you are a programmer,
also you can write some code.Right?
That's all,Thank you!
I'm using USB-booted Ubuntu
VOTE ME!
THANK YOU!