blather 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/Manifest +36 -33
- data/README.rdoc +11 -17
- data/Rakefile +4 -3
- data/blather.gemspec +9 -9
- data/examples/drb_client.rb +7 -0
- data/examples/echo.rb +9 -18
- data/lib/blather.rb +140 -31
- data/lib/blather/{core/errors.rb → errors.rb} +0 -0
- data/lib/blather/{core/jid.rb → jid.rb} +0 -0
- data/lib/blather/{core/roster.rb → roster.rb} +0 -0
- data/lib/blather/{core/roster_item.rb → roster_item.rb} +0 -0
- data/lib/blather/{core/stanza.rb → stanza.rb} +6 -14
- data/lib/blather/stanza/error.rb +31 -0
- data/lib/blather/{core/stanza → stanza}/iq.rb +2 -2
- data/lib/blather/stanza/iq/query.rb +50 -0
- data/lib/blather/{core/stanza → stanza}/iq/roster.rb +3 -3
- data/lib/blather/{core/stanza → stanza}/message.rb +6 -2
- data/lib/blather/{core/stanza → stanza}/presence.rb +10 -0
- data/lib/blather/{core/stanza → stanza}/presence/status.rb +8 -6
- data/lib/blather/{core/stanza → stanza}/presence/subscription.rb +1 -1
- data/lib/blather/{core/stream.rb → stream.rb} +1 -1
- data/lib/blather/{core/stream → stream}/parser.rb +0 -5
- data/lib/blather/{core/stream → stream}/resource.rb +0 -0
- data/lib/blather/{core/stream → stream}/sasl.rb +16 -5
- data/lib/blather/{core/stream → stream}/session.rb +0 -0
- data/lib/blather/{core/stream → stream}/tls.rb +0 -0
- data/lib/blather/{core/sugar.rb → sugar.rb} +4 -0
- data/lib/blather/{core/xmpp_node.rb → xmpp_node.rb} +1 -3
- data/spec/blather/{core/jid_spec.rb → jid_spec.rb} +16 -1
- data/spec/blather/{core/roster_item_spec.rb → roster_item_spec.rb} +1 -1
- data/spec/blather/{core/roster_spec.rb → roster_spec.rb} +11 -1
- data/spec/blather/stanza/iq/query_spec.rb +34 -0
- data/spec/blather/stanza/iq/roster_spec.rb +7 -0
- data/spec/blather/stanza/iq_spec.rb +11 -0
- data/spec/blather/stanza/message_spec.rb +52 -0
- data/spec/blather/stanza/presence/status_spec.rb +102 -0
- data/spec/blather/stanza/presence/subscription_spec.rb +74 -0
- data/spec/blather/stanza/presence_spec.rb +24 -0
- data/spec/blather/{core/stanza_spec.rb → stanza_spec.rb} +1 -1
- data/spec/blather/{core/stream_spec.rb → stream_spec.rb} +208 -9
- data/spec/blather/{core/xmpp_node_spec.rb → xmpp_node_spec.rb} +1 -1
- metadata +75 -69
- data/examples/shell_client.rb +0 -28
- data/lib/blather/callback.rb +0 -24
- data/lib/blather/client.rb +0 -81
- data/lib/blather/core/stanza/iq/query.rb +0 -42
- data/lib/blather/extensions.rb +0 -4
- data/lib/blather/extensions/last_activity.rb +0 -55
- data/lib/blather/extensions/version.rb +0 -85
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: blather
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: "0. | 
| 4 | 
            +
              version: "0.2"
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Jeff Smick
         | 
| @@ -9,7 +9,7 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2008- | 
| 12 | 
            +
            date: 2008-12-19 00:00:00 -08:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -23,14 +23,14 @@ dependencies: | |
| 23 23 | 
             
                    version: "0"
         | 
| 24 24 | 
             
                version: 
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 26 | 
            -
              name: libxml
         | 
| 26 | 
            +
              name: libxml-ruby
         | 
| 27 27 | 
             
              type: :runtime
         | 
| 28 28 | 
             
              version_requirement: 
         | 
| 29 29 | 
             
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 30 30 | 
             
                requirements: 
         | 
| 31 31 | 
             
                - - ">="
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 33 | 
            -
                    version:  | 
| 33 | 
            +
                    version: 0.9.2
         | 
| 34 34 | 
             
                version: 
         | 
| 35 35 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 36 36 | 
             
              name: echoe
         | 
| @@ -52,81 +52,80 @@ extra_rdoc_files: | |
| 52 52 | 
             
            - CHANGELOG
         | 
| 53 53 | 
             
            - lib/autotest/discover.rb
         | 
| 54 54 | 
             
            - lib/autotest/spec.rb
         | 
| 55 | 
            -
            - lib/blather/ | 
| 56 | 
            -
            - lib/blather/ | 
| 57 | 
            -
            - lib/blather/ | 
| 58 | 
            -
            - lib/blather/ | 
| 59 | 
            -
            - lib/blather/ | 
| 60 | 
            -
            - lib/blather/ | 
| 61 | 
            -
            - lib/blather/ | 
| 62 | 
            -
            - lib/blather/ | 
| 63 | 
            -
            - lib/blather/ | 
| 64 | 
            -
            - lib/blather/ | 
| 65 | 
            -
            - lib/blather/ | 
| 66 | 
            -
            - lib/blather/ | 
| 67 | 
            -
            - lib/blather/ | 
| 68 | 
            -
            - lib/blather/ | 
| 69 | 
            -
            - lib/blather/ | 
| 70 | 
            -
            - lib/blather/ | 
| 71 | 
            -
            - lib/blather/ | 
| 72 | 
            -
            - lib/blather/ | 
| 73 | 
            -
            - lib/blather/ | 
| 74 | 
            -
            - lib/blather/ | 
| 75 | 
            -
            - lib/blather/ | 
| 76 | 
            -
            - lib/blather/core/xmpp_node.rb
         | 
| 77 | 
            -
            - lib/blather/extensions/last_activity.rb
         | 
| 78 | 
            -
            - lib/blather/extensions/version.rb
         | 
| 79 | 
            -
            - lib/blather/extensions.rb
         | 
| 55 | 
            +
            - lib/blather/errors.rb
         | 
| 56 | 
            +
            - lib/blather/jid.rb
         | 
| 57 | 
            +
            - lib/blather/roster.rb
         | 
| 58 | 
            +
            - lib/blather/roster_item.rb
         | 
| 59 | 
            +
            - lib/blather/stanza/error.rb
         | 
| 60 | 
            +
            - lib/blather/stanza/iq/query.rb
         | 
| 61 | 
            +
            - lib/blather/stanza/iq/roster.rb
         | 
| 62 | 
            +
            - lib/blather/stanza/iq.rb
         | 
| 63 | 
            +
            - lib/blather/stanza/message.rb
         | 
| 64 | 
            +
            - lib/blather/stanza/presence/status.rb
         | 
| 65 | 
            +
            - lib/blather/stanza/presence/subscription.rb
         | 
| 66 | 
            +
            - lib/blather/stanza/presence.rb
         | 
| 67 | 
            +
            - lib/blather/stanza.rb
         | 
| 68 | 
            +
            - lib/blather/stream/parser.rb
         | 
| 69 | 
            +
            - lib/blather/stream/resource.rb
         | 
| 70 | 
            +
            - lib/blather/stream/sasl.rb
         | 
| 71 | 
            +
            - lib/blather/stream/session.rb
         | 
| 72 | 
            +
            - lib/blather/stream/tls.rb
         | 
| 73 | 
            +
            - lib/blather/stream.rb
         | 
| 74 | 
            +
            - lib/blather/sugar.rb
         | 
| 75 | 
            +
            - lib/blather/xmpp_node.rb
         | 
| 80 76 | 
             
            - lib/blather.rb
         | 
| 81 77 | 
             
            - LICENSE
         | 
| 82 78 | 
             
            - README.rdoc
         | 
| 83 79 | 
             
            files: 
         | 
| 84 80 | 
             
            - CHANGELOG
         | 
| 81 | 
            +
            - examples/drb_client.rb
         | 
| 85 82 | 
             
            - examples/echo.rb
         | 
| 86 | 
            -
            - examples/shell_client.rb
         | 
| 87 83 | 
             
            - lib/autotest/discover.rb
         | 
| 88 84 | 
             
            - lib/autotest/spec.rb
         | 
| 89 | 
            -
            - lib/blather/ | 
| 90 | 
            -
            - lib/blather/ | 
| 91 | 
            -
            - lib/blather/ | 
| 92 | 
            -
            - lib/blather/ | 
| 93 | 
            -
            - lib/blather/ | 
| 94 | 
            -
            - lib/blather/ | 
| 95 | 
            -
            - lib/blather/ | 
| 96 | 
            -
            - lib/blather/ | 
| 97 | 
            -
            - lib/blather/ | 
| 98 | 
            -
            - lib/blather/ | 
| 99 | 
            -
            - lib/blather/ | 
| 100 | 
            -
            - lib/blather/ | 
| 101 | 
            -
            - lib/blather/ | 
| 102 | 
            -
            - lib/blather/ | 
| 103 | 
            -
            - lib/blather/ | 
| 104 | 
            -
            - lib/blather/ | 
| 105 | 
            -
            - lib/blather/ | 
| 106 | 
            -
            - lib/blather/ | 
| 107 | 
            -
            - lib/blather/ | 
| 108 | 
            -
            - lib/blather/ | 
| 109 | 
            -
            - lib/blather/ | 
| 110 | 
            -
            - lib/blather/core/xmpp_node.rb
         | 
| 111 | 
            -
            - lib/blather/extensions/last_activity.rb
         | 
| 112 | 
            -
            - lib/blather/extensions/version.rb
         | 
| 113 | 
            -
            - lib/blather/extensions.rb
         | 
| 85 | 
            +
            - lib/blather/errors.rb
         | 
| 86 | 
            +
            - lib/blather/jid.rb
         | 
| 87 | 
            +
            - lib/blather/roster.rb
         | 
| 88 | 
            +
            - lib/blather/roster_item.rb
         | 
| 89 | 
            +
            - lib/blather/stanza/error.rb
         | 
| 90 | 
            +
            - lib/blather/stanza/iq/query.rb
         | 
| 91 | 
            +
            - lib/blather/stanza/iq/roster.rb
         | 
| 92 | 
            +
            - lib/blather/stanza/iq.rb
         | 
| 93 | 
            +
            - lib/blather/stanza/message.rb
         | 
| 94 | 
            +
            - lib/blather/stanza/presence/status.rb
         | 
| 95 | 
            +
            - lib/blather/stanza/presence/subscription.rb
         | 
| 96 | 
            +
            - lib/blather/stanza/presence.rb
         | 
| 97 | 
            +
            - lib/blather/stanza.rb
         | 
| 98 | 
            +
            - lib/blather/stream/parser.rb
         | 
| 99 | 
            +
            - lib/blather/stream/resource.rb
         | 
| 100 | 
            +
            - lib/blather/stream/sasl.rb
         | 
| 101 | 
            +
            - lib/blather/stream/session.rb
         | 
| 102 | 
            +
            - lib/blather/stream/tls.rb
         | 
| 103 | 
            +
            - lib/blather/stream.rb
         | 
| 104 | 
            +
            - lib/blather/sugar.rb
         | 
| 105 | 
            +
            - lib/blather/xmpp_node.rb
         | 
| 114 106 | 
             
            - lib/blather.rb
         | 
| 115 107 | 
             
            - LICENSE
         | 
| 108 | 
            +
            - Manifest
         | 
| 116 109 | 
             
            - Rakefile
         | 
| 117 110 | 
             
            - README.rdoc
         | 
| 118 | 
            -
            - spec/blather/ | 
| 119 | 
            -
            - spec/blather/ | 
| 120 | 
            -
            - spec/blather/ | 
| 121 | 
            -
            - spec/blather/ | 
| 122 | 
            -
            - spec/blather/ | 
| 123 | 
            -
            - spec/blather/ | 
| 111 | 
            +
            - spec/blather/jid_spec.rb
         | 
| 112 | 
            +
            - spec/blather/roster_item_spec.rb
         | 
| 113 | 
            +
            - spec/blather/roster_spec.rb
         | 
| 114 | 
            +
            - spec/blather/stanza/iq/query_spec.rb
         | 
| 115 | 
            +
            - spec/blather/stanza/iq/roster_spec.rb
         | 
| 116 | 
            +
            - spec/blather/stanza/iq_spec.rb
         | 
| 117 | 
            +
            - spec/blather/stanza/message_spec.rb
         | 
| 118 | 
            +
            - spec/blather/stanza/presence/status_spec.rb
         | 
| 119 | 
            +
            - spec/blather/stanza/presence/subscription_spec.rb
         | 
| 120 | 
            +
            - spec/blather/stanza/presence_spec.rb
         | 
| 121 | 
            +
            - spec/blather/stanza_spec.rb
         | 
| 122 | 
            +
            - spec/blather/stream_spec.rb
         | 
| 123 | 
            +
            - spec/blather/xmpp_node_spec.rb
         | 
| 124 124 | 
             
            - spec/build_safe.rb
         | 
| 125 125 | 
             
            - spec/spec_helper.rb
         | 
| 126 | 
            -
            - Manifest
         | 
| 127 126 | 
             
            - blather.gemspec
         | 
| 128 127 | 
             
            has_rdoc: true
         | 
| 129 | 
            -
            homepage:  | 
| 128 | 
            +
            homepage: http://github.com/sprsquish/blather/tree/master
         | 
| 130 129 | 
             
            post_install_message: 
         | 
| 131 130 | 
             
            rdoc_options: 
         | 
| 132 131 | 
             
            - --line-numbers
         | 
| @@ -164,9 +163,16 @@ signing_key: | |
| 164 163 | 
             
            specification_version: 2
         | 
| 165 164 | 
             
            summary: An evented XMPP library written on EventMachine and libxml-ruby
         | 
| 166 165 | 
             
            test_files: 
         | 
| 167 | 
            -
            - spec/blather/ | 
| 168 | 
            -
            - spec/blather/ | 
| 169 | 
            -
            - spec/blather/ | 
| 170 | 
            -
            - spec/blather/ | 
| 171 | 
            -
            - spec/blather/ | 
| 172 | 
            -
            - spec/blather/ | 
| 166 | 
            +
            - spec/blather/jid_spec.rb
         | 
| 167 | 
            +
            - spec/blather/roster_item_spec.rb
         | 
| 168 | 
            +
            - spec/blather/roster_spec.rb
         | 
| 169 | 
            +
            - spec/blather/stanza/iq/query_spec.rb
         | 
| 170 | 
            +
            - spec/blather/stanza/iq/roster_spec.rb
         | 
| 171 | 
            +
            - spec/blather/stanza/iq_spec.rb
         | 
| 172 | 
            +
            - spec/blather/stanza/message_spec.rb
         | 
| 173 | 
            +
            - spec/blather/stanza/presence/status_spec.rb
         | 
| 174 | 
            +
            - spec/blather/stanza/presence/subscription_spec.rb
         | 
| 175 | 
            +
            - spec/blather/stanza/presence_spec.rb
         | 
| 176 | 
            +
            - spec/blather/stanza_spec.rb
         | 
| 177 | 
            +
            - spec/blather/stream_spec.rb
         | 
| 178 | 
            +
            - spec/blather/xmpp_node_spec.rb
         | 
    
        data/examples/shell_client.rb
    DELETED
    
    | @@ -1,28 +0,0 @@ | |
| 1 | 
            -
            require 'lib/blather/client'
         | 
| 2 | 
            -
            include Blather
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            class ShellClient < Client
         | 
| 5 | 
            -
              def receive_roster(roster)
         | 
| 6 | 
            -
                super
         | 
| 7 | 
            -
                if roster.type == :result
         | 
| 8 | 
            -
                  start_highline
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
              end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              def receive_message(msg)
         | 
| 13 | 
            -
                
         | 
| 14 | 
            -
              end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              def start_highline
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            EM.run {
         | 
| 22 | 
            -
              shell = Shell.new
         | 
| 23 | 
            -
             | 
| 24 | 
            -
              #shell
         | 
| 25 | 
            -
              EM.spawn { shell.start }
         | 
| 26 | 
            -
             | 
| 27 | 
            -
              Blather.run 'orthie@jabber.local/Blather', 'orthie', shell
         | 
| 28 | 
            -
            }
         | 
    
        data/lib/blather/callback.rb
    DELETED
    
    | @@ -1,24 +0,0 @@ | |
| 1 | 
            -
            module Blather
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              class Callback
         | 
| 4 | 
            -
                include Comparable
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                attr_accessor :priority
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                def initialize(priority = 0, &callback)
         | 
| 9 | 
            -
                  @priority = priority
         | 
| 10 | 
            -
                  @callback = callback
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                def call(*args)
         | 
| 14 | 
            -
                  @callback.call(*args)
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                # Favor higher numbers
         | 
| 18 | 
            -
                def <=>(o)
         | 
| 19 | 
            -
                  self.priority <=> o.priority
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
              end #Callback
         | 
| 23 | 
            -
             | 
| 24 | 
            -
            end
         | 
    
        data/lib/blather/client.rb
    DELETED
    
    | @@ -1,81 +0,0 @@ | |
| 1 | 
            -
            require File.join(File.dirname(__FILE__), %w[.. blather])
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Blather
         | 
| 4 | 
            -
             | 
| 5 | 
            -
              class Client
         | 
| 6 | 
            -
                @@callbacks = {}
         | 
| 7 | 
            -
                @@status = nil
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                attr_accessor :jid,
         | 
| 10 | 
            -
                              :roster
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                def send_data(data)
         | 
| 13 | 
            -
                  @stream.send data
         | 
| 14 | 
            -
                end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                def status
         | 
| 17 | 
            -
                  @@status
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                def set_status(state = nil, msg = nil, to = nil)
         | 
| 21 | 
            -
                  status = Presence::Status.new state, msg
         | 
| 22 | 
            -
                  status.to = to
         | 
| 23 | 
            -
                  @@status = status unless to
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                  send_data status
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                def stream_started(stream)
         | 
| 29 | 
            -
                  @stream = stream
         | 
| 30 | 
            -
                  retreive_roster
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                def call(stanza)
         | 
| 34 | 
            -
                  stanza.callback_heirarchy.each { |type| break if callback(type, stanza) }
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                # Default response to an Iq 'get' or 'set' is 'service-unavailable'/'cancel'
         | 
| 38 | 
            -
                def receive_iq(iq)
         | 
| 39 | 
            -
                  send_data(ErrorStanza.new_from(iq, 'service-unavailable', 'cancel').reply!) if [:set, :get].include?(iq.type)
         | 
| 40 | 
            -
                end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                def receive_roster(node)
         | 
| 43 | 
            -
                  if !@roster && node.type == :result
         | 
| 44 | 
            -
                    self.roster = Roster.new(@stream, node)
         | 
| 45 | 
            -
                    register_callback(:status, -128) { |_, status| roster[status.from].status = status if roster[status.from]; false }
         | 
| 46 | 
            -
                    set_status
         | 
| 47 | 
            -
                  elsif node.type == :set
         | 
| 48 | 
            -
                    roster.process node
         | 
| 49 | 
            -
                  end
         | 
| 50 | 
            -
                end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                def self.register_callback(type, priority = 0, &callback)
         | 
| 53 | 
            -
                  @@callbacks[type] ||= []
         | 
| 54 | 
            -
                  @@callbacks[type] << Callback.new(priority, &callback)
         | 
| 55 | 
            -
                  @@callbacks[type].sort!
         | 
| 56 | 
            -
                end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                def register_callback(type, priority = 0, &callback)
         | 
| 59 | 
            -
                  self.class.register_callback(type, priority = 0, &callback)
         | 
| 60 | 
            -
                end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                def self.status(state = nil, msg = nil)
         | 
| 63 | 
            -
                  @@status = Presence::Status.new state, msg
         | 
| 64 | 
            -
                end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                def callback(type, stanza)
         | 
| 67 | 
            -
                  complete = false
         | 
| 68 | 
            -
                  (@@callbacks[type] || []).each { |callback| break if complete = callback.call(self, stanza) }
         | 
| 69 | 
            -
             | 
| 70 | 
            -
                  method = "receive_#{type}"
         | 
| 71 | 
            -
                  complete = __send__(method, stanza) if !complete && respond_to?(method)
         | 
| 72 | 
            -
                  complete
         | 
| 73 | 
            -
                end
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                def retreive_roster
         | 
| 76 | 
            -
                  send_data Iq::Roster.new
         | 
| 77 | 
            -
                end
         | 
| 78 | 
            -
             | 
| 79 | 
            -
              end #Client
         | 
| 80 | 
            -
             | 
| 81 | 
            -
            end
         | 
| @@ -1,42 +0,0 @@ | |
| 1 | 
            -
            module Blather
         | 
| 2 | 
            -
            class Stanza
         | 
| 3 | 
            -
            class Iq
         | 
| 4 | 
            -
             | 
| 5 | 
            -
              class Query < Iq
         | 
| 6 | 
            -
                register :query, :query
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                def self.new(type)
         | 
| 9 | 
            -
                  elem = super
         | 
| 10 | 
            -
                  elem.query.xmlns = self.xmlns
         | 
| 11 | 
            -
                  elem
         | 
| 12 | 
            -
                end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                def inherit(node)
         | 
| 15 | 
            -
                  query.remove!
         | 
| 16 | 
            -
                  @query = nil
         | 
| 17 | 
            -
                  super
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                def query
         | 
| 21 | 
            -
                  @query ||= if q = find_first('query')
         | 
| 22 | 
            -
                    q
         | 
| 23 | 
            -
                  else
         | 
| 24 | 
            -
                    self << q = XMPPNode.new('query')
         | 
| 25 | 
            -
                    q
         | 
| 26 | 
            -
                  end
         | 
| 27 | 
            -
                end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                def reply
         | 
| 30 | 
            -
                  elem = super
         | 
| 31 | 
            -
                  elem.type = :result
         | 
| 32 | 
            -
                end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                def reply!
         | 
| 35 | 
            -
                  self.type = :result
         | 
| 36 | 
            -
                  super
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
              end #Query
         | 
| 39 | 
            -
             | 
| 40 | 
            -
            end #Iq
         | 
| 41 | 
            -
            end #Stanza
         | 
| 42 | 
            -
            end
         | 
    
        data/lib/blather/extensions.rb
    DELETED
    
    
| @@ -1,55 +0,0 @@ | |
| 1 | 
            -
            module Blather
         | 
| 2 | 
            -
              module Extensions #:nodoc:
         | 
| 3 | 
            -
             | 
| 4 | 
            -
                module LastActivity #:nodoc:
         | 
| 5 | 
            -
                  def self.included(base)
         | 
| 6 | 
            -
                    base.class_eval do
         | 
| 7 | 
            -
                      @@last_activity = Time.now
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                      alias_method :send_data_without_activity, :send_data
         | 
| 10 | 
            -
                      def send_data(data)
         | 
| 11 | 
            -
                        @@last_activity = Time.now
         | 
| 12 | 
            -
                        send_data_without_activity data
         | 
| 13 | 
            -
                      end
         | 
| 14 | 
            -
                    end
         | 
| 15 | 
            -
                  end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  def last_activity
         | 
| 18 | 
            -
                    (Time.now - @@last_activity).to_i
         | 
| 19 | 
            -
                  end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                  def receive_last_activity(stanza)
         | 
| 22 | 
            -
                    send_data stanza.reply!(last_activity) if stanza.type == 'get'
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
                end #LastActivity
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                class LastActivityStanza < Query #:nodoc:
         | 
| 27 | 
            -
                  register :last_activity, nil, 'jabber:iq:last'
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                  def self.new(type = :get, seconds = nil)
         | 
| 30 | 
            -
                    elem = super type
         | 
| 31 | 
            -
                    elem.seconds = seconds
         | 
| 32 | 
            -
                    elem
         | 
| 33 | 
            -
                  end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  def seconds=(seconds)
         | 
| 36 | 
            -
                    query.attributes.remove :seconds
         | 
| 37 | 
            -
                    query['seconds'] = seconds.to_i.to_s if seconds
         | 
| 38 | 
            -
                  end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                  def seconds
         | 
| 41 | 
            -
                    (query['seconds'] || 0).to_i
         | 
| 42 | 
            -
                  end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                  def reply(seconds)
         | 
| 45 | 
            -
                    elem = super()
         | 
| 46 | 
            -
                    elem.last_activity = seconds
         | 
| 47 | 
            -
                  end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                  def reply!(seconds)
         | 
| 50 | 
            -
                    self.last_activity = seconds
         | 
| 51 | 
            -
                    super()
         | 
| 52 | 
            -
                  end
         | 
| 53 | 
            -
                end #LastActivityStanza
         | 
| 54 | 
            -
              end
         | 
| 55 | 
            -
            end
         | 
| @@ -1,85 +0,0 @@ | |
| 1 | 
            -
            module Blather
         | 
| 2 | 
            -
              module Extensions #:nodoc:
         | 
| 3 | 
            -
             | 
| 4 | 
            -
                module Version #:nodoc:
         | 
| 5 | 
            -
                  def self.included(base)
         | 
| 6 | 
            -
                    base.class_eval do
         | 
| 7 | 
            -
                      @@version = {}
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                      def self.version(name, ver, os = nil)
         | 
| 10 | 
            -
                        @@version = {:name => name, :version => ver, :os => os}
         | 
| 11 | 
            -
                      end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                      add_callback(:iq, 100) do |c, s|
         | 
| 14 | 
            -
                        if s.detect { |n| n['xmlns'] == 'jabber:iq:version' }
         | 
| 15 | 
            -
                          ver = VersionStanza.new('result', c.version)
         | 
| 16 | 
            -
                          ver.id = s.id
         | 
| 17 | 
            -
                          ver.from = c.jid
         | 
| 18 | 
            -
                          ver.to = s.from
         | 
| 19 | 
            -
                          c.send_data ver
         | 
| 20 | 
            -
                        end
         | 
| 21 | 
            -
                      end
         | 
| 22 | 
            -
                    end
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                  def version
         | 
| 26 | 
            -
                    @@version
         | 
| 27 | 
            -
                  end
         | 
| 28 | 
            -
                end #Version
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                class VersionStanza < Iq #:nodoc:
         | 
| 31 | 
            -
                  def self.new(type = 'result', ver = {})
         | 
| 32 | 
            -
                    elem = super(type)
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                    query = XML::Node.new('query')
         | 
| 35 | 
            -
                    query.xmlns = 'jabber:iq:version'
         | 
| 36 | 
            -
                    elem << query
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                    elem.name = ver[:name] if ver[:name]
         | 
| 39 | 
            -
                    elem.version = ver[:version] if ver[:version]
         | 
| 40 | 
            -
                    elem.os = ver[:os] if ver[:os]
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                    elem
         | 
| 43 | 
            -
                  end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                  def query
         | 
| 46 | 
            -
                    @query ||= self.detect { |n| n.name == 'query' }
         | 
| 47 | 
            -
                  end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                  def name=(name)
         | 
| 50 | 
            -
                    query.each { |n| n.remove! or break if n.name == 'name' }
         | 
| 51 | 
            -
                    query << XML::Node.new('name', name)
         | 
| 52 | 
            -
                  end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                  def name
         | 
| 55 | 
            -
                    if name = query.detect { |n| n.name == 'name' }
         | 
| 56 | 
            -
                      name.content
         | 
| 57 | 
            -
                    end
         | 
| 58 | 
            -
                  end
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                  def version=(version)
         | 
| 61 | 
            -
                    query.each { |n| n.remove! or break if n.name == 'version' }
         | 
| 62 | 
            -
                    query << XML::Node.new('version', version)
         | 
| 63 | 
            -
                  end
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                  def version
         | 
| 66 | 
            -
                    if version = query.detect { |n| n.version == 'version' }
         | 
| 67 | 
            -
                      version.content
         | 
| 68 | 
            -
                    end
         | 
| 69 | 
            -
                  end
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                  def os=(os)
         | 
| 72 | 
            -
                    query.each { |n| n.remove! or break if n.name == 'os' }
         | 
| 73 | 
            -
                    query << XML::Node.new('os', os)
         | 
| 74 | 
            -
                  end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                  def os
         | 
| 77 | 
            -
                    if os = query.detect { |n| n.os == 'os' }
         | 
| 78 | 
            -
                      os.content
         | 
| 79 | 
            -
                    end
         | 
| 80 | 
            -
                  end
         | 
| 81 | 
            -
                end #VersionStanza
         | 
| 82 | 
            -
              end
         | 
| 83 | 
            -
            end
         | 
| 84 | 
            -
             | 
| 85 | 
            -
            Blather::Client.__send__ :include, Blather::Extensions::Version
         |