lib/blather/client/dsl.rb in blather-0.3.0 vs lib/blather/client/dsl.rb in blather-0.3.1
- old
+ new
@@ -11,18 +11,17 @@
# Prepare server settings
# setup [node@domain/resource], [password], [host], [port]
# host and port are optional defaulting to the domain in the JID and 5222 respectively
def setup(jid, password, host = nil, port = nil)
client.setup(jid, password, host, port)
- at_exit { client.run }
end
##
# Shutdown the connection.
# Flushes the write buffer then stops EventMachine
def shutdown
- client.stop
+ client.close
end
##
# Set handler for a stanza type
def handle(stanza_type, *guards, &block)
@@ -35,25 +34,25 @@
handle :ready, &block
end
##
# Set current status
- def status(state = nil, msg = nil)
+ def set_status(state = nil, msg = nil)
client.status = state, msg
end
##
# Direct access to the roster
- def roster
+ def my_roster
client.roster
end
##
# Write data to the stream
# Anything that resonds to #to_s can be paseed to the stream
def write(stanza)
- client.write(stanza)
+ client.write stanza
end
##
# Helper method to make sending basic messages easier
# say [jid], [msg]
@@ -66,34 +65,30 @@
def jid
client.jid
end
##
- #
+ # Request items or info from an entity
+ # discover (items|info), [jid], [node] do |response|
+ # end
def discover(what, who, where, &callback)
stanza = Blather::Stanza.class_from_registration(:query, "http://jabber.org/protocol/disco##{what}").new
stanza.to = who
stanza.node = where
client.temporary_handler stanza.id, &callback
write stanza
end
##
- # PubSub proxy
- def pubsub
- client.pubsub
- end
-
- ##
# Checks to see if the method is part of the handlers list.
# If so it creates a handler, otherwise it'll pass it back
# to Ruby's method_missing handler
- def method_missing(method, *args, &block)
- if Blather::Stanza.handler_list.include?(method)
- handle method, *args, &block
- else
- super
- end
+ Blather::Stanza.handler_list.each do |handler_name|
+ module_eval <<-METHOD, __FILE__, __LINE__
+ def #{handler_name}(*args, &callback)
+ handle :#{handler_name}, *args, &callback
+ end
+ METHOD
end
end #DSL
end #Blather