Activeナントカ

Activeナントカ

ActiveFoobar - client library

@tkawa

Background

  • I'm doing with REST
  • I'm a Rubyist and a Rails developer
  • I'm reading “RESTful Web APIs” in the group
    • It's exciting and high ideal
    • But, client side is not covered
    • Even with a server implementation, we can't use it without a client implementation
    • I want to implement a client with Ruby

せっかくなのでActiveResourceを使ってみたいと思ったけど、インターフェイスがだいぶ違いそう。そもそもリソース指向ではない

Keyword

「意味を表す名前」Names that describe semantics

  • 値の意味を表す名前 (Semantic Descriptor)
  • リンクの意味を表す名前 (Link Relation)
<!-- http://example.com/people/135 -->
<span class="name">Toru Kawamura</span>
Member of <a href="/organizations/32" rel="member_of">Sendagaya.rb</a>

namehttp://schema.org/name

member_ofhttp://schema.org/memberOf

Imagine...

person = Person.find('http://example.com/people/135')
# fetch http://example.com/people/135
# => <ActiveNantoka::Person>
person.items_for('http://schema.org/name')
# => ["Toru Kawamura"]
person.links_for('http://schema.org/memberOf')
# fetch http://example.com/organizations/32
# => [<ActiveNantoka::Organization>]

「標準語彙名(standard vocabulary)」で値やリンクを取得できる

リンクは has_one/has_many 的リレーションに

What is it worth?

典型的な「ad-hoc JSON」のAPI

{
  "fullname" : "Toru Kawamura",
  "organizations" : [
    {
      "title" : "Sendagaya.rb",
      "url" : "/organizations/32"
    }
  ]
}
{
  "fullname" : "Toru Kawamura",
  "organizations" : [
    {
      "title" : "Sendagaya.rb",
      "url" : "/organizations/32"
    }
  ]
}

fullnamehttp://schema.org/name

organizations.urlhttp://schema.org/memberOf

のマッピング(Profile)さえ記述してあれば、全く同様に扱える!

意味が同じであれば、APIの構造が違っても同一のインターフェイスで扱える

“Twitter API”、“Facebook API”、“Google+ API” を同じクライアントで(理論的には) 扱える

Just a imagination

まだ構想しかありません

Inspired by microdata DOM API

http://www.whatwg.org/specs/web-apps/current-work/multipage/microdata.html#using-the-microdata-dom-api

How about this?