Sha256: 06f74e9e188a3d4ad50dcea897be9901ee47ce5d0e2873fc28c02d12f1ffbc00

Contents?: true

Size: 1.13 KB

Versions: 14

Compression:

Stored size: 1.13 KB

Contents

module Blather
class Stanza
class Presence

  class Subscription < Presence
    register :subscription, :subscription

    def initialize(to = nil, type = nil)
      super()
      self.to = to
      self.type = type
    end

    def inherit(node)
      inherit_attrs node.attributes
      self
    end

    def to=(to)
      super JID.new(to).stripped
    end

    ##
    # Create an approve stanza
    def approve!
      self.type = :subscribed
      morph_to_reply
    end

    ##
    # Create a refuse stanza
    def refuse!
      self.type = :unsubscribed
      morph_to_reply
    end

    ##
    # Create an unsubscribe stanza
    def unsubscribe!
      self.type = :unsubscribe
      morph_to_reply
    end

    ##
    # Create a cancel stanza
    def cancel!
      self.type = :unsubscribed
      morph_to_reply
    end

    ##
    # Create a request stanza
    def request!
      self.type = :subscribe
      morph_to_reply
    end

    def request?
      self.type == :subscribe
    end

  private
    def morph_to_reply
      self.to = self.from if self.from
      self.from = nil
      self
    end
  end #Subscription

end #Presence
end #Stanza
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
sprsquish-blather-0.2.3 lib/blather/stanza/presence/subscription.rb
sprsquish-blather-0.3.0 lib/blather/stanza/presence/subscription.rb
sprsquish-blather-0.3.1 lib/blather/stanza/presence/subscription.rb
sprsquish-blather-0.3.2 lib/blather/stanza/presence/subscription.rb
sprsquish-blather-0.3.3 lib/blather/stanza/presence/subscription.rb
sprsquish-blather-0.3.4 lib/blather/stanza/presence/subscription.rb
blather-0.2.1 lib/blather/stanza/presence/subscription.rb
blather-0.2.2 lib/blather/stanza/presence/subscription.rb
blather-0.3.1 lib/blather/stanza/presence/subscription.rb
blather-0.3.0 lib/blather/stanza/presence/subscription.rb
blather-0.2.3 lib/blather/stanza/presence/subscription.rb
blather-0.3.4 lib/blather/stanza/presence/subscription.rb
blather-0.3.3 lib/blather/stanza/presence/subscription.rb
blather-0.3.2 lib/blather/stanza/presence/subscription.rb