rocketchat 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b66e81f40f37674d888d4ecc579c419302e85003
4
- data.tar.gz: '018fe90ff20e767ada7b4e55f6cec4089c2b1afe'
3
+ metadata.gz: 92064005eb022f8630c18a093696fc5058cde945
4
+ data.tar.gz: 8106bebe9e04e28e06889d283876e0e00194c651
5
5
  SHA512:
6
- metadata.gz: 42d0210e35daa4efb6b48a2665158de8089c02d38be580a2313672e33c7e40d132522fd025c8b217997540da32c11c50e8c39411b312bbb6dcc4926ee649e944
7
- data.tar.gz: 8a942dfa094139fb1b4e597fbc0aa5e4ef4c5a881b4fbe43d2f5327806d9b67516485ab1133994b9b8c9222ffe3ee88cc04d656cbdafb463441ba41941a76a12
6
+ metadata.gz: a2de3192406d8a89a6b7c0cf808be8af72ba7e5a27013f3e4850987bd3858649926beb4dfe037a45ec59d0990d7a757480cfe432a469dec3c27a0a2476d6400c
7
+ data.tar.gz: dcf80cf8c56457594c613a249affdddcf29f3a77459b548db3cae7c13d549eabde4d59c487e13d901dd3280690a95c9e065e029137f89c2131cc9aa9ffd9f463
@@ -2,5 +2,6 @@ module RocketChat
2
2
  class Error < StandardError; end
3
3
  class HTTPError < Error; end
4
4
  class InvalidMethodError < HTTPError; end
5
+ class JsonParseError < Error; end
5
6
  class StatusError < Error; end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module RocketChat
2
- VERSION = '0.1.10'.freeze
2
+ VERSION = '0.1.11'.freeze
3
3
  end
@@ -13,15 +13,12 @@ module RocketChat
13
13
  # @return [Boolean]
14
14
  # @raise [HTTPError, StatusError]
15
15
  #
16
- def add_leader(room_id: nil, user_id: nil)
16
+ def add_leader(room_id: nil, name: nil, user_id: nil, username: nil)
17
17
  session.request_json(
18
18
  self.class.api_path('addLeader'),
19
19
  method: :post,
20
- body: {
21
- roomId: room_id,
22
- userId: user_id
23
- },
24
- upstreamed_errors: ['error-room-not-found']
20
+ body: room_params(room_id, name)
21
+ .merge(user_params(user_id, username))
25
22
  )['success']
26
23
  end
27
24
 
@@ -32,15 +29,12 @@ module RocketChat
32
29
  # @return [Boolean]
33
30
  # @raise [HTTPError, StatusError]
34
31
  #
35
- def remove_leader(room_id: nil, user_id: nil)
32
+ def remove_leader(room_id: nil, name: nil, user_id: nil, username: nil)
36
33
  session.request_json(
37
34
  self.class.api_path('removeLeader'),
38
35
  method: :post,
39
- body: {
40
- roomId: room_id,
41
- userId: user_id
42
- },
43
- upstreamed_errors: ['error-room-not-found']
36
+ body: room_params(room_id, name)
37
+ .merge(user_params(user_id, username))
44
38
  )['success']
45
39
  end
46
40
 
@@ -67,15 +67,12 @@ module RocketChat
67
67
  # @return [Boolean]
68
68
  # @raise [HTTPError, StatusError]
69
69
  #
70
- def add_owner(room_id: nil, user_id: nil)
70
+ def add_owner(room_id: nil, name: nil, user_id: nil, username: nil)
71
71
  session.request_json(
72
72
  self.class.api_path('addOwner'),
73
73
  method: :post,
74
- body: {
75
- roomId: room_id,
76
- userId: user_id
77
- },
78
- upstreamed_errors: ['error-room-not-found']
74
+ body: room_params(room_id, name)
75
+ .merge(user_params(user_id, username))
79
76
  )['success']
80
77
  end
81
78
 
@@ -86,15 +83,44 @@ module RocketChat
86
83
  # @return [Boolean]
87
84
  # @raise [HTTPError, StatusError]
88
85
  #
89
- def remove_owner(room_id: nil, user_id: nil)
86
+ def remove_owner(room_id: nil, name: nil, user_id: nil, username: nil)
90
87
  session.request_json(
91
88
  self.class.api_path('removeOwner'),
92
89
  method: :post,
93
- body: {
94
- roomId: room_id,
95
- userId: user_id
96
- },
97
- upstreamed_errors: ['error-room-not-found']
90
+ body: room_params(room_id, name)
91
+ .merge(user_params(user_id, username))
92
+ )['success']
93
+ end
94
+
95
+ #
96
+ # *.add_moderator REST API
97
+ # @param [String] room_id Rocket.Chat room id
98
+ # @param [String] user_id Rocket.Chat user id
99
+ # @return [Boolean]
100
+ # @raise [HTTPError, StatusError]
101
+ #
102
+ def add_moderator(room_id: nil, name: nil, user_id: nil, username: nil)
103
+ session.request_json(
104
+ self.class.api_path('addModerator'),
105
+ method: :post,
106
+ body: room_params(room_id, name)
107
+ .merge(user_params(user_id, username))
108
+ )['success']
109
+ end
110
+
111
+ #
112
+ # *.remove_moderator REST API
113
+ # @param [String] room_id Rocket.Chat room id
114
+ # @param [String] user_id Rocket.Chat user id
115
+ # @return [Boolean]
116
+ # @raise [HTTPError, StatusError]
117
+ #
118
+ def remove_moderator(room_id: nil, name: nil, user_id: nil, username: nil)
119
+ session.request_json(
120
+ self.class.api_path('removeModerator'),
121
+ method: :post,
122
+ body: room_params(room_id, name)
123
+ .merge(user_params(user_id, username))
98
124
  )['success']
99
125
  end
100
126
 
@@ -1,5 +1,6 @@
1
1
  require 'uri'
2
2
  require 'openssl'
3
+ require 'net/http'
3
4
 
4
5
  module RocketChat
5
6
  #
@@ -28,7 +29,7 @@ module RocketChat
28
29
  response = request path, options
29
30
  check_response response, fail_unless_ok
30
31
 
31
- response_json = JSON.parse(response.body)
32
+ response_json = parse_response(response.body)
32
33
  options[:debug].puts("Response: #{response_json.inspect}") if options[:debug]
33
34
  check_response_json response_json, upstreamed_errors
34
35
 
@@ -47,8 +48,14 @@ module RocketChat
47
48
 
48
49
  private
49
50
 
51
+ def parse_response(response)
52
+ JSON.parse(response)
53
+ rescue JSON::ParserError
54
+ raise RocketChat::JsonParseError, "RocketChat response parse error: #{response}"
55
+ end
56
+
50
57
  def check_response(response, fail_unless_ok)
51
- return unless fail_unless_ok && !response.is_a?(Net::HTTPOK)
58
+ return if response.is_a?(Net::HTTPOK) || !(fail_unless_ok || response.is_a?(Net::HTTPServerError))
52
59
  raise RocketChat::HTTPError, "Invalid http response code: #{response.code}"
53
60
  end
54
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocketchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - int512
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-30 00:00:00.000000000 Z
12
+ date: 2017-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler