lib/blather/client/dsl.rb in blather-0.8.0 vs lib/blather/client/dsl.rb in blather-0.8.1

- old
+ new

@@ -31,13 +31,10 @@ # @example Set the DSL to its own namespace. # # require 'blather/client/dsl' # module Echo # extend Blather::DSL - # def self.run - # client.run - # end # # when_ready { puts "Connected ! send messages to #{jid.stripped}." } # # subscription :request? do |s| # write_to_stream s.approve! @@ -51,20 +48,23 @@ # message :chat?, :body do |m| # say m.from, "You sent: #{m.body}" # end # end # + # Echo.setup 'foo@bar.com', 'foobar' + # # EM.run { Echo.run } # # @example Create a class out of it # # require 'blather/client/dsl' # class Echo # include Blather::DSL # end # # echo = Echo.new + # echo.setup 'foo@bar.com', 'foobar' # echo.when_ready { puts "Connected ! send messages to #{jid.stripped}." } # # echo.subscription :request? do |s| # write_to_stream s.approve! # end @@ -76,11 +76,12 @@ # # echo.message :chat?, :body do |m| # say m.from, "You sent: #{m.body}" # end # - # EM.run { echo.client.run } + # EM.run { echo.run } + # module DSL autoload :PubSub, File.expand_path(File.join(File.dirname(__FILE__), *%w[dsl pubsub])) def self.append_features(o) @@ -124,9 +125,14 @@ # this is `nil` the domain on the JID will be used # @param [Fixnum, String] (optional) port the port to connect on # @param [Fixnum] (optional) connection_timeout the time to wait for connection to succeed before timing out def setup(jid, password, host = nil, port = nil, certs = nil, connection_timeout = nil) client.setup(jid, password, host, port, certs, connection_timeout) + end + + # Connect to the server. Must be run in the EventMachine reactor + def run + client.run end # Shutdown the connection. # Flushes the write buffer then stops EventMachine def shutdown