Encheção de linguiça :D




                          @dev_ton
Olá!




       @dev_ton
eu

Antônio Roberto ( ton )
e você




                          @dev_ton
2009


       @dev_ton
@dev_ton
Leroy




eu




             @dev_ton
@dev_ton
@dev_ton
apoio



        @dev_ton
Introdução ao
CRAMP e WebSockets

       apoio



                     @dev_ton
CRAMP



        @dev_ton
CRAMP

- O que é?
- Quando usar?




                         @dev_ton
CRAMP
Controller & Model




                     @dev_ton
CRAMP
Cramp::Controller

Os 4 estágios após uma requisição:
Initialization
Response Initialization
Starting
Finishing




...
CRAMP
Cramp::Controller
Helpers:
on_start
before_start
on_finish
periodic_timer
keep_connection_alive
respond_with
request_...
CRAMP
Cramp::Controller
on_start

 class Hello < Cramp::Controller::Action
   on_start :say_hello

   def say_hello
     r...
CRAMP
Cramp::Controller
before_start

 before_start :valid_param

 def valid_user
   if param[:id] =~ /[^a-zA-Z](.*)/
    ...
CRAMP
Cramp::Controller
on_finish
 class PollUserAction < Cramp::Controller::Action
   on_start :start_polling
   on_finish...
CRAMP
Cramp::Controller
periodic_timer

 class PollUserAction < Cramp::Controller::Action
   periodic_timer :poll_user, :e...
CRAMP
Cramp::Controller
keep_connection_alive


 class PollUserAction < Cramp::Controller::Action
   periodic_timer :poll_...
CRAMP
Cramp::Controller
respond_with


 def respond_with
   content_type = params[:format] == 'xml' ? 'application/xml' : ...
CRAMP
Cramp::Controller
request_limit_exceeded
 class PollUserAction < Cramp::Controller::Action
   periodic_timer :poll_u...
CRAMP
Cramp::Model




                       @dev_ton
CRAMP
Cramp::Model




                :(
                       @dev_ton
CRAMP
Cramp::Model

Cramp::Model.init(:username => 'root', :database =>
'cramp_development')

class User < Cramp::Model::B...
CRAMP
Cramp::Model

EM.run do
  User.select(:id, :name).limit(10).offset(20).first {|u| .. }
  User.where(User[:name].eq('...
CRAMP
Cramp::Model

EM.run do
  def user_saved(status)
    if status.success?
      ...
    else
      user = status.recor...
WebSocket



            @dev_ton
WebSocket
  A mágica!




              @dev_ton
WebSocket
                              4 passos

var location = 'http://localhost:8080/backend';
var socket = new WebSock...
WebSocket
   &
 CRAMP


            @dev_ton
WebSocket & CRAMP
Cramp::Controller::Websocket


Cramp::Controller::Websocket.backend = :thin



on_data




             ...
WebSocket & CRAMP
on_data

 Cramp::Controller::Websocket.backend = :thin

 class WelcomeController < Cramp::Controller::We...
Ajax & WebSockets




                    @dev_ton
DEMO :D



          @dev_ton
Obrigado! :)

email: forevertonny@gmail.com
twitter: @dev_ton
links
Indrodução ao CRAMP & WebSockets ( patrik )
http://m.onkey.org/2010/1/7/introducing-cramp
http://m.onkey.org/2010/1/...
Obrigado!




            @dev_ton
Upcoming SlideShare
Loading in...5
×

Cramp websockets

1,410

Published on

Slides da palestra ocorrida no dia 29/06 sobre CRAMP e WebSockets

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,410
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide





































  • Cramp websockets

    1. 1. Encheção de linguiça :D @dev_ton
    2. 2. Olá! @dev_ton
    3. 3. eu Antônio Roberto ( ton ) e você @dev_ton
    4. 4. 2009 @dev_ton
    5. 5. @dev_ton
    6. 6. Leroy eu @dev_ton
    7. 7. @dev_ton
    8. 8. @dev_ton
    9. 9. apoio @dev_ton
    10. 10. Introdução ao CRAMP e WebSockets apoio @dev_ton
    11. 11. CRAMP @dev_ton
    12. 12. CRAMP - O que é? - Quando usar? @dev_ton
    13. 13. CRAMP Controller & Model @dev_ton
    14. 14. CRAMP Cramp::Controller Os 4 estágios após uma requisição: Initialization Response Initialization Starting Finishing @dev_ton
    15. 15. CRAMP Cramp::Controller Helpers: on_start before_start on_finish periodic_timer keep_connection_alive respond_with request_limit_exceeded @dev_ton
    16. 16. CRAMP Cramp::Controller on_start class Hello < Cramp::Controller::Action   on_start :say_hello   def say_hello     render "Hello World! :)"     finish   end end @dev_ton
    17. 17. CRAMP Cramp::Controller before_start before_start :valid_param def valid_user   if param[:id] =~ /[^a-zA-Z](.*)/     yield   else     halt 500, {'Content-Type' => 'text/plain'}, "Invalid ID"   end end @dev_ton
    18. 18. CRAMP Cramp::Controller on_finish class PollUserAction < Cramp::Controller::Action   on_start :start_polling   on_finish :stop_polling   def start_polling     # Call find_user every 10 seconds     @timer = EventMachine::PeriodicTimer.new(2) { find_user }   end   def find_user     User.first {|u| render "#{u.inspect}n" }   end   def stop_polling     puts "Cancelling the timer.."     @timer.cancel   end end @dev_ton
    19. 19. CRAMP Cramp::Controller periodic_timer class PollUserAction < Cramp::Controller::Action periodic_timer :poll_user, :every => 2 def poll_user User.first {|u| render "#{u.inspect}n" } end end @dev_ton
    20. 20. CRAMP Cramp::Controller keep_connection_alive class PollUserAction < Cramp::Controller::Action   periodic_timer :poll_user, :every => 2   keep_connection_alive, :every => 30 end @dev_ton
    21. 21. CRAMP Cramp::Controller respond_with def respond_with   content_type = params[:format] == 'xml' ? 'application/xml' : 'application/json'   [200, {'Content-Type' => content_type}] end @dev_ton
    22. 22. CRAMP Cramp::Controller request_limit_exceeded class PollUserAction < Cramp::Controller::Action   periodic_timer :poll_user, :every => 2   periodic_timer :check_limit_exceed, :every => 10   def poll_user     ..   end   def check_limit_exceed     finish if request_limit_exceeded   end end @dev_ton
    23. 23. CRAMP Cramp::Model @dev_ton
    24. 24. CRAMP Cramp::Model :( @dev_ton
    25. 25. CRAMP Cramp::Model Cramp::Model.init(:username => 'root', :database => 'cramp_development') class User < Cramp::Model::Base attribute :id, :type => Integer, :primary_key => true attribute :name validates_presence_of :name end @dev_ton
    26. 26. CRAMP Cramp::Model EM.run do User.select(:id, :name).limit(10).offset(20).first {|u| .. } User.where(User[:name].eq('Lush')).limit(2).all {|users| ... } User.each {|user| .. } def lush_users_found(users) ... end User.where(User[:name].eq('Lush'), User[:id].gt(5)).all method(:lush_users_found) end @dev_ton
    27. 27. CRAMP Cramp::Model EM.run do def user_saved(status) if status.success? ... else user = status.record puts "Oops. Found errors : #{status.record.errors.inspect}" end end user = User.new user.save method(:user_saved) end @dev_ton
    28. 28. WebSocket @dev_ton
    29. 29. WebSocket A mágica! @dev_ton
    30. 30. WebSocket 4 passos var location = 'http://localhost:8080/backend'; var socket = new WebSocket(location); socket.onopen = function(data) { ... }; socket.onmessage = function(data) {... }; socket.onclose = function(data) { ... }; socket.send(data); https://gist.github.com/98c8448ba054b7992aff#file_example.js @dev_ton
    31. 31. WebSocket & CRAMP @dev_ton
    32. 32. WebSocket & CRAMP Cramp::Controller::Websocket Cramp::Controller::Websocket.backend = :thin on_data @dev_ton
    33. 33. WebSocket & CRAMP on_data Cramp::Controller::Websocket.backend = :thin class WelcomeController < Cramp::Controller::Websocket   on_data :received_data   def received_data(data)     render "Got your #{data}"   end end https://gist.github.com/d04affd72e2ea57039eb @dev_ton
    34. 34. Ajax & WebSockets @dev_ton
    35. 35. DEMO :D @dev_ton
    36. 36. Obrigado! :) email: forevertonny@gmail.com twitter: @dev_ton
    37. 37. links Indrodução ao CRAMP & WebSockets ( patrik ) http://m.onkey.org/2010/1/7/introducing-cramp http://m.onkey.org/2010/1/15/websockets-made-easy-with-cramp WebSockets API http://dev.w3.org/html5/websockets/ Video ( pubsubhubbub ) http://www.youtube.com/watch?v=B5kHx0rGkec App Apresentação http://github.com/devton/socketchat @dev_ton
    38. 38. Obrigado! @dev_ton
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×