jubjub 0.0.7 → 0.0.8

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.
Files changed (62) hide show
  1. data/README.mdown +27 -1
  2. data/lib/jubjub.rb +1 -1
  3. data/lib/jubjub/connection/xmpp_gateway.rb +9 -9
  4. data/lib/jubjub/connection/xmpp_gateway/helper.rb +5 -5
  5. data/lib/jubjub/connection/xmpp_gateway/muc.rb +127 -32
  6. data/lib/jubjub/connection/xmpp_gateway/pubsub.rb +64 -64
  7. data/lib/jubjub/data_form.rb +16 -13
  8. data/lib/jubjub/errors.rb +2 -2
  9. data/lib/jubjub/helpers.rb +32 -0
  10. data/lib/jubjub/jid.rb +8 -8
  11. data/lib/jubjub/muc.rb +3 -1
  12. data/lib/jubjub/muc/affiliation.rb +77 -0
  13. data/lib/jubjub/muc/affiliations_collection.rb +31 -0
  14. data/lib/jubjub/muc/collection.rb +12 -19
  15. data/lib/jubjub/muc/configuration.rb +2 -2
  16. data/lib/jubjub/muc/muc.rb +24 -11
  17. data/lib/jubjub/pubsub.rb +1 -1
  18. data/lib/jubjub/pubsub/affiliation.rb +20 -20
  19. data/lib/jubjub/pubsub/affiliation_collection.rb +11 -18
  20. data/lib/jubjub/pubsub/collection.rb +14 -21
  21. data/lib/jubjub/pubsub/configuration.rb +2 -2
  22. data/lib/jubjub/pubsub/item.rb +8 -8
  23. data/lib/jubjub/pubsub/item_collection.rb +10 -17
  24. data/lib/jubjub/pubsub/pubsub.rb +17 -17
  25. data/lib/jubjub/pubsub/subscription.rb +6 -6
  26. data/lib/jubjub/response.rb +1 -1
  27. data/lib/jubjub/response/error.rb +6 -6
  28. data/lib/jubjub/response/proxy.rb +8 -8
  29. data/lib/jubjub/response/response.rb +10 -10
  30. data/lib/jubjub/user.rb +16 -15
  31. data/spec/connection/xmpp_gateway_muc_spec.rb +174 -40
  32. data/spec/connection/xmpp_gateway_pubsub_spec.rb +100 -104
  33. data/spec/fixtures/vcr_cassettes/muc_configuration.yml +73 -6
  34. data/spec/fixtures/vcr_cassettes/muc_create_with_configuration.yml +8 -8
  35. data/spec/fixtures/vcr_cassettes/muc_message.yml +89 -0
  36. data/spec/fixtures/vcr_cassettes/muc_modify_affiliations.yml +367 -0
  37. data/spec/fixtures/vcr_cassettes/muc_retrieve_affiliations.yml +93 -0
  38. data/spec/fixtures/vcr_cassettes/pubsub_publish_with_dataform_payload.yml +3 -3
  39. data/spec/fixtures/vcr_cassettes/pubsub_retrieve_items.yml +24 -18
  40. data/spec/mixins/user_spec.rb +37 -37
  41. data/spec/models/data_form_spec.rb +3 -3
  42. data/spec/models/jid_spec.rb +41 -41
  43. data/spec/models/muc_affiliation_collection_spec.rb +146 -0
  44. data/spec/models/muc_affiliation_spec.rb +215 -0
  45. data/spec/models/muc_collection_spec.rb +64 -32
  46. data/spec/models/muc_configuration_spec.rb +3 -3
  47. data/spec/models/muc_spec.rb +44 -23
  48. data/spec/models/pubsub_affiliation_collection_spec.rb +65 -30
  49. data/spec/models/pubsub_affiliation_spec.rb +50 -50
  50. data/spec/models/pubsub_collection_spec.rb +65 -49
  51. data/spec/models/pubsub_item_collection_spec.rb +17 -17
  52. data/spec/models/pubsub_item_spec.rb +18 -18
  53. data/spec/models/pubsub_spec.rb +41 -41
  54. data/spec/models/pubsub_subscription_spec.rb +23 -23
  55. data/spec/models/response_error_spec.rb +19 -19
  56. data/spec/models/response_proxy_spec.rb +51 -49
  57. data/spec/models/response_spec.rb +33 -33
  58. data/spec/support/helpers.rb +21 -1
  59. data/spec/support/matchers.rb +4 -4
  60. data/spec/support/shared_examples.rb +132 -94
  61. data/spec/support/webmock_stanza_matching.rb +43 -0
  62. metadata +45 -16
@@ -1,7 +1,9 @@
1
1
  class Jubjub::Pubsub::AffiliationCollection
2
-
2
+
3
3
  attr_reader :jid, :node
4
-
4
+
5
+ include Jubjub::Helpers::Collection
6
+
5
7
  def initialize(jid,node,connection)
6
8
  @jid = Jubjub::Jid.new jid
7
9
  @node = node
@@ -11,28 +13,19 @@ class Jubjub::Pubsub::AffiliationCollection
11
13
  def [](jid_num)
12
14
  case jid_num
13
15
  when Fixnum
14
- affiliations[jid_num]
16
+ list[jid_num]
15
17
  when Jubjub::Jid
16
- affiliations.find{|i| i.jid == jid_num } || Jubjub::Pubsub::Affiliation.new( jid, node, jid_num, 'none', @connection )
18
+ search_list( Jubjub::Pubsub::Affiliation.new( jid, node, jid_num, 'none', @connection ) ){|i| i.jid == jid_num }
17
19
  else
18
20
  j = Jubjub::Jid.new( jid_num )
19
- affiliations.find{|i| i.jid == j } || Jubjub::Pubsub::Affiliation.new( jid, node, j, 'none', @connection )
21
+ search_list( Jubjub::Pubsub::Affiliation.new( jid, node, j, 'none', @connection ) ){|i| i.jid == j }
20
22
  end
21
23
  end
22
24
 
23
- # Hint that methods are actually applied to list using method_missing
24
- def inspect
25
- affiliations.inspect
26
- end
27
-
28
25
  private
29
26
 
30
- def method_missing(name, *args, &block)
31
- affiliations.send(name, *args, &block)
32
- end
33
-
34
- def affiliations
35
- @affiliations ||= @connection.pubsub.retrieve_affiliations( @jid, @node )
27
+ def list
28
+ @list ||= @connection.pubsub.retrieve_affiliations( @jid, @node )
36
29
  end
37
-
38
- end
30
+
31
+ end
@@ -2,18 +2,20 @@
2
2
  # and delaying expensive operations until
3
3
  # required
4
4
  class Jubjub::Pubsub::Collection
5
-
5
+
6
6
  attr_reader :jid
7
-
7
+
8
+ include Jubjub::Helpers::Collection
9
+
8
10
  def initialize(jid, connection)
9
11
  @jid = Jubjub::Jid.new jid
10
12
  @connection = connection
11
13
  end
12
-
14
+
13
15
  def create(node)
14
16
  @connection.pubsub.create jid, node
15
17
  end
16
-
18
+
17
19
  def create(node, &block)
18
20
  config = nil
19
21
  if block_given?
@@ -23,46 +25,37 @@ class Jubjub::Pubsub::Collection
23
25
  end
24
26
  @connection.pubsub.create jid, node, config
25
27
  end
26
-
28
+
27
29
  def destroy(node, redirect_jid = nil, redirect_node = nil)
28
30
  redirect_jid = Jubjub::Jid.new(redirect_jid) if redirect_jid
29
31
  @connection.pubsub.destroy jid, node, redirect_jid, redirect_node
30
32
  end
31
-
33
+
32
34
  def purge(node)
33
35
  @connection.pubsub.purge jid, node
34
36
  end
35
-
37
+
36
38
  def subscribe(node)
37
39
  @connection.pubsub.subscribe jid, node
38
40
  end
39
-
41
+
40
42
  def unsubscribe(node, subid=nil)
41
43
  @connection.pubsub.unsubscribe jid, node, subid
42
44
  end
43
-
45
+
44
46
  def [](node_num)
45
47
  case node_num
46
48
  when Fixnum
47
49
  list[node_num]
48
50
  else
49
- list.find{|p| p.node == node_num } || Jubjub::Pubsub.new( jid, node_num, @connection )
51
+ search_list(Jubjub::Pubsub.new( jid, node_num, @connection )){|p| p.node == node_num }
50
52
  end
51
53
  end
52
-
53
- # Hint that methods are actually applied to list using method_missing
54
- def inspect
55
- list.inspect
56
- end
57
54
 
58
55
  private
59
56
 
60
- def method_missing(name, *args, &block)
61
- list.send(name, *args, &block)
62
- end
63
-
64
57
  def list
65
58
  @list ||= @connection.pubsub.list jid
66
59
  end
67
-
68
- end
60
+
61
+ end
@@ -1,5 +1,5 @@
1
1
  require 'jubjub/data_form'
2
2
 
3
3
  class Jubjub::Pubsub::Configuration < Jubjub::DataForm
4
-
5
- end
4
+
5
+ end
@@ -1,7 +1,7 @@
1
1
  class Jubjub::Pubsub::Item
2
-
2
+
3
3
  attr_reader :jid, :node, :item_id, :data
4
-
4
+
5
5
  def initialize(jid, node, item_id, data, connection)
6
6
  @jid = Jubjub::Jid.new jid
7
7
  @node = node
@@ -9,17 +9,17 @@ class Jubjub::Pubsub::Item
9
9
  @data = data
10
10
  @connection = connection
11
11
  end
12
-
12
+
13
13
  # Hide the connection details and show jid as string for compactness
14
14
  def inspect
15
15
  obj_id = "%x" % (object_id << 1)
16
16
  "#<#{self.class}:0x#{obj_id} @jid=\"#{jid}\" @node=#{node.inspect} @item_id=#{item_id.inspect} @data=#{data.inspect}>"
17
17
  end
18
-
18
+
19
19
  def retract
20
20
  @connection.pubsub.retract jid, node, item_id
21
21
  end
22
-
22
+
23
23
  def ==(other)
24
24
  other.is_a?( self.class ) &&
25
25
  other.jid == self.jid &&
@@ -27,9 +27,9 @@ class Jubjub::Pubsub::Item
27
27
  other.item_id == self.item_id &&
28
28
  other.data == self.data
29
29
  end
30
-
30
+
31
31
  def uri
32
32
  "xmpp:#{@jid}?;node=#{@node};item=#{@item_id}"
33
33
  end
34
-
35
- end
34
+
35
+ end
@@ -1,7 +1,9 @@
1
1
  class Jubjub::Pubsub::ItemCollection
2
-
2
+
3
3
  attr_reader :jid, :node
4
-
4
+
5
+ include Jubjub::Helpers::Collection
6
+
5
7
  def initialize(jid,node,connection)
6
8
  @jid = Jubjub::Jid.new jid
7
9
  @node = node
@@ -11,25 +13,16 @@ class Jubjub::Pubsub::ItemCollection
11
13
  def [](item_num)
12
14
  case item_num
13
15
  when Fixnum
14
- items[item_num]
16
+ list[item_num]
15
17
  else
16
- items.find{|i| i.item_id == item_num }
18
+ search_list{|i| i.item_id == item_num }
17
19
  end
18
20
  end
19
21
 
20
- # Hint that methods are actually applied to list using method_missing
21
- def inspect
22
- items.inspect
23
- end
24
-
25
22
  private
26
23
 
27
- def method_missing(name, *args, &block)
28
- items.send(name, *args, &block)
29
- end
30
-
31
- def items
32
- @items ||= @connection.pubsub.retrieve_items( @jid, @node )
24
+ def list
25
+ @list ||= @connection.pubsub.retrieve_items( @jid, @node )
33
26
  end
34
-
35
- end
27
+
28
+ end
@@ -1,66 +1,66 @@
1
1
  class Jubjub::Pubsub
2
-
2
+
3
3
  attr_reader :jid, :node
4
-
4
+
5
5
  def initialize(jid, node, connection)
6
6
  @jid = Jubjub::Jid.new jid
7
7
  @node = node
8
8
  @connection = connection
9
9
  end
10
-
10
+
11
11
  def destroy(redirect_jid = nil, redirect_node = nil)
12
12
  redirect_jid = Jubjub::Jid.new(redirect_jid) if redirect_jid
13
13
  @connection.pubsub.destroy jid, node, redirect_jid, redirect_node
14
14
  end
15
-
15
+
16
16
  def purge
17
17
  @connection.pubsub.purge jid, node
18
18
  end
19
-
19
+
20
20
  def subscribe
21
21
  @connection.pubsub.subscribe jid, node
22
22
  end
23
-
23
+
24
24
  def unsubscribe(subid = nil)
25
- @connection.pubsub.unsubscribe jid, node, subid
25
+ @connection.pubsub.unsubscribe jid, node, subid
26
26
  end
27
-
27
+
28
28
  def publish(data, item_id = nil)
29
29
  @connection.pubsub.publish jid, node, data, item_id
30
30
  end
31
-
31
+
32
32
  def retract(item_id)
33
33
  @connection.pubsub.retract jid, node, item_id
34
34
  end
35
-
35
+
36
36
  # Hide the connection details and show jid as string for compactness
37
37
  def inspect
38
38
  obj_id = "%x" % (object_id << 1)
39
39
  "#<#{self.class}:0x#{obj_id} @jid=\"#{jid}\" @node=#{node.inspect}>"
40
40
  end
41
-
41
+
42
42
  def items
43
43
  ItemCollection.new jid, node, @connection
44
44
  end
45
-
45
+
46
46
  def affiliations
47
47
  AffiliationCollection.new jid, node, @connection
48
48
  end
49
-
49
+
50
50
  def uri
51
51
  "xmpp:#{@jid}?;node=#{@node}"
52
52
  end
53
-
53
+
54
54
  def ==(other)
55
55
  other.is_a?( self.class ) &&
56
56
  other.jid == self.jid &&
57
57
  other.node == self.node
58
58
  end
59
-
59
+
60
60
  private
61
61
 
62
62
  def method_missing(name, *args, &block)
63
63
  items.send(name, *args, &block)
64
64
  end
65
-
66
- end
65
+
66
+ end
@@ -1,7 +1,7 @@
1
1
  class Jubjub::Pubsub::Subscription
2
-
2
+
3
3
  attr_reader :jid, :node, :subscriber, :subid, :subscription
4
-
4
+
5
5
  def initialize(jid, node, subscriber, subid, subscription, connection)
6
6
  @jid = Jubjub::Jid.new jid
7
7
  @node = node
@@ -10,15 +10,15 @@ class Jubjub::Pubsub::Subscription
10
10
  @subscription = subscription
11
11
  @connection = connection
12
12
  end
13
-
13
+
14
14
  def unsubscribe
15
15
  @connection.pubsub.unsubscribe jid, node, subid
16
16
  end
17
-
17
+
18
18
  # Hide the connection details and show jid as string for compactness
19
19
  def inspect
20
20
  obj_id = "%x" % (object_id << 1)
21
21
  "#<#{self.class}:0x#{obj_id} @jid=\"#{jid}\" @node=#{node.inspect} @subscriber=\"#{subscriber}\" @subid=#{subid.inspect} @subscription=#{subscription.inspect}>"
22
22
  end
23
-
24
- end
23
+
24
+ end
@@ -1,3 +1,3 @@
1
1
  require "jubjub/response/response"
2
2
  require "jubjub/response/proxy"
3
- require "jubjub/response/error"
3
+ require "jubjub/response/error"
@@ -7,19 +7,19 @@ module Jubjub
7
7
  def initialize(xml)
8
8
  @stanza = xml
9
9
  end
10
-
10
+
11
11
  def condition
12
12
  @condition ||= begin
13
13
  condition = @stanza.xpath('//error/ietf:*','ietf' => 'urn:ietf:params:xml:ns:xmpp-stanzas').first
14
14
  condition.name if condition
15
15
  end
16
16
  end
17
-
17
+
18
18
  def type
19
19
  @error_type ||= stanza.xpath('//error').first.attr('type')
20
20
  end
21
-
22
- def text(language=nil)
21
+
22
+ def text(language=nil)
23
23
  if language
24
24
  xpath = "//error/text[@xml:lang='#{language}']"
25
25
  else
@@ -27,7 +27,7 @@ module Jubjub
27
27
  end
28
28
  stanza.xpath(xpath).text
29
29
  end
30
-
30
+
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -6,39 +6,39 @@ module Jubjub
6
6
  instance_methods.each do |m|
7
7
  undef_method(m) if m.to_s !~ /(?:^__|^nil?$|^send$|^object_id$|^should$)/
8
8
  end
9
-
9
+
10
10
  attr_reader :proxy_primary, :proxy_secondary
11
-
11
+
12
12
  def initialize(primary, secondary, primary_method)
13
13
  @proxy_primary = primary
14
14
  @proxy_secondary = secondary
15
15
  @primary_method = primary_method
16
16
  end
17
-
17
+
18
18
  # We really want to show the secondary object
19
19
  # as the primary is just a thin layer on top
20
20
  def inspect
21
21
  proxy_secondary.inspect
22
22
  end
23
-
23
+
24
24
  # Used to give away this is really a proxy
25
25
  def proxy_class
26
26
  Jubjub::Response::Proxy
27
27
  end
28
-
28
+
29
29
  private
30
30
 
31
31
  def method_missing(name, *args, &block)
32
32
  # If the method exists on the primary use that
33
33
  # unless it's the method name called to create the proxy from the primary, or is a standard object method
34
- if name.to_s != @primary_method && (proxy_primary.public_methods - Object.public_methods).include?( name.to_s )
34
+ if name.to_s != @primary_method && (proxy_primary.public_methods - Object.public_methods).map{|m| m.to_s }.include?( name.to_s )
35
35
  proxy_primary.send(name, *args, &block)
36
36
  else
37
37
  # Else use a method on the secondary
38
38
  proxy_secondary.send(name, *args, &block)
39
39
  end
40
40
  end
41
-
41
+
42
42
  end
43
43
  end
44
- end
44
+ end
@@ -1,33 +1,33 @@
1
1
  module Jubjub
2
-
2
+
3
3
  class Response
4
-
4
+
5
5
  attr_reader :stanza, :result
6
-
6
+
7
7
  def initialize(xml,&block)
8
8
  @stanza = xml
9
-
9
+
10
10
  @result = nil
11
11
  @result = yield stanza if block_given?
12
12
  end
13
-
13
+
14
14
  def proxy_result
15
- # Allows some syntax sugar. We can chain from the result,
15
+ # Allows some syntax sugar. We can chain from the result,
16
16
  # but still get access to the response via the proxy
17
17
  @proxy_result ||= Proxy.new self, result, 'proxy_result'
18
18
  end
19
-
19
+
20
20
  def success?
21
21
  @success ||= stanza.xpath('/iq[@type="result"]|/iq[@type="set"]|/iq[@type="get"]').any?
22
22
  end
23
-
23
+
24
24
  def error
25
25
  @errors ||= begin
26
26
  s = stanza.at_xpath('/iq[@type="error"]/error')
27
27
  Error.new s if s
28
28
  end
29
29
  end
30
-
30
+
31
31
  end
32
-
32
+
33
33
  end