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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 208917e6e7d28b70ad4d67c8225c3151172a079f
4
- data.tar.gz: d03b96ad1b9f7967fa5105c324bae3b284e1f332
3
+ metadata.gz: 5f22342235d28be96f2441fe4c11ff7dd7427df8
4
+ data.tar.gz: 7b9003e28fd1ddf2fd8e8e9d7c9c4eee7a27fc1c
5
5
  SHA512:
6
- metadata.gz: 8d9d4f928ef0d26fffba177e2a10f59d87fb5a0f6dbed7cda38ecf7e961ad1dafaac4b5e45525f05f0fc435dd6272b50e90cd362f1203dcd4f286ca30e8811a0
7
- data.tar.gz: b1be8abe3c48b7902e991afd0f6302532986934e393094be40d734f1006b01b9891e72b1ab0ae10f50c13c4c77a2d98838a3d9540424aa4cf744ff4503dd95a9
6
+ metadata.gz: bd3b3b0d43d089d87e4bc9a825e7a53579f28a84b865eb6c6a83b2a1c4aec43048be2f1148825d5911126084ba472e22ee0d564f9b82045b805ffc975dc4be34
7
+ data.tar.gz: f9818927d4920a027c00f81baffa56a1ff449e6580025be09a7f4e0549111f25e95b7ea24dae394f34b3a49e1e1ebc009a987f71a123325cd07198141ed4dbc1
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .DS_Store
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
23
24
 
24
25
  spec.add_runtime_dependency "faraday", "~> 0.9.0"
25
26
  end
@@ -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
- response.body
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
@@ -1,3 +1,3 @@
1
1
  module EjabberdRest
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.7"
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.1
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-01-31 00:00:00.000000000 Z
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