rocketchat 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +8 -0
- data/README.md +32 -1
- data/lib/rocket_chat/gem_version.rb +1 -1
- data/lib/rocket_chat/messages/user.rb +51 -1
- data/lib/rocket_chat/request_helper.rb +28 -21
- data/lib/rocket_chat/util.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 846bb0b7c4040d10264d89534bfd3d11b173a575
|
4
|
+
data.tar.gz: afa6fcb282d0c3f0af6720fff6a92b5fe1b4b043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d295d4ff6a5712cb9c547a58c968c40c8d02e57dc28fdc970a84b8960f264a991c1982346ad41b67251e990bed5127f3592fabce8b12c08f9e13e5f49c14428
|
7
|
+
data.tar.gz: 35da2385925f779f50f01c248587ec36bff6d19be6edd7b4b52ee9933538003796732ac89c75fa07bf22208415f3340075fc4231f6a9861a95d489d537070cf7
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,7 @@ And then execute:
|
|
25
25
|
|
26
26
|
## Supported API calls
|
27
27
|
|
28
|
-
This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
28
|
+
This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.54)
|
29
29
|
|
30
30
|
#### Miscellaneous information
|
31
31
|
* /api/v1/info
|
@@ -37,6 +37,9 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
|
37
37
|
|
38
38
|
### Users
|
39
39
|
* /api/v1/users.create
|
40
|
+
* /api/v1/users.delete
|
41
|
+
* /api/v1/users.info
|
42
|
+
* /api/v1/users.setAvatar
|
40
43
|
* /api/v1/users.update
|
41
44
|
|
42
45
|
|
@@ -100,6 +103,34 @@ Optional parameters for update are:
|
|
100
103
|
:username, :email, :password, :name, :active, :roles, :join_default_channels, :require_password_change, :send_welcome_email, :verified, :custom_fields
|
101
104
|
|
102
105
|
|
106
|
+
To get user info:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
require 'rocketchat'
|
110
|
+
|
111
|
+
rocket_server = RocketChat::Server.new('http://your.server.address/')
|
112
|
+
session = rocket_server.login('username', 'password')
|
113
|
+
session.users.info(username: 'some_username')
|
114
|
+
```
|
115
|
+
|
116
|
+
Either user_id (RocketChat's ID) or username can be used.
|
117
|
+
|
118
|
+
Deleting a user can be done with the same options.
|
119
|
+
|
120
|
+
|
121
|
+
To set a user's avatar:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
require 'rocketchat'
|
125
|
+
|
126
|
+
rocket_server = RocketChat::Server.new('http://your.server.address/')
|
127
|
+
session = rocket_server.login('username', 'password')
|
128
|
+
session.users.set_avatar('http://image_url')
|
129
|
+
```
|
130
|
+
|
131
|
+
There is an optional parameter user_id, that works if the setting user is allowed to set other's avatar.
|
132
|
+
|
133
|
+
|
103
134
|
## Contributing
|
104
135
|
|
105
136
|
Bug reports and pull requests are welcome on GitHub at https://github.com/abrom/rocketchat-ruby.
|
@@ -54,6 +54,56 @@ module RocketChat
|
|
54
54
|
RocketChat::User.new response['user']
|
55
55
|
end
|
56
56
|
|
57
|
+
#
|
58
|
+
# users.delete REST API
|
59
|
+
# @param [String] user_id Rocket.Chat user id
|
60
|
+
# @param [String] username Username
|
61
|
+
# @return [Boolean]
|
62
|
+
# @raise [HTTPError, StatusError]
|
63
|
+
#
|
64
|
+
def delete(user_id: nil, username: nil)
|
65
|
+
session.request_json(
|
66
|
+
'/api/v1/users.delete',
|
67
|
+
method: :post,
|
68
|
+
body: user_id ? { userId: user_id } : { username: username },
|
69
|
+
upstreamed_errors: ['error-invalid-user']
|
70
|
+
)['success']
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# users.info REST API
|
75
|
+
# @param [String] user_id Rocket.Chat user id
|
76
|
+
# @param [String] username Username
|
77
|
+
# @return [User]
|
78
|
+
# @raise [HTTPError, StatusError]
|
79
|
+
#
|
80
|
+
def info(user_id: nil, username: nil)
|
81
|
+
response = session.request_json(
|
82
|
+
'/api/v1/users.info',
|
83
|
+
body: user_id ? { userId: user_id } : { username: username },
|
84
|
+
upstreamed_errors: ['error-invalid-user']
|
85
|
+
)
|
86
|
+
|
87
|
+
RocketChat::User.new response['user'] if response['success']
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# users.setAvatar REST API
|
92
|
+
# @param [String] avatar_url URL to use for avatar
|
93
|
+
# @param [String] user_id user to update (optional)
|
94
|
+
# @return [Boolean]
|
95
|
+
# @raise [HTTPError, StatusError]
|
96
|
+
#
|
97
|
+
def set_avatar(avatar_url, user_id: nil)
|
98
|
+
body = { avatarUrl: avatar_url }
|
99
|
+
body[:userId] = user_id if user_id
|
100
|
+
session.request_json(
|
101
|
+
'/api/v1/users.setAvatar',
|
102
|
+
method: :post,
|
103
|
+
body: body
|
104
|
+
)['success']
|
105
|
+
end
|
106
|
+
|
57
107
|
private
|
58
108
|
|
59
109
|
attr_reader :session
|
@@ -61,7 +111,7 @@ module RocketChat
|
|
61
111
|
def user_option_hash(options, include_personal_fields = false)
|
62
112
|
args = [options, :active, :roles, :join_default_channels, :require_password_change,
|
63
113
|
:send_welcome_email, :verified, :custom_fields]
|
64
|
-
args += [
|
114
|
+
args += %i[username email name password] if include_personal_fields
|
65
115
|
|
66
116
|
options = Util.slice_hash(*args)
|
67
117
|
return {} if options.empty?
|
@@ -22,18 +22,13 @@ module RocketChat
|
|
22
22
|
|
23
23
|
def request_json(path, options = {})
|
24
24
|
fail_unless_ok = options.delete :fail_unless_ok
|
25
|
+
upstreamed_errors = Array(options.delete(:upstreamed_errors))
|
25
26
|
|
26
27
|
response = request path, options
|
27
|
-
|
28
|
-
raise RocketChat::HTTPError, "Invalid http response code: #{response.code}"
|
29
|
-
end
|
28
|
+
check_response response, fail_unless_ok
|
30
29
|
|
31
30
|
response_json = JSON.parse(response.body)
|
32
|
-
|
33
|
-
raise RocketChat::StatusError, response_json['error'] unless response_json['success']
|
34
|
-
else
|
35
|
-
raise RocketChat::StatusError, response_json['message'] unless response_json['status'] == 'success'
|
36
|
-
end
|
31
|
+
check_response_json response_json, upstreamed_errors
|
37
32
|
|
38
33
|
response_json
|
39
34
|
end
|
@@ -50,6 +45,21 @@ module RocketChat
|
|
50
45
|
|
51
46
|
private
|
52
47
|
|
48
|
+
def check_response(response, fail_unless_ok)
|
49
|
+
return unless fail_unless_ok && !response.is_a?(Net::HTTPOK)
|
50
|
+
raise RocketChat::HTTPError, "Invalid http response code: #{response.code}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_response_json(response_json, upstreamed_errors)
|
54
|
+
if response_json.key? 'success'
|
55
|
+
unless response_json['success'] || upstreamed_errors.include?(response_json['errorType'])
|
56
|
+
raise RocketChat::StatusError, response_json['error']
|
57
|
+
end
|
58
|
+
elsif response_json['status'] != 'success'
|
59
|
+
raise RocketChat::StatusError, response_json['message']
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
def get_headers(options)
|
54
64
|
headers = options[:headers]
|
55
65
|
|
@@ -80,11 +90,16 @@ module RocketChat
|
|
80
90
|
|
81
91
|
def create_request(path, options)
|
82
92
|
headers = get_headers(options)
|
83
|
-
|
84
|
-
req = Net::HTTP.const_get(options[:method].to_s.capitalize).new(path, headers)
|
85
|
-
|
86
93
|
body = options[:body]
|
87
|
-
|
94
|
+
|
95
|
+
if options[:method] == :post
|
96
|
+
req = Net::HTTP::Post.new(path, headers)
|
97
|
+
add_body(req, body) if body
|
98
|
+
else
|
99
|
+
uri = path
|
100
|
+
uri += '?' + URI.encode_www_form(body) if body
|
101
|
+
req = Net::HTTP::Get.new(uri, headers)
|
102
|
+
end
|
88
103
|
|
89
104
|
req
|
90
105
|
end
|
@@ -94,15 +109,7 @@ module RocketChat
|
|
94
109
|
request.body = body.to_json
|
95
110
|
request.content_type = 'application/json'
|
96
111
|
else
|
97
|
-
request.body =
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def url_encode(body)
|
102
|
-
if body.is_a?(Hash)
|
103
|
-
URI.encode_www_form body
|
104
|
-
else
|
105
|
-
body.to_s
|
112
|
+
request.body = body.to_s
|
106
113
|
end
|
107
114
|
end
|
108
115
|
end
|
data/lib/rocket_chat/util.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.5
|
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-04-
|
12
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|