ejabberd_rest 0.0.7 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f22342235d28be96f2441fe4c11ff7dd7427df8
4
- data.tar.gz: 7b9003e28fd1ddf2fd8e8e9d7c9c4eee7a27fc1c
3
+ metadata.gz: aaa8f83b362e37b545605e3abf23e257a13d83cd
4
+ data.tar.gz: 5a3623912ff667d0cd5465d463c6122701f90ead
5
5
  SHA512:
6
- metadata.gz: bd3b3b0d43d089d87e4bc9a825e7a53579f28a84b865eb6c6a83b2a1c4aec43048be2f1148825d5911126084ba472e22ee0d564f9b82045b805ffc975dc4be34
7
- data.tar.gz: f9818927d4920a027c00f81baffa56a1ff449e6580025be09a7f4e0549111f25e95b7ea24dae394f34b3a49e1e1ebc009a987f71a123325cd07198141ed4dbc1
6
+ metadata.gz: 94caf9ff9aad1795a21f2f30b8afcd6fe7ae76e92daa8c9773d732443c5507a0011968ad7f272ab8e6adbcee2de28bfdb80536aaad8dfc08400b940eeb607708
7
+ data.tar.gz: 344218f93bf66801077ecd8cc6483b92fc6de993bfc150b26dda5ad34968214675146a74a614156255deb1ff64c9bfc119934cdd5f83497beb0d928f172d350a
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "pry"
24
24
 
25
25
  spec.add_runtime_dependency "faraday", "~> 0.9.0"
26
+ spec.add_runtime_dependency "typhoeus", "~> 0.6.8"
26
27
  end
data/lib/ejabberd_rest.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require "ejabberd_rest/version"
2
2
  require "ejabberd_rest/client"
3
- require "faraday"
3
+ require "faraday"
4
+ require "typhoeus/adapters/faraday"
@@ -3,14 +3,21 @@ require "securerandom"
3
3
 
4
4
  module EjabberdRest
5
5
  class Client
6
- attr_accessor :debug, :http_adapter, :mod_rest_url
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
- @mod_rest_url = attributes[:url] || DEFAULT_MOD_REST_URL
12
- @http_adapter = attributes[:http_adapter] || :net_http
13
- @debug = attributes[:debug] || false
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 pubsub_publish(from_jid, host, node, message)
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
- post_stanza(stanza)
86
+ stanza
72
87
  end
73
88
 
74
- def pubsub_subscribe(jid, host, node, resource)
75
- stanza = "<iq type='set' from='#{jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
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
- post_stanza(stanza)
108
+ stanza
82
109
  end
83
110
 
84
- def pubsub_unsubscribe(jid, host, node, resource)
85
- stanza = "<iq type='set' from='#{jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
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
- post_stanza(stanza)
130
+ stanza
92
131
  end
93
132
 
94
- private
95
-
96
- def connection
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
- builder.adapter @http_adapter
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
- # Check if status code success
111
- if response.status / 100 == 2
112
- response.body
113
- else
114
- raise Exception, "HTTP status code: #{response.status} == Body: #{response.body}"
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
@@ -1,3 +1,3 @@
1
1
  module EjabberdRest
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  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.7
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-08 00:00:00.000000000 Z
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