mojodna-xmpp4r 0.4.0.2 → 0.4.0.3

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.
@@ -10,9 +10,9 @@ module Jabber
10
10
  def get_subscriptions_from_all_nodes(oauth_consumer, oauth_token)
11
11
  iq = basic_pubsub_query(:get)
12
12
 
13
+ entities = iq.pubsub.add(REXML::Element.new('subscriptions'))
13
14
  iq.pubsub.add(create_oauth_node(oauth_consumer, oauth_token))
14
15
 
15
- entities = iq.pubsub.add(REXML::Element.new('subscriptions'))
16
16
  res = nil
17
17
  @stream.send_with_id(iq) { |reply|
18
18
  if reply.pubsub.first_element('subscriptions')
@@ -33,9 +33,9 @@ module Jabber
33
33
  sub.attributes['node'] = node
34
34
  sub.attributes['jid'] = @stream.jid.strip.to_s
35
35
 
36
- sub.add(create_oauth_node(oauth_consumer, oauth_token))
37
-
38
36
  iq.pubsub.add(sub)
37
+ iq.pubsub.add(create_oauth_node(oauth_consumer, oauth_token))
38
+
39
39
  res = nil
40
40
  @stream.send_with_id(iq) do |reply|
41
41
  pubsubanswer = reply.pubsub
@@ -47,15 +47,15 @@ module Jabber
47
47
  end
48
48
 
49
49
  # override #unsubscribe_from to add an oauth element
50
- def unsubscribe_from(node, oauth_consumer, oauth_token, subid=nil)
50
+ def unsubscribe_from(node, oauth_consumer, oauth_token, subid = nil)
51
51
  iq = basic_pubsub_query(:set)
52
52
  unsub = PubSub::Unsubscribe.new
53
53
  unsub.node = node
54
54
  unsub.jid = @stream.jid.strip
55
55
 
56
- unsub.add(create_oauth_node(oauth_consumer, oauth_token))
57
-
58
56
  iq.pubsub.add(unsub)
57
+ iq.pubsub.add(create_oauth_node(oauth_consumer, oauth_token))
58
+
59
59
  ret = false
60
60
  @stream.send_with_id(iq) { |reply|
61
61
  ret = reply.kind_of?(Jabber::Iq) and reply.type == :result
@@ -65,8 +65,13 @@ module Jabber
65
65
 
66
66
  protected
67
67
 
68
- # add the OAuth sauce (XEP-235)
69
- def create_oauth_node(oauth_consumer, oauth_token)
68
+ # add the OAuth sauce (XEP-0235)
69
+ # The `options` hash may contain the following parameters:
70
+ # :oauth_nonce => nonce (one will be generated otherwise)
71
+ # :oauth_timestamp => timestamp (one will be generated otherwise)
72
+ # :oauth_signature_method => signature method (defaults to HMAC-SHA1)
73
+ # :oauth_version => OAuth version (defaults to "1.0")
74
+ def create_oauth_node(oauth_consumer, oauth_token, options = {})
70
75
  require 'oauth/signature/hmac/sha1'
71
76
  require 'cgi'
72
77
 
@@ -75,31 +80,47 @@ module Jabber
75
80
  "uri" => [@stream.jid.strip.to_s, @pubsubjid.strip.to_s] * "&",
76
81
  "parameters" => {
77
82
  "oauth_consumer_key" => oauth_consumer.key,
83
+ "oauth_nonce" => options[:oauth_nonce] || OAuth::Helper.generate_nonce,
84
+ "oauth_timestamp" => options[:oauth_timestamp] || OAuth::Helper.generate_timestamp,
78
85
  "oauth_token" => oauth_token.token,
79
- "oauth_signature_method" => "HMAC-SHA1"
86
+ "oauth_signature_method" => options[:oauth_signature_method] || "HMAC-SHA1",
87
+ "oauth_version" => options[:oauth_version] || "1.0"
80
88
  }
81
89
 
82
- signature = OAuth::Signature.sign(request, :consumer => oauth_consumer, :token => oauth_token)
90
+ request.sign!(:consumer => oauth_consumer, :token => oauth_token)
83
91
 
92
+ # TODO create XMPPElements for OAuth elements
84
93
  oauth = REXML::Element.new("oauth")
85
- oauth.attributes['xmlns'] = 'urn:xmpp:oauth'
94
+ oauth.attributes['xmlns'] = 'urn:xmpp:tmp:oauth'
86
95
 
87
96
  oauth_consumer_key = REXML::Element.new("oauth_consumer_key")
88
- oauth_consumer_key.text = oauth_consumer.key
97
+ oauth_consumer_key.text = request.oauth_consumer_key
89
98
  oauth.add(oauth_consumer_key)
90
99
 
91
100
  oauth_token_node = REXML::Element.new("oauth_token")
92
- oauth_token_node.text = oauth_token.token
101
+ oauth_token_node.text = request.oauth_token
93
102
  oauth.add(oauth_token_node)
94
103
 
95
104
  oauth_signature_method = REXML::Element.new("oauth_signature_method")
96
- oauth_signature_method.text = "HMAC-SHA1"
105
+ oauth_signature_method.text = request.oauth_signature_method
97
106
  oauth.add(oauth_signature_method)
98
107
 
99
108
  oauth_signature = REXML::Element.new("oauth_signature")
100
- oauth_signature.text = signature
109
+ oauth_signature.text = request.oauth_signature
101
110
  oauth.add(oauth_signature)
102
111
 
112
+ oauth_timestamp = REXML::Element.new("oauth_timestamp")
113
+ oauth_timestamp.text = request.oauth_timestamp
114
+ oauth.add(oauth_timestamp)
115
+
116
+ oauth_nonce = REXML::Element.new("oauth_nonce")
117
+ oauth_nonce.text = request.oauth_nonce
118
+ oauth.add(oauth_nonce)
119
+
120
+ oauth_version = REXML::Element.new("oauth_version")
121
+ oauth_version.text = request.oauth_version
122
+ oauth.add(oauth_version)
123
+
103
124
  oauth
104
125
  end
105
126
  end
data/lib/xmpp4r/xmpp4r.rb CHANGED
@@ -8,7 +8,7 @@ module Jabber
8
8
  # XMPP4R Version number. This is the ONLY place where the version number
9
9
  # should be specified. This constant is used to determine the version of
10
10
  # package tarballs and generated gems.
11
- XMPP4R_VERSION = '0.4.0.2'
11
+ XMPP4R_VERSION = '0.4.0.3'
12
12
  end
13
13
 
14
14
  require 'xmpp4r/client'
data/xmpp4r.gemspec CHANGED
@@ -300,5 +300,5 @@ Gem::Specification.new do |s|
300
300
  s.rubygems_version = "1.3.1"
301
301
  s.specification_version = 2
302
302
  s.summary = "XMPP4R is an XMPP/Jabber library for Ruby."
303
- s.version = "0.4.0.2"
303
+ s.version = "0.4.0.3"
304
304
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojodna-xmpp4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.2
4
+ version: 0.4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Nussbaum
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2008-10-27 00:00:00 -07:00
14
+ date: 2009-02-03 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies: []
17
17