Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

atomPub, ruby y la api de 11870

3,204 views

Published on

Published in: Technology
  • Be the first to comment

atomPub, ruby y la api de 11870

  1. 1. Atom Publishing Protocol, ruby y la api de 11870.com David Calavera
  2. 2. antecedentes
  3. 3. 11870.com ๏ recuerda y comparte negocios ... David Calavera Conferencia Rails 2007
  4. 4. 11870.com • recuerda y comparte negocios ... ๏ no solo de comentarios vive el hombre David Calavera Conferencia Rails 2007
  5. 5. 11870.com • recuerda y comparte negocios ... • no solo de comentarios vive el hombre ๏ ¿por qué tengo que atarme a la web? David Calavera Conferencia Rails 2007
  6. 6. 11870.com • recuerda y comparte negocios ... • no solo de comentarios vive el hombre • ¿por qué tengo que atarme a la web? ๏ ¿quien tiene que adaptarse? David Calavera Conferencia Rails 2007
  7. 7. atomPub
  8. 8. “the atom publishing protocol is an application-level protocol for publishing and editing web resources” David Calavera Conferencia Rails 2007
  9. 9. ๏ ¿sabes qué es HTTP y como usarlo? David Calavera Conferencia Rails 2007
  10. 10. • ¿sabes qué es HTTP y como usarlo? ๏ ¿sabes qué es XML y como usarlo? David Calavera Conferencia Rails 2007
  11. 11. • ¿sabes qué es HTTP y como usarlo? • ¿sabes qué es XML y como usarlo? ๏ ¿sabes qué es un feed y como crearlo? David Calavera Conferencia Rails 2007
  12. 12. atomPub características
  13. 13. estándar http://ietfreport.isoc.org/idref/rfc5023 David Calavera Conferencia Rails 2007
  14. 14. basado en atom <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <feed xmlns=quot;http://www.w3.org/2005/Atomquot; xml:lang=quot;enquot;> <id>http://www.verbosemode.com/wp-app.php/posts</id> <updated>2007-11-04T11:38:28Z</updated> <title type=quot;textquot;>Verbose mode</title> <subtitle type=quot;textquot;>Verbose mode</subtitle> <entry> <id>http://www.verbosemode.com/?p=3</id> <title type=quot;textquot;>Spanish Rails Conf 07</title> <updated>2007-11-04T11:38:28Z</updated> <published>2007-11-04T11:38:28Z</published> ... David Calavera Conferencia Rails 2007
  15. 15. arquitectura REST David Calavera Conferencia Rails 2007
  16. 16. arquitectura REST ๏ protocolo sin estado David Calavera Conferencia Rails 2007
  17. 17. arquitectura REST • protocolo sin estado ๏ operaciones bien definidas David Calavera Conferencia Rails 2007
  18. 18. arquitectura REST • protocolo sin estado • operaciones bien definidas ๏ sintaxis universal (IRI) David Calavera Conferencia Rails 2007
  19. 19. IRI www. .w3.mag.keio.ac.jp David Calavera Conferencia Rails 2007
  20. 20. URI www.%e3%81%bb%e3%82%93%e3%81%a8%e3%81%86%e3% 81%ab%e3%81%aa%e3%81%8c%e3%81%84%e3%82%8f%e3% 81%91%e3%81%ae%e3%82%8f%e3%81%8b%e3%82%89%e3% 81%aa%e3%81%84%e3%81%a9%e3%82%81%e3%81%84%e3% 82%93%e3%82%81%e3%81%84%e3%81%ae%e3%82%89% e3%81%b9%e3%82%8b%e3%81%be%e3%81%a0%e3%81%aa% e3%81%8c%e3%81%8f%e3%81%97%e3%81%aa%e3%81%84% e3%81%a8%e3%81%9f%e3%82%8a%e3%81%aa%e3%81% 84.w3.mag.keio.ac.jp David Calavera Conferencia Rails 2007
  21. 21. introspectivo David Calavera Conferencia Rails 2007
  22. 22. introspectivo documento de servicio David Calavera Conferencia Rails 2007
  23. 23. introspectivo documento de servicio colección colección David Calavera Conferencia Rails 2007
  24. 24. introspectivo documento de servicio colección elementos colección elementos David Calavera Conferencia Rails 2007
  25. 25. fácilmente extensible <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <feed xmlns=quot;http://www.w3.org/2005/Atomquot; xml:lang=quot;enquot; xmlns:openSearch=quot;http://a9.com/-/spec/opensearchrss/1.0/quot;> <id>http://www.verbosemode.com/wp-app.php/posts</id> <updated>2007-11-04T11:38:28Z</updated> <title type=quot;textquot;>Verbose mode</title> <subtitle type=quot;textquot;>Verbose mode</subtitle> <openSearch:totalResults>1</openSearch:totalResults> <openSearch:startIndex>1</openSearch:startIndex> <openSearch:itemsPerPage>25</openSearch:itemsPerPage> <entry> <id>http://www.verbosemode.com/?p=3</id> <title type=quot;textquot;>Spanish Rails Conf 07</title> <updated>2007-11-04T11:38:28Z</updated> <published>2007-11-04T11:38:28Z</published> ... David Calavera Conferencia Rails 2007
  26. 26. multimedia David Calavera Conferencia Rails 2007
  27. 27. más... ๏ paginación David Calavera Conferencia Rails 2007
  28. 28. <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <feed xmlns=quot;http://www.w3.org/2005/Atomquot; xml:lang=quot;enquot;> <id>http://www.verbosemode.com/wp-app.php/posts</id> <updated>2007-11-04T11:38:28Z</updated> <link rel=quot;selfquot; href=quot;http://www.verbosemode.com/wp-app.php/posts?p=3quot;/> <link rel=quot;nextquot; href=quot;http://www.verbosemode.com/wp-app.php/posts?p=4quot;/> <link rel=quot;previousquot; href=quot;http://www.verbosemode.com/wp-app.php/posts?p=2quot;/> <link rel=quot;firstquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <link rel=quot;lastquot; href=quot;http://www.verbosemode.com/wp-app.php/posts?p=5quot;/> ... David Calavera Conferencia Rails 2007
  29. 29. más... • paginación ๏ caché David Calavera Conferencia Rails 2007
  30. 30. POST /wp-app.php/posts HTTP/1.1 201 Created Content-Type: application/atom+xml;type=entry;charset=quot;utf-8quot; ETag: quot;c180de84f991g8quot; David Calavera Conferencia Rails 2007
  31. 31. POST /wp-app.php/posts HTTP/1.1 201 Created Content-Type: application/atom+xml;type=entry;charset=quot;utf-8quot; ETag: quot;c180de84f991g8quot; GET /wp-app.php/post/3 HTTP/1.1 304 Not Modified If-None-Match: quot;c180de84f991g8quot; David Calavera Conferencia Rails 2007
  32. 32. POST /wp-app.php/posts HTTP/1.1 201 Created Content-Type: application/atom+xml;type=entry;charset=quot;utf-8quot; ETag: quot;c180de84f991g8quot; GET /wp-app.php/post/3 HTTP/1.1 304 Not Modified If-None-Match: quot;c180de84f991g8quot; PUT /wp-app.php/post/3 HTTP/1.1 412 Precondition Failed If-Match: quot;c180de84f991g8quot; David Calavera Conferencia Rails 2007
  33. 33. más... • paginación • caché ๏ control de estado David Calavera Conferencia Rails 2007
  34. 34. <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <entry xmlns=quot;http://www.w3.org/2005/Atomquot; xmlns:app=quot;http://www.w3.org/2007/appquot; xml:lang=quot;enquot;> <id>http://www.verbosemode.com/?p=3</id> <title type=quot;textquot;>Spanish Rails Conf 07</title> <app:control> <app:draft>no</app:draft> </app:control> ... David Calavera Conferencia Rails 2007
  35. 35. más... • paginación • caché • control de estado ๏ seguridad David Calavera Conferencia Rails 2007
  36. 36. atomPub estructura
  37. 37. atomPub:service GET 'http://www.verbosemode.com/wp-app.php/service' HTTP/1.1 200 OK David Calavera Conferencia Rails 2007
  38. 38. atomPub:service <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <service xmlns=quot;http://www.w3.org/2007/appquot; xmlns:atom=quot;http://www.w3.org/2005/Atomquot;> <workspace> <atom:title>Workspace</atom:title> <collection href=quot;http://www.verbosemode.com/wp-app.php/postsquot;> <atom:title>Posts</atom:title> <accept>application/atom+xml;type=entry</accept> <categories href=quot;http://www.verbosemode.com/wp-app.php/categoriesquot;/> </collection> <collection href=quot;http://www.verbosemode.com/wp-app.php/attachmentsquot;> <atom:title>Media</atom:title> <accept>image/*</accept> <accept>audio/*</accept> <accept>video/*</accept> </collection> </workspace> </service> David Calavera Conferencia Rails 2007
  39. 39. atomPub:service <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <service xmlns=quot;http://www.w3.org/2007/appquot; xmlns:atom=quot;http://www.w3.org/2005/Atomquot;> <workspace> <atom:title>Workspace</atom:title> <collection href=quot;http://www.verbosemode.com/wp-app.php/postsquot;> <atom:title>Posts</atom:title> <accept>application/atom+xml;type=entry</accept> <categories href=quot;http://www.verbosemode.com/wp-app.php/categoriesquot;/> </collection> <collection href=quot;http://www.verbosemode.com/wp-app.php/attachmentsquot;> <atom:title>Media</atom:title> <accept>image/*</accept> <accept>audio/*</accept> <accept>video/*</accept> </collection> </workspace> </service> David Calavera Conferencia Rails 2007
  40. 40. atomPub:service <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <service xmlns=quot;http://www.w3.org/2007/appquot; xmlns:atom=quot;http://www.w3.org/2005/Atomquot;> <workspace> <atom:title>Workspace</atom:title> <collection href=quot;http://www.verbosemode.com/wp-app.php/postsquot;> <atom:title>Posts</atom:title> <accept>application/atom+xml;type=entry</accept> <categories href=quot;http://www.verbosemode.com/wp-app.php/categoriesquot;/> </collection> <collection href=quot;http://www.verbosemode.com/wp-app.php/attachmentsquot;> <atom:title>Media</atom:title> <accept>image/*</accept> <accept>audio/*</accept> <accept>video/*</accept> </collection> </workspace> </service> David Calavera Conferencia Rails 2007
  41. 41. atomPub:service <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <service xmlns=quot;http://www.w3.org/2007/appquot; xmlns:atom=quot;http://www.w3.org/2005/Atomquot;> <workspace> <atom:title>Workspace</atom:title> <collection href=quot;http://www.verbosemode.com/wp-app.php/postsquot;> <atom:title>Posts</atom:title> <accept>application/atom+xml;type=entry</accept> <categories href=quot;http://www.verbosemode.com/wp-app.php/categoriesquot;/> </collection> <collection href=quot;http://www.verbosemode.com/wp-app.php/attachmentsquot;> <atom:title>Media</atom:title> <accept>image/*</accept> <accept>audio/*</accept> <accept>video/*</accept> </collection> </workspace> </service> David Calavera Conferencia Rails 2007
  42. 42. atomPub:service <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <service xmlns=quot;http://www.w3.org/2007/appquot; xmlns:atom=quot;http://www.w3.org/2005/Atomquot;> <workspace> <atom:title>Workspace</atom:title> <collection href=quot;http://www.verbosemode.com/wp-app.php/postsquot;> <atom:title>Posts</atom:title> <accept>application/atom+xml;type=entry</accept> <categories href=quot;http://www.verbosemode.com/wp-app.php/categoriesquot;/> </collection> <collection href=quot;http://www.verbosemode.com/wp-app.php/attachmentsquot;> <atom:title>Media</atom:title> <accept>image/*</accept> <accept>audio/*</accept> <accept>video/*</accept> </collection> </workspace> </service> David Calavera Conferencia Rails 2007
  43. 43. atomPub:categories GET 'http://www.verbosemode.com/wp-app.php/categories' HTTP/1.1 200 OK David Calavera Conferencia Rails 2007
  44. 44. atomPub:categories <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <app:categories xmlns:app=quot;http://www.w3.org/2007/appquot; xmlns=quot;http://www.w3.org/2005/Atomquot; fixed=quot;yesquot; scheme=quot;http://www.verbosemode.comquot;> <category term=quot;atomPubquot; /> <category term=quot;railsquot; /> </app:categories> David Calavera Conferencia Rails 2007
  45. 45. atomPub:collection POST 'http://www.verbosemode.com/wp-app.php/posts' HTTP/1.1 201 Created Content-Type: */* Location: 'http://www.verbosemode.com/wp-app.php/post/3' Content-Location: 'http://www.verbosemode.com/wp-app.php/post/3' GET 'http://www.verbosemode.com/wp-app.php/posts' HTTP/1.1 200 OK David Calavera Conferencia Rails 2007
  46. 46. atomPub:collection <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <feed xmlns=quot;http://www.w3.org/2005/Atomquot; xmlns:app=quot;http://www.w3.org/2007/appquot; xml:lang=quot;enquot;> <id>http://www.verbosemode.com/wp-app.php/posts</id> <updated>2007-11-04T11:38:28Z</updated> <title type=quot;textquot;>Verbose mode</title> <link rel=quot;firstquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <link rel=quot;lastquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <link rel=quot;selfquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <entry> <id>http://www.verbosemode.com/?p=3</id> <title type=quot;textquot;>Spanish Rails Conf 07</title> <app:edited>2007-11-04T11:38:28Z</app:edited> <link rel=quot;editquot; href=quot;http://www.verbosemode.com/wp-app.php/post/3quot;/> <app:control><app:draft>no</app:draft></app:control> ... David Calavera Conferencia Rails 2007
  47. 47. atomPub:collection <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <feed xmlns=quot;http://www.w3.org/2005/Atomquot; xmlns:app=quot;http://www.w3.org/2007/appquot; xml:lang=quot;enquot;> <id>http://www.verbosemode.com/wp-app.php/posts</id> <updated>2007-11-04T11:38:28Z</updated> <title type=quot;textquot;>Verbose mode</title> <link rel=quot;firstquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <link rel=quot;lastquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <link rel=quot;selfquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <entry> <id>http://www.verbosemode.com/?p=3</id> <title type=quot;textquot;>Spanish Rails Conf 07</title> <app:edited>2007-11-04T11:38:28Z</app:edited> <link rel=quot;editquot; href=quot;http://www.verbosemode.com/wp-app.php/post/3quot;/> <app:control><app:draft>no</app:draft></app:control> ... David Calavera Conferencia Rails 2007
  48. 48. atomPub:collection <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <feed xmlns=quot;http://www.w3.org/2005/Atomquot; xmlns:app=quot;http://www.w3.org/2007/appquot; xml:lang=quot;enquot;> <id>http://www.verbosemode.com/wp-app.php/posts</id> <updated>2007-11-04T11:38:28Z</updated> <title type=quot;textquot;>Verbose mode</title> <link rel=quot;firstquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <link rel=quot;lastquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <link rel=quot;selfquot; href=quot;http://www.verbosemode.com/wp-app.php/postsquot;/> <entry> <id>http://www.verbosemode.com/?p=3</id> <title type=quot;textquot;>Spanish Rails Conf 07</title> <app:edited>2007-11-04T11:38:28Z</app:edited> <link rel=quot;editquot; href=quot;http://www.verbosemode.com/wp-app.php/post/3quot;/> <app:control><app:draft>no</app:draft></app:control> ... David Calavera Conferencia Rails 2007
  49. 49. atomPub:entry PUT 'http://www.verbosemode.com/wp-app.php/post/3' HTTP/1.1 204 No Content Content-Type: application/atom+xml;type=entry DELETE 'http://www.verbosemode.com/wp-app.php/post/3' HTTP/1.1 200 OK GET 'http://www.verbosemode.com/wp-app.php/post/3' HTTP/1.1 200 OK David Calavera Conferencia Rails 2007
  50. 50. atomPub:entry <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <entry xmlns=quot;http://www.w3.org/2005/Atomquot; xmlns:app=quot;http://www.w3.org/2007/appquot; xml:lang=quot;enquot;> <id>http://www.verbosemode.com/?p=3</id> <title type=quot;textquot;>Spanish Rails Conf 07</title> <updated>2007-11-04T15:43:49Z</updated> <published>2007-11-04T11:38:28Z</published> <app:edited>2007-11-04T15:43:49Z</app:edited> <app:control><app:draft>no</app:draft></app:control> <author><name>david</name></author> <content type=quot;xhtmlquot;><div xmlns='http://www.w3.org/1999/xhtml'> Next November 22 and 23 I'm going to attend to ...</div></content> <link rel=quot;editquot; href=quot;http://www.verbosemode.com/wp-app.php/post/3quot; /> <category scheme=quot;http://www.verbosemode.comquot; term=quot;atomPubquot; /> <category scheme=quot;http://www.verbosemode.comquot; term=quot;railsquot; /> <summary type=quot;textquot;>Next November 22 and 23 I’m ...</summary> </entry> David Calavera Conferencia Rails 2007
  51. 51. atomPub:entry ¿y... qué pasa con los otros tipos de recursos? <entry xmlns=quot;http://www.w3.org/2005/Atomquot; xmlns:app=quot;http://www.w3.org/2007/appquot; xml:lang=quot;enquot;> <id>http://www.verbosemode.com/wp-content/uploads/2007/11/avatar.png</id> <title type=quot;textquot;>avatar poster</title> <updated>2007-11-13T21:59:55Z</updated> <published>2007-11-13T21:59:55Z</published> <app:edited>2007-11-13T21:59:55Z</app:edited> <app:control><app:draft>no</app:draft></app:control> <author><name>david</name></author> <link rel=quot;edit-mediaquot; href=quot;http://www.verbosemode.com/wp-app.php/attachment/file/4quot; /> <link rel=quot;editquot; href=quot;http://www.verbosemode.com/wp-app.php/post/4quot; /> <content type=quot;image/pngquot; src=quot;http://www.verbosemode.com/wp-content/uploads/2007/11/avatar.pngquot;/> </entry> David Calavera Conferencia Rails 2007
  52. 52. atomPub:entry ¿y... qué pasa con los otros tipos de recursos? PUT 'http://www.verbosemode.com/wp-app.php/attachment/file/4' HTTP/1.1 204 No Content Content-Type: */* DELETE 'http://www.verbosemode.com/wp-app.php/attachment/file/4' HTTP/1.1 200 OK GET 'http://www.verbosemode.com/wp-app.php/attachment/file/4' HTTP/1.1 200 OK David Calavera Conferencia Rails 2007
  53. 53. atomPub ¿pero... hay gente que usa esto?
  54. 54. ๏ google: gdata, youtube, openSocial David Calavera Conferencia Rails 2007
  55. 55. • google: gdata, youtube, openSocial ๏ microsoft: windows live writer David Calavera Conferencia Rails 2007
  56. 56. • google: gdata, youtube, openSocial • microsoft: windows live writer ๏ ibm: lotus connections David Calavera Conferencia Rails 2007
  57. 57. • google: gdata, youtube, openSocial • microsoft: windows live writer • ibm: lotus connections ๏ wordpress David Calavera Conferencia Rails 2007
  58. 58. • google: gdata, youtube, openSocial • microsoft: windows live writer • ibm: lotus connections • wordpress ๏ nokia: liveblog David Calavera Conferencia Rails 2007
  59. 59. • google: gdata, youtube, openSocial • microsoft: windows live writer • ibm: lotus connections • wordpress • nokia: liveblog ๏ six apart: typepad, movable type David Calavera Conferencia Rails 2007
  60. 60. • google: gdata, youtube, openSocial • microsoft: windows live writer • ibm: lotus connections • wordpress • nokia: liveblog • six apart: typepad, movable type ๏ 11870.com
  61. 61. ruby sin más
  62. 62. Net::HTTP David Calavera Conferencia Rails 2007
  63. 63. Net::HTTP ๏ fácil de mantener David Calavera Conferencia Rails 2007
  64. 64. Net::HTTP • fácil de mantener ๏ respuesta condicionada al estado David Calavera Conferencia Rails 2007
  65. 65. HTTPResponse HTTPSuccess # 2xx HTTPOK # 200 HTTPCreated # 201 HTTPRedirection # 3xx HTTPNotModified # 304 HTTPClientError # 4xx HTTPBadRequest # 400 HTTPUnauthorized # 401 HTTPForbidden # 403 HTTPNotFound # 404 HTTPPreconditionFailed # 412 HTTPUnsupportedMediaType # 415 HTTPServerError # 5xx HTTPInternalServerError # 500 David Calavera Conferencia Rails 2007
  66. 66. Net:HTTP • fácil de mantener • respuesta condicionada al estado ๏ no sabe si estoy en una capa segura David Calavera Conferencia Rails 2007
  67. 67. require 'net/http' require 'net/https' @uri = 'https://registro.conferenciarails.org' http = Net::HTTP.new @uri http.use_ssl = true if @uri =~ /^https/ David Calavera Conferencia Rails 2007
  68. 68. los cuatro verbos http Net::HTTP.start(@uri.host, @uri.port) do |http| end David Calavera Conferencia Rails 2007
  69. 69. los cuatro verbos http Net::HTTP.start(@uri.host, @uri.port) do |http| #POST http.request Net::HTTP::Post.new(@uri.path), data end David Calavera Conferencia Rails 2007
  70. 70. los cuatro verbos http Net::HTTP.start(@uri.host, @uri.port) do |http| #POST http.request Net::HTTP::Post.new(@uri.path), data #GET http.request Net::HTTP::Get.new(@uri.path) end David Calavera Conferencia Rails 2007
  71. 71. los cuatro verbos http Net::HTTP.start(@uri.host, @uri.port) do |http| #POST http.request Net::HTTP::Post.new(@uri.path), data #GET http.request Net::HTTP::Get.new(@uri.path) #PUT http.request Net::HTTP::Put.new(@uri.path), data end David Calavera Conferencia Rails 2007
  72. 72. los cuatro verbos http Net::HTTP.start(@uri.host, @uri.port) do |http| #POST http.request Net::HTTP::Post.new(@uri.path), data #GET http.request Net::HTTP::Get.new(@uri.path) #PUT http.request Net::HTTP::Put.new(@uri.path), data #DELETE http.request Net::HTTP::Delete.new(@uri.path) end David Calavera Conferencia Rails 2007
  73. 73. REXML ๏ parser completo David Calavera Conferencia Rails 2007
  74. 74. REXML • parser completo ๏ escrito completamente en ruby David Calavera Conferencia Rails 2007
  75. 75. REXML • parser completo • escrito completamente en ruby ๏ pasa los test de aceptación de Oasis David Calavera Conferencia Rails 2007
  76. 76. REXML • parser completo • escrito completamente en ruby • pasa los test de aceptación de Oasis ๏ soporta XPath David Calavera Conferencia Rails 2007
  77. 77. REXML y xpath NS = {'atom' => 'http://www.w3.org/2005/Atom', 'app' => 'http://www.w3.org/2007/app', 'georss' => 'http://www.georss.org/georss/10', 'gml' => 'http://www.opengis.net/gml' } REXML::XPath.each( feed.root, './atom:entry', NS) do |entry| title = REXML::XPath.first(entry, './atom:title/text()', NS) edited = REXML::XPath.first(entry, './app:edited/text()', NS) pos = REXML::XPath.first(entry, './georss:where/gml:Point/gml:pos/text()', NS) end David Calavera Conferencia Rails 2007
  78. 78. REXML y xpath NS = {'atom' => 'http://www.w3.org/2005/Atom', 'app' => 'http://www.w3.org/2007/app', 'georss' => 'http://www.georss.org/georss/10', 'gml' => 'http://www.opengis.net/gml' } REXML::XPath.each( feed.root, './atom:entry', NS) do |entry| title = REXML::XPath.first(entry, './atom:title/text()', NS) edited = REXML::XPath.first(entry, './app:edited/text()', NS) pos = REXML::XPath.first(entry, './georss:where/gml:Point/gml:pos/text()', NS) end David Calavera Conferencia Rails 2007
  79. 79. REXML y xpath NS = {'atom' => 'http://www.w3.org/2005/Atom', 'app' => 'http://www.w3.org/2007/app', 'georss' => 'http://www.georss.org/georss/10', 'gml' => 'http://www.opengis.net/gml' } REXML::XPath.each( feed.root, './atom:entry', NS) do |entry| title = REXML::XPath.first(entry, './atom:title/text()', NS) edited = REXML::XPath.first(entry, './app:edited/text()', NS) pos = REXML::XPath.first(entry, './georss:where/gml:Point/gml:pos/text()', NS) end David Calavera Conferencia Rails 2007
  80. 80. REXML y xpath NS = {'atom' => 'http://www.w3.org/2005/Atom', 'app' => 'http://www.w3.org/2007/app', 'georss' => 'http://www.georss.org/georss/10', 'gml' => 'http://www.opengis.net/gml' } REXML::XPath.each( feed.root, './atom:entry', NS) do |entry| title = REXML::XPath.first(entry, './atom:title/text()', NS) edited = REXML::XPath.first(entry, './app:edited/text()', NS) pos = REXML::XPath.first(entry, './georss:where/gml:Point/gml:pos/text()', NS) end David Calavera Conferencia Rails 2007
  81. 81. REXML y xpath NS = {'atom' => 'http://www.w3.org/2005/Atom', 'app' => 'http://www.w3.org/2007/app', 'georss' => 'http://www.georss.org/georss/10', 'gml' => 'http://www.opengis.net/gml' } REXML::XPath.each( feed.root, './atom:entry', NS) do |entry| title = REXML::XPath.first(entry, './atom:title/text()', NS) edited = REXML::XPath.first(entry, './app:edited/text()', NS) pos = REXML::XPath.first(entry, './georss:where/gml:Point/gml:pos/text()', NS) end David Calavera Conferencia Rails 2007
  82. 82. Builder ๏ crea xml fácilmente David Calavera Conferencia Rails 2007
  83. 83. require 'builder' builder = Builder::XmlMarkup.new xml = builder.feed( 'xmlns' => 'http://www.w3.org/2005/Atom' ) do |feed| feed.id 'http://conferenciarails.org/atomPub' feed.updated Time.now feed.author do |author| author.name 'David Calavera' end feed.entry do |entry| entry.title 'entrada para la conferencia rails' end end David Calavera Conferencia Rails 2007
  84. 84. Builder • crea xml fácilmente ๏ no solo se usa con rails David Calavera Conferencia Rails 2007
  85. 85. ๏ in the beginning... was the command line builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2) David Calavera Conferencia Rails 2007
  86. 86. • in the beginning... was the command line builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2) ๏ vamos de camping Camping.goes :Atom module Atom::Views def index html do head do title 'Atom Publishing Protocol @ conferecia rails' end body do ... end end end David Calavera Conferencia Rails 2007
  87. 87. ruby extras
  88. 88. atom-tools http://code.necronomicorp.com/atom-tools ๏ parsea y manipula feeds David Calavera Conferencia Rails 2007
  89. 89. atom-tools http://code.necronomicorp.com/atom-tools • parsea y manipula feeds ๏ adaptado al rfc 5023 David Calavera Conferencia Rails 2007
  90. 90. atom-tools http://code.necronomicorp.com/atom-tools • parsea y manipula feeds • adaptado al rfc 5023 ๏ abstracción de http y xml David Calavera Conferencia Rails 2007
  91. 91. require 'atom-tools' http = Atom::HTTP.new http.user = 'david' http.pass = 'my password' http.always_auth :basic service = Atom::Service.new 'http://verbosemode.com/wp-app.php/service', http service.collections.each do |collection| puts collection.accepts end David Calavera Conferencia Rails 2007
  92. 92. require 'atom-tools' http = Atom::HTTP.new http.user = 'david' http.pass = 'my password' http.always_auth :basic service = Atom::Service.new 'http://verbosemode.com/wp-app.php/service', http service.collections.each do |collection| puts collection.accepts end David Calavera Conferencia Rails 2007
  93. 93. require 'atom-tools' http = Atom::HTTP.new http.user = 'david' http.pass = 'my password' http.always_auth :basic service = Atom::Service.new 'http://verbosemode.com/wp-app.php/service', http service.collections.each do |collection| puts collection.accepts end David Calavera Conferencia Rails 2007
  94. 94. atom_pub_server http://svn.thinkincode.net/rails/plugins/atom_pub_server ๏ rails es REST David Calavera Conferencia Rails 2007
  95. 95. atom_pub_server http://svn.thinkincode.net/rails/plugins/atom_pub_server • rails es REST ๏ mejor soporte para atom y atomPub David Calavera Conferencia Rails 2007
  96. 96. atom_feed do |feed| feed.title(quot;My great blog!quot;) feed.updated((@posts.first.created_at)) for post in @posts feed.entry(post) do |entry| entry.tag!('georss:where', 'xmlns:georss' => 'http://www.georss.org/georss/10') do |where| where.tag!('gml:Poing', 'xmlns:gml' => 'http://www.opengis.net/gml') do |point| point.tag!('gml:pos', nil, '40.419967 -3.698965') end end David Calavera Conferencia Rails 2007
  97. 97. atom_feed({'xmlns:georss' => 'http://www.georss.org/georss/10', 'xmlns:gml' => 'http://www.opengis.net/gml'}) do |feed| feed.title(quot;My great blog!quot;) feed.updated((@posts.first.created_at)) for post in @posts feed.entry(post) do |entry| entry.georss:where do |where| where.gml:Point do |point| point.tag!('gml:pos', '40.419967 -3.698965') end end David Calavera Conferencia Rails 2007
  98. 98. atom_pub_server http://svn.thinkincode.net/rails/plugins/atom_pub_server • rails es REST • mejor soporte para atom y atomPub ๏ acts_as_collection David Calavera Conferencia Rails 2007
  99. 99. class PostsController < ApplicationController acts_as_collection :title => 'Posts', :workspace => 'Blog', :accept => Mime::ATOM_ENTRY, :href => 'http::/verbosemode.com/atomPub/posts', :categories => [ { :fixed => 'yes', :scheme => 'http://verbosemode.com/tags', :category => [{:term => 'rails'}, {:term => 'plugins'}] }, {:href => 'http://verbosemode.com/mysections'} ] end David Calavera Conferencia Rails 2007
  100. 100. atom_pub_server http://svn.thinkincode.net/rails/plugins/atom_pub_server • rails es REST • mejor soporte para atom y atomPub • acts_as_collection ๏ acts_as_service_document David Calavera Conferencia Rails 2007
  101. 101. class ServicesController < ApplicationController acts_as_service_document def index render :xml => service_document end end David Calavera Conferencia Rails 2007
  102. 102. the ape http://www.tbray.org/ape ๏ the atom publishing exerciser
  103. 103. the ape http://www.tbray.org/ape • the atom publishing exerciser ๏ introspección!!! David Calavera Conferencia Rails 2007
  104. 104. David Calavera Conferencia Rails 2007
  105. 105. the ape http://www.tbray.org/ape • the atom publishing exerciser • introspección!!! ๏ varios sistemas de autenticación David Calavera Conferencia Rails 2007
  106. 106. David Calavera Conferencia Rails 2007
  107. 107. the ape http://www.tbray.org/ape • the atom publishing exerciser • introspección!!! • varios sistemas de autenticación ๏ no es muy fácil de instalar (de momento) David Calavera Conferencia Rails 2007
  108. 108. the ape http://www.tbray.org/ape • the atom publishing exerciser • introspección!!! • varios sistemas de autenticación • no es muy fácil de instalar (de momento) ๏ no es muy fácil de configurar (de momento) David Calavera Conferencia Rails 2007
  109. 109. la api de 11870.com http://11870.com/api
  110. 110. por partes ๏ api de búsqueda ➡ formato openSearch (http://opensearch.org) David Calavera Conferencia Rails 2007
  111. 111. <?xml version=quot; 1.0quot; encoding=quot;UTF-8quot;?> <service xmlns:atom=quot;http://www.w3.org/2005/Atomquot; xmlns=quot;http://www.w3.org/2007/app quot; xml:base=quot;http://11870.com/quot;> <workspace> <atom:title type=quot;textquot;>11870 workspace</atom:title> <collection href=quot;/api/v1/searchquot;> <atom:title type=quot;textquot;>Search</atom:title> </collection> </workspace> </service> David Calavera Conferencia Rails 2007
  112. 112. por partes • api de búsqueda ๏ api de gestión de contenidos David Calavera Conferencia Rails 2007
  113. 113. <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <service xmlns:atom=quot;http://www.w3.org/2005/Atomquot; xmlns=quot; http://www.w3.org/2007/appquot; xml:base=quot;http://localhost/quot;> <workspace> <atom:title type=quot;textquot;>11870 workspace</atom:title> <collection href=quot;/api/v1/sites/calaveraquot;> <atom:title type=quot;textquot;>Sites</atom:title> <accept>application/atom+xml;type=entry</accept> <categories xmlns:oos=quot;http://11870.com/api/oos quot; href=quot;http://localhost/api/v1/lists/calaveraquot; oos:label=quot;listsquot;/> <categories xmlns:oos=quot; http://11870.com/api/oosquot; href=quot;http://localhost/api/v1/tags/calaveraquot; oos:label=quot;tagsquot;/> <categories xmlns:oos=quot; http://11870.com/api/oosquot; href=quot;http://localhost/api/v1/privacyquot; oos:label=quot;privacyquot;/> </collection> <collection href=quot;/api/v1/contacts/calaveraquot;> <atom:title type=quot;textquot;>Contacts</atom:title> <accept>application/atom+xml;type=entry</accept> <categories xmlns:oos=quot; http://11870.com/api/oosquot; href=quot;http://localhost/api/v1/trustedquot; oos:label=quot;trustedquot;/> </collection> <collection href=quot;/api/v1/usersquot;> <atom:title type=quot;textquot;>Users</atom:title> <accept>image/*</accept> <accept>application/atom+xml;type=entry</accept> </collection> <collection href=quot;/api/v1/searchquot;> <atom:title type=quot;textquot;>Search</atom:title> </collection> </workspace> </service> David Calavera Conferencia Rails 2007
  114. 114. más allá de atomPub ๏ sintaxis David Calavera Conferencia Rails 2007
  115. 115. <entry xmlns:app=quot;http://www.w3.org/2007/appquot; xmlns:oos=quot;http://11870.com/api/oosquot; xmlns:georss=quot;http://www.georss.org/georss/10quot; xmlns=quot;http://www.w3.org/2005/Atomquot; xml:lang=quot;enquot;> <id>http://11870.com/pro/23474/calavera</id> <title type=quot;textquot;>Apple Store Fifth Avenue</title> <oos:useraddress>767 5th Avenue</oos:useraddress> <oos:url>http://www.apple.com/retail/fifthavenue</oos:url> <oos:telephone>+1 212 3361440</oos:telephone> <oos:locality slug=quot;/us/new-yorkquot;>New York</oos:locality> <oos:country slug=quot;/usquot;>United States</oos:country> David Calavera Conferencia Rails 2007
  116. 116. más allá de atomPub • sintaxis ๏ autenticación David Calavera Conferencia Rails 2007
  117. 117. más allá de atomPub • sintaxis ๏ autenticación ➡ identificar aplicaciones David Calavera Conferencia Rails 2007
  118. 118. Net::HTTP.start( '11870.com' ) do |http| req = Net::HTTP::Get.new('/api/v1') req['appToken'] = 'el app token que 11870 te ha asignado' digest = Digest::MD5.hexdigest(quot;#{req['appToken']}#{la clave secreta}quot;) req['authSign'] = digest http.request req end David Calavera Conferencia Rails 2007
  119. 119. más allá de atomPub • sintaxis ๏ autenticación ➡ identificar aplicaciones ➡ autenticar usuarios David Calavera Conferencia Rails 2007
  120. 120. request['Authorization'] = 'WSSE profile=quot;UsernameTokenquot;' request['X-WSSE'] = wsse! def wsse! nonce = Array.new(10){ rand(0x1000000) }.pack('I*') nonce_b64 = [nonce].pack(quot;mquot;).chomp now = Time.now.gmtime.strftime(quot;%FT%TZquot;) digest = [Digest::SHA1.digest(nonce_b64 + now + @password)].pack(quot;mquot;).chomp %Q<UsernameToken Username=quot;#{@username}quot;, PasswordDigest=quot;#{digest}quot;, Nonce=quot;#{nonce_b64}quot;, Created=quot;#{now}quot;> end David Calavera Conferencia Rails 2007
  121. 121. más allá de atomPub • sintaxis ๏ autenticación ➡ identificar aplicaciones ➡ autenticar usuarios ➡ evolucionará a OAuth (http://oauth.net) David Calavera Conferencia Rails 2007
  122. 122. más allá de atomPub • sintaxis • autenticación ๏ múltiples representaciones David Calavera Conferencia Rails 2007
  123. 123. { quot;idquot;:quot;/api/v1/sites/calaveraquot;, quot;titlequot;:quot;Sitesquot;, quot;updatedquot;:quot;2007-09-28T07:53:46.000Zquot;, quot;authorsquot;:[{ quot;namequot;:quot;calaveraquot; } ], quot;linksquot;:[{ quot;hrefquot;:quot;http://11870.com/api/v1/sites/calaveraquot;, quot;relquot;:quot;selfquot; },{ quot;hrefquot;:quot;http://11870.com/api/v1/sites/calavera?page=2quot;, quot;relquot;:quot;nextquot; } ], quot;entriesquot;:[{ quot;langquot;:quot;esquot;, quot;idquot;:quot;http://11870.com/pro/23474/calaveraquot;, quot;titlequot;:quot;Apple Store Fifth Avenuequot;, quot;summaryquot;:quot;en directoquot;, quot;contentquot;:quot;estoy ahora mismo en esta... David Calavera Conferencia Rails 2007
  124. 124. más allá de atomPub • sintaxis • autenticación • múltiples representaciones ๏ control de versiones David Calavera Conferencia Rails 2007
  125. 125. ๏ ahora Net::HTTP.start( '11870.com' ) do |http| http.request Net::HTTP::Get.new('/api/v1') end David Calavera Conferencia Rails 2007
  126. 126. • ahora Net::HTTP.start( '11870.com' ) do |http| http.request Net::HTTP::Get.new('/api/v1') end ๏ en un futuro Net::HTTP.start( '11870.com' ) do |http| http.request Net::HTTP::Get.new('/api/v1.5') end David Calavera Conferencia Rails 2007
  127. 127. más allá de atomPub • sintaxis • autenticación • múltiples representaciones • control de versiones ๏ soporte de librerías David Calavera Conferencia Rails 2007
  128. 128. http://code.google.com/p/api-11870/ David Calavera Conferencia Rails 2007
  129. 129. más allá de atomPub • sintaxis • autenticación • múltiples representaciones • control de versiones • soporte de librerías ๏ ¡documentación! David Calavera Conferencia Rails 2007
  130. 130. http://groups.google.com/group/api-11870 David Calavera Conferencia Rails 2007
  131. 131. la api de 11870.com oos4ruby
  132. 132. búsqueda require 'oos4ruby' oos = Oos.new oos.auth_app 'appToken', 'secretKey' oos.search q => 'apple store in new york' oos.search bbox => ['SOUTH', 'WEST', 'NORTH', 'EAST'] oos.search lat => 'LATITUDE', lon => 'LONGITUDE', radius => '3000 METRES' oos.search tags => ['restaurant', 'cheap', 'clean'] David Calavera Conferencia Rails 2007
  133. 133. búsqueda require 'oos4ruby' oos = Oos.new oos.auth_app 'appToken', 'secretKey' oos.search q => 'apple store in new york' oos.search bbox => ['SOUTH', 'WEST', 'NORTH', 'EAST'] oos.search lat => 'LATITUDE', lon => 'LONGITUDE', radius => '3000 METRES' oos.search tags => ['restaurant', 'cheap', 'clean'] David Calavera Conferencia Rails 2007
  134. 134. búsqueda require 'oos4ruby' oos = Oos.new oos.auth_app 'appToken', 'secretKey' oos.search q => 'apple store in new york' oos.search bbox => ['SOUTH', 'WEST', 'NORTH', 'EAST'] oos.search lat => 'LATITUDE', lon => 'LONGITUDE', radius => '3000 METRES' oos.search tags => ['restaurant', 'cheap', 'clean'] David Calavera Conferencia Rails 2007
  135. 135. búsqueda require 'oos4ruby' oos = Oos.new oos.auth_app 'appToken', 'secretKey' oos.search q => 'apple store in new york' oos.search bbox => ['SOUTH', 'WEST', 'NORTH', 'EAST'] oos.search lat => 'LATITUDE', lon => 'LONGITUDE', radius => '3000 METRES' oos.search tags => ['restaurant', 'cheap', 'clean'] David Calavera Conferencia Rails 2007
  136. 136. búsqueda require 'oos4ruby' oos = Oos.new oos.auth_app 'appToken', 'secretKey' oos.search q => 'apple store in new york' oos.search bbox => ['SOUTH', 'WEST', 'NORTH', 'EAST'] oos.search lat => 'LATITUDE', lon => 'LONGITUDE', radius => '3000 METRES' oos.search tags => ['restaurant', 'cheap', 'clean'] David Calavera Conferencia Rails 2007
  137. 137. gestión require 'oos4ruby' oos = Oos.new oos.auth_user 'user email', 'auth token' user = oos.user user.sites.each do |pro| unless pro.multimedia.empty? pro.multimedia.each do |media| puts media.type puts media.src end end end user.contacts.create! :slug => 'calavera', :trusted => 'true' user.update_avatar! '/Users/david/skull.png' David Calavera Conferencia Rails 2007
  138. 138. gestión require 'oos4ruby' oos = Oos.new oos.auth_user 'user email', 'auth token' user = oos.user user.sites.each do |pro| unless pro.multimedia.empty? pro.multimedia.each do |media| puts media.type puts media.src end end end user.contacts.create! :slug => 'calavera', :trusted => 'true' user.update_avatar! '/Users/david/skull.png' David Calavera Conferencia Rails 2007
  139. 139. gestión require 'oos4ruby' oos = Oos.new oos.auth_user 'user email', 'auth token' user = oos.user user.sites.each do |pro| unless pro.multimedia.empty? pro.multimedia.each do |media| puts media.type puts media.src end end end user.contacts.create! :slug => 'calavera', :trusted => 'true' user.update_avatar! '/Users/david/skull.png' David Calavera Conferencia Rails 2007
  140. 140. gestión require 'oos4ruby' oos = Oos.new oos.auth_user 'user email', 'auth token' user = oos.user user.sites.each do |pro| unless pro.multimedia.empty? pro.multimedia.each do |media| puts media.type puts media.src end end end user.contacts.create! :slug => 'calavera', :trusted => 'true' user.update_avatar! '/Users/david/skull.png' David Calavera Conferencia Rails 2007
  141. 141. ¿...?
  142. 142. muchas gracias http://thinkincode.net

×