Skip to content

theball/babylon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babylon

DESCRIPTION:

Babylon is a framework to build XMPP Applications in Ruby. The framework uses EventMachine to handle network connections.

This framework can use both an XMPP Component (XEP-0114) and an XMPP Client. However, we strongly discourage any production application using a regular client.

FEATURES/PROBLEMS:

  • This hasn’t been tested.

  • Problems with quotes and double-quotes in text that are not handled correctly… I spent too many hours on this! Please help!

ROADMAP :

  • Instead of passing the stanzas as Nokogiri:XML:Node elements we should find a way to pass an “agnostic” ruby data-structure, so that app developers don’t have to learn/know/understand Nokogiri

  • HELPERS :

    * strip jids (...)
  • Improve the Client Connection to support other authentication than PLAIN SASL

SYNOPSIS:

You can build applications directly with Babylon, or you can use the Babylon::ClientConnection and Babylon::ComponentConnection to create simple apps, but you will then have to handle stanza routing and creation yourself. You can also use these classes in external gems.

To create an Application with Babylon:

  1. Install the gem

  2. The app contains a generator that will “build” a scaffold for your application.

    $> babylon myapp
  3. Use the generator or write your own controllers :

    $> script/generate message echo:10:"//message[@type='chat']/body" subscribed:0:"//presence[@type='subscribe']"

This will generate a “MessageController” class with 2 methods : echo and subscribed. “echo” will be called when the component receives message stanzas of type ‘chat’, while “subscribed” will be called for presence stanzas of type ‘subscribe’. 10 and 0 are the priority : useful when a stanza matches 2 XPath. Also, try to put high priorities to the “most frequent” stanzas to improve your component’s performance. This will also generate 2 ‘views’ used to build your stanzas. And finally, this will write 2 routes in the config/routes.rb

  1. Write your application’s code and views :

/app/controllers/message_controller.rb

class MessageController < Babylon::Base::Controller

  def echo
    extract_to_and_from
    body = @stanza.xpath("//message/body").first
    @resp = body.text.reverse
  end

  def subscribed
    extract_to_and_from
    @ack = "Thanks for following me!"
  end

  protected

  def extract_to_and_from
    @from = @stanza.attributes["to"].text
    @to = @stanza.attributes["from"].text
  end

end
  1. Implement the corresponding views (used to generate the messages). Babylon uses the same file conventions as Rails : a subdirectory for each controller, and one file per action :

Compared to Rails, we are using accessors (and not @variables assigned in the controller).

/app/views/message/echo.xml.builder

self.message(:to => to, :from => from, :type => :chat) do
    self.body(resp)
end

/app/views/message/subscribed.xml.builder

self.message(:to => to, :from => from, :type => :chat) do
  self.body(ack) # Same as self.send(:body, body)
end
  1. Make sure that the XMPP settings are correct in config/config.yaml. !!! You need to have a Jabber Component, regular clients will NOT work!!!

  2. And finally start the component :

    script/component
    

ADDITIONAL INFORMATION

This code hasn’t been tested at all! (yes, i know it’s bad, but I couldn’t have rspec working with eventmachine) Feel free to pull, branch, improve {code|specs|tests|docs} and we will merge it!

If you used a version before 0.0.6, please change your routes to use the new router DSL. (See template for more help). It shouldn’t be long… sorry for that.

REQUIREMENTS:

Gems : Eventmachine, nokogiri, YAML

Our goal is to limit the number of dependencies. Nokogiri seems to be only XML Library on Ruby that has a Push SAX Parser, that is why we are using it. It also seems pretty ‘fast’. However, we think it is bad to “force” the framework users to receive Nokogiri objects (too much coupling), so we’re looking for a Ruby datastcuture that would have an easy mapping with XML. Any thoughts?

INSTALL:

  • sudo gem install babylon

LICENSE:

(The MIT License)

Copyright © 2009 Julien Genestoux notifixio.us

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Babylon is a framework to build EventMachine based XMPP External Components in Ruby.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages