ejabberd_rest 0.0.1 → 0.0.7
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 +4 -4
- data/.gitignore +1 -0
- data/ejabberd_rest.gemspec +1 -0
- data/lib/ejabberd_rest/client.rb +70 -3
- 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: 5f22342235d28be96f2441fe4c11ff7dd7427df8
|
4
|
+
data.tar.gz: 7b9003e28fd1ddf2fd8e8e9d7c9c4eee7a27fc1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd3b3b0d43d089d87e4bc9a825e7a53579f28a84b865eb6c6a83b2a1c4aec43048be2f1148825d5911126084ba472e22ee0d564f9b82045b805ffc975dc4be34
|
7
|
+
data.tar.gz: f9818927d4920a027c00f81baffa56a1ff449e6580025be09a7f4e0549111f25e95b7ea24dae394f34b3a49e1e1ebc009a987f71a123325cd07198141ed4dbc1
|
data/.gitignore
CHANGED
data/ejabberd_rest.gemspec
CHANGED
data/lib/ejabberd_rest/client.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require "ejabberd_rest/errors"
|
2
|
+
require "securerandom"
|
2
3
|
|
3
4
|
module EjabberdRest
|
4
5
|
class Client
|
5
|
-
attr_accessor :http_adapter, :mod_rest_url
|
6
|
+
attr_accessor :debug, :http_adapter, :mod_rest_url
|
6
7
|
|
7
8
|
DEFAULT_MOD_REST_URL = "http://localhost:5285"
|
8
9
|
|
9
10
|
def initialize(attributes={})
|
10
11
|
@mod_rest_url = attributes[:url] || DEFAULT_MOD_REST_URL
|
11
12
|
@http_adapter = attributes[:http_adapter] || :net_http
|
13
|
+
@debug = attributes[:debug] || false
|
12
14
|
end
|
13
15
|
|
14
16
|
def add_user(username, domain, password)
|
@@ -29,12 +31,72 @@ module EjabberdRest
|
|
29
31
|
post("/rest", body: "unregister #{username} #{domain}")
|
30
32
|
end
|
31
33
|
|
34
|
+
def post_stanza(stanza)
|
35
|
+
post("/rest", body: stanza)
|
36
|
+
end
|
37
|
+
|
38
|
+
def modify_affiliations(from_jid, host, node, affiliations = {})
|
39
|
+
stanza = "<iq type='set' from='#{from_jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
|
40
|
+
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>"
|
41
|
+
stanza << "<affiliations node='#{node}'>"
|
42
|
+
affiliations.each do |k,v|
|
43
|
+
stanza << "<affiliation jid='#{k}' affiliation='#{v}' />"
|
44
|
+
end
|
45
|
+
stanza << "</affiliations>"
|
46
|
+
stanza << "</pubsub>"
|
47
|
+
stanza << "</iq>"
|
48
|
+
|
49
|
+
post_stanza(stanza)
|
50
|
+
end
|
51
|
+
|
52
|
+
def pubsub_delete_node(from_jid, host, node)
|
53
|
+
stanza = "<iq type='set' from='#{from_jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
|
54
|
+
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>"
|
55
|
+
stanza << "<delete node='#{node}'/>"
|
56
|
+
stanza << "</pubsub>"
|
57
|
+
stanza << "</iq>"
|
58
|
+
end
|
59
|
+
|
60
|
+
def pubsub_publish(from_jid, host, node, message)
|
61
|
+
stanza = "<iq type='set' from='#{from_jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
|
62
|
+
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
|
63
|
+
stanza << "<publish node='#{node}'>"
|
64
|
+
stanza << "<item id='#{SecureRandom.uuid}'>"
|
65
|
+
stanza << "#{message}"
|
66
|
+
stanza << "</item>"
|
67
|
+
stanza << "</publish>"
|
68
|
+
stanza << "</pubsub>"
|
69
|
+
stanza << "</iq>"
|
70
|
+
|
71
|
+
post_stanza(stanza)
|
72
|
+
end
|
73
|
+
|
74
|
+
def pubsub_subscribe(jid, host, node, resource)
|
75
|
+
stanza = "<iq type='set' from='#{jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
|
76
|
+
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
|
77
|
+
stanza << "<subscribe node='#{node}' jid='#{jid}/#{resource}' />"
|
78
|
+
stanza << "</pubsub>"
|
79
|
+
stanza << "</iq>"
|
80
|
+
|
81
|
+
post_stanza(stanza)
|
82
|
+
end
|
83
|
+
|
84
|
+
def pubsub_unsubscribe(jid, host, node, resource)
|
85
|
+
stanza = "<iq type='set' from='#{jid}' to='#{host}' id='#{SecureRandom.uuid}'>"
|
86
|
+
stanza << "<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
|
87
|
+
stanza << "<unsubscribe node='#{node}' jid='#{jid}/#{resource}' />"
|
88
|
+
stanza << "</pubsub>"
|
89
|
+
stanza << "</iq>"
|
90
|
+
|
91
|
+
post_stanza(stanza)
|
92
|
+
end
|
93
|
+
|
32
94
|
private
|
33
95
|
|
34
96
|
def connection
|
35
97
|
connection = Faraday.new(@mod_rest_url) do |builder|
|
36
98
|
builder.request :url_encoded
|
37
|
-
builder.response :logger
|
99
|
+
builder.response :logger if @debug
|
38
100
|
|
39
101
|
builder.adapter @http_adapter
|
40
102
|
end
|
@@ -45,7 +107,12 @@ module EjabberdRest
|
|
45
107
|
request.body = options[:body] if options[:body]
|
46
108
|
end
|
47
109
|
|
48
|
-
|
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}"
|
115
|
+
end
|
49
116
|
end
|
50
117
|
end
|
51
118
|
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.7
|
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-
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: faraday
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|