Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dominion Enterprises _H@<k@th0n_

Dominion Enterprises _H@<k@th0n_

Dominion Enterprise Hackathon Inspiration.

Ken Collins

April 11, 2012
Tweet

More Decks by Ken Collins

Other Decks in Technology

Transcript

  1. Divitis <div id="post"> <div id="header"> <span class="pubdate"> <span class="day">27</span> <span

    class="month">Dec</span> <span class="year">2010</span> </span> <h1>My New Blog</h1> </div> ... <div id="disqus_thread"> ... </div> </div> Monday, September 12, 11
  2. Semantic <article id="post"> <header> <time pubdate datetime="2010-12-27T00:00:00-05:00"> <span class="day">27</span> <span

    class="month">Dec</span> <span class="year">2010</span> </time> <h1>My New Blog</h1> </header> ... <footer id="disqus_thread"> ... </footer> </article> Monday, September 12, 11
  3. CSS3 Selectors Borders (images, radius, shadows) Colors (rgba, hsla, opacity)

    Text (wrap, overlay, shadows) Monday, September 12, 11
  4. CSS3 Selectors Borders (images, radius, shadows) Colors (rgba, hsla, opacity)

    Text (wrap, overlay, shadows) Backgrounds (gradients, clip, origin) Monday, September 12, 11
  5. CSS3 Selectors Borders (images, radius, shadows) Colors (rgba, hsla, opacity)

    Text (wrap, overlay, shadows) Backgrounds (gradients, clip, origin) Media Queries & Fonts Monday, September 12, 11
  6. Data Format (JSON & XML) { "id":8, "email":"[email protected]", "posts":[ {"id":30,

    "title":"First Post", "body":"Some text..."}, {"id":73, "title":"Second Post", "body":"More text..."} ] } Monday, September 12, 11
  7. <user> <id type="integer">8</id> <email>[email protected]</email> <posts type="array"> <post> <id type="integer">30</id> <title>First

    Post</title> <body>Some text...</body> </post> <post> <id type="integer">73</id> <title>Second Post</title> <body>More text...</body> </post> </posts> </user> Data Format (JSON & XML) Monday, September 12, 11
  8. Data Format (JSON & XML) Always Use Object Notation Rails

    has #to_json and #to_xml Define #as_json for obj primitive. Monday, September 12, 11
  9. Data Format (JSON & XML) Always Use Object Notation Rails

    has #to_json and #to_xml Define #as_json for obj primitive. New objects using #from_json and #from_xml methods. Monday, September 12, 11
  10. json = '{ "id":8, "email":"[email protected]", "posts":[ {"id":30, "title":"First Post", "body":"Some

    text..."}, {"id":73, "title":"Second Post", "body":"More text..."} ] }' user = User.new.from_json(json) user.email # => [email protected] user.posts.size # => 2 user.post.first.title # => "First Post" Data Format (JSON & XML) Monday, September 12, 11
  11. Representation State Transfer (REST) CREATE READ UPDATE DELETE DB HTTP

    INSERT SELECT UPDATE DELETE POST GET PUT DELETE Monday, September 12, 11
  12. Representation State Transfer (REST) CREATE READ UPDATE DELETE DB HTTP

    INSERT SELECT UPDATE DELETE POST GET PUT DELETE Monday, September 12, 11
  13. Representation State Transfer (REST) CREATE READ UPDATE DELETE DB HTTP

    INSERT SELECT UPDATE DELETE POST GET PUT DELETE Monday, September 12, 11
  14. Representation State Transfer (REST) GET /users {:controller=>"users", :action=>"index"} POST /users

    {:controller=>"users", :action=>"create"} GET /users/:id {:controller=>"users", :action=>"show"} PUT /users/:id {:controller=>"users", :action=>"update"} DELETE /users/:id {:controller=>"users", :action=>"destroy"} Monday, September 12, 11
  15. HTTP Clients In Ruby Many choices! Ruby’s core lib Net::HTTP

    looks more like wizardry vs idiomatic Ruby. Monday, September 12, 11
  16. HTTP Clients In Ruby Many choices! Ruby’s core lib Net::HTTP

    looks more like wizardry vs idiomatic Ruby. Research and pick one that works best for you. Monday, September 12, 11
  17. Typhoeus https:/ /github.com/dbalatero/typhoeus High Speed! Built On Top Of libcurl

    Simple RESTful Request Parallel Requests Memoization & Caching Monday, September 12, 11
  18. hydra = Typhoeus::Hydra.new request = Typhoeus::Request.new("http://localhost/posts/1.json") request.on_complete do |response| json

    = JSON.parse(response.body) post = Post.new.from_json(json) # Do crazy callback stuff... end hydra.queue request hydra.run # This is a blocking call that # returns once all requests are complete. Typhoeus Monday, September 12, 11
  19. xml = Builder::XmlMarkup.new(:indent=>2) xml.user do xml.id 8, :type => 'integer'

    xml.email "[email protected]" xml.posts :type => 'array' do xml.post {...} end end xml.target! # => # <user> # <id type="integer">8</id> # <email>[email protected]</email> # <posts type="array"> # <post> # ... # </post> # </posts> # </user> Pragmatic Use Of Builder http:/ /builder.rubyforge.org/ Monday, September 12, 11