ejabberd_rest 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ejabberd_rest.gemspec +1 -0
- data/lib/ejabberd_rest.rb +2 -1
- data/lib/ejabberd_rest/client.rb +68 -28
- data/lib/ejabberd_rest/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaa8f83b362e37b545605e3abf23e257a13d83cd
|
4
|
+
data.tar.gz: 5a3623912ff667d0cd5465d463c6122701f90ead
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94caf9ff9aad1795a21f2f30b8afcd6fe7ae76e92daa8c9773d732443c5507a0011968ad7f272ab8e6adbcee2de28bfdb80536aaad8dfc08400b940eeb607708
|
7
|
+
data.tar.gz: 344218f93bf66801077ecd8cc6483b92fc6de993bfc150b26dda5ad34968214675146a74a614156255deb1ff64c9bfc119934cdd5f83497beb0d928f172d350a
|
data/ejabberd_rest.gemspec
CHANGED
data/lib/ejabberd_rest.rb
CHANGED
data/lib/ejabberd_rest/client.rb
CHANGED
@@ -3,14 +3,21 @@ require "securerandom"
|
|
3
3
|
|
4
4
|
module EjabberdRest
|
5
5
|
class Client
|
6
|
-
attr_accessor :debug, :
|
6
|
+
attr_accessor :debug, :max_concurrency, :mod_rest_url
|
7
7
|
|
8
8
|
DEFAULT_MOD_REST_URL = "http://localhost:5285"
|
9
9
|
|
10
10
|
def initialize(attributes={})
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
mod_rest_url = attributes[:url] || DEFAULT_MOD_REST_URL
|
12
|
+
debug = attributes[:debug] || false
|
13
|
+
max_concurrency = attributes[:max_concurrency] || 100
|
14
|
+
|
15
|
+
manager = Typhoeus::Hydra.new(max_concurrency: 100)
|
16
|
+
@connection = Faraday.new(mod_rest_url, parallel_manager: manager) do |builder|
|
17
|
+
builder.request :url_encoded
|
18
|
+
builder.response :logger if debug
|
19
|
+
builder.adapter :typhoeus
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
23
|
def add_user(username, domain, password)
|
@@ -35,6 +42,14 @@ module EjabberdRest
|
|
35
42
|
post("/rest", body: stanza)
|
36
43
|
end
|
37
44
|
|
45
|
+
def post_all_stanzas(stanzas)
|
46
|
+
@connection.in_parallel do
|
47
|
+
stanzas.each do |stanza|
|
48
|
+
post_stanza(stanza)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
def modify_affiliations(from_jid, host, node, affiliations = {})
|
39
54
|
stanza = "<iq type='set' from='#{from_jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
|
40
55
|
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>"
|
@@ -57,7 +72,7 @@ module EjabberdRest
|
|
57
72
|
stanza << "</iq>"
|
58
73
|
end
|
59
74
|
|
60
|
-
def
|
75
|
+
def pubsub_item_stanza(from_jid, host, node, message)
|
61
76
|
stanza = "<iq type='set' from='#{from_jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
|
62
77
|
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
|
63
78
|
stanza << "<publish node='#{node}'>"
|
@@ -68,51 +83,76 @@ module EjabberdRest
|
|
68
83
|
stanza << "</pubsub>"
|
69
84
|
stanza << "</iq>"
|
70
85
|
|
71
|
-
|
86
|
+
stanza
|
72
87
|
end
|
73
88
|
|
74
|
-
def
|
75
|
-
|
89
|
+
def pubsub_publish(from_jid, host, node, message)
|
90
|
+
post_stanza(pubsub_item_stanza(from_jid, host, node, message))
|
91
|
+
end
|
92
|
+
|
93
|
+
def pubsub_publish_all_items(from_jid, host, node, items)
|
94
|
+
@connection.in_parallel do
|
95
|
+
items.each do |item|
|
96
|
+
pubsub_publish(from_jid, host, node, item)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def subscribe_stanza(jid, pubsub_service, node, resource)
|
102
|
+
stanza = "<iq type='set' from='#{jid}' to='#{pubsub_service}' id='#{SecureRandom.uuid}'>"
|
76
103
|
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
|
77
104
|
stanza << "<subscribe node='#{node}' jid='#{jid}/#{resource}' />"
|
78
105
|
stanza << "</pubsub>"
|
79
106
|
stanza << "</iq>"
|
80
107
|
|
81
|
-
|
108
|
+
stanza
|
82
109
|
end
|
83
110
|
|
84
|
-
def
|
85
|
-
|
111
|
+
def pubsub_subscribe(jid, pubsub_service, node, resource)
|
112
|
+
post_stanza(subscribe_stanza(jid, pubsub_service, node, resource))
|
113
|
+
end
|
114
|
+
|
115
|
+
def pubsub_subscribe_all_resources(jid, pubsub_service, node, resources)
|
116
|
+
@connection.in_parallel do
|
117
|
+
resources.each do |r|
|
118
|
+
pubsub_subscribe(jid, pubsub_service, node, r)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def unsubscribe_stanza(jid, pubsub_service, node, resource)
|
124
|
+
stanza = "<iq type='set' from='#{jid}' to='#{pubsub_service}' id='#{SecureRandom.uuid}'>"
|
86
125
|
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
|
87
126
|
stanza << "<unsubscribe node='#{node}' jid='#{jid}/#{resource}' />"
|
88
127
|
stanza << "</pubsub>"
|
89
128
|
stanza << "</iq>"
|
90
129
|
|
91
|
-
|
130
|
+
stanza
|
92
131
|
end
|
93
132
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
connection = Faraday.new(@mod_rest_url) do |builder|
|
98
|
-
builder.request :url_encoded
|
99
|
-
builder.response :logger if @debug
|
133
|
+
def pubsub_unsubscribe(jid, pubsub_service, node, resource)
|
134
|
+
post_stanza(unsubscribe_stanza(jid, pubsub_service, node, resource))
|
135
|
+
end
|
100
136
|
|
101
|
-
|
137
|
+
def pubsub_unsubscribe_all_resources(jid, pubsub_service, node, resources)
|
138
|
+
@connection.in_parallel do
|
139
|
+
resources.each do |r|
|
140
|
+
pubsub_unsubscribe(jid, pubsub_service, node, r)
|
141
|
+
end
|
102
142
|
end
|
103
143
|
end
|
104
144
|
|
105
|
-
def post(path, options)
|
106
|
-
response = connection.send(:post, path) do |request|
|
107
|
-
request.body = options[:body] if options[:body]
|
108
|
-
end
|
109
145
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
def post(path, options={})
|
150
|
+
@connection.post do |req|
|
151
|
+
req.url path
|
152
|
+
req.options[:timeout] = 60
|
153
|
+
req.body = options[:body] if options[:body]
|
115
154
|
end
|
116
155
|
end
|
156
|
+
|
117
157
|
end
|
118
158
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ejabberd_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fajar Budiprasetyo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.9.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: typhoeus
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.8
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.8
|
69
83
|
description: Ruby interface to add and delete user using ejabberd mod_rest.
|
70
84
|
email:
|
71
85
|
- fajar.ab@gmail.com
|