rocketchat 0.0.7 → 0.0.8

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: 6ff674c069b6c5cc2bb466966c996007d1cc286b
4
- data.tar.gz: 2d8ba00018c162adea4a1a7204419aa52c3fdb61
3
+ metadata.gz: ac447ec59a2cd4858ce06737a597577f1536fb86
4
+ data.tar.gz: b7d860d2d1118d6a2e694e90f6118aa061018434
5
5
  SHA512:
6
- metadata.gz: 40935960e7f75f53ae5eeb87608f2e232e6e837e7b1cb24247ed94f2b54cebcba1685ad9b4c7ef6d6892217727624985eef57a287d2c7041856833458a6ba3d3
7
- data.tar.gz: fb0484eae8d74644066810a156ce8cc1b2adeb7ddf001f855362d92469f18d168bca08815877e5bed8d06816a8a0327d5bc9372d305600481379ea3167174ad9
6
+ metadata.gz: 1bfd1e5f79ac35ad403164f11d88876873c709b1b6bfe660fe8fb7eb00e6114345ca62bac956528edbf0b96ffdd2cef517d53d40e7cafd9057978da3564e1cc2
7
+ data.tar.gz: cf974f96c266e81049f977a42814477cfa2b7cf48ce63f42cac340f21fc3e8a7a1ac46ff692dda360859af4dc1ad1be839b66f9d9700717dc7a2ca78d530d40f
data/README.md CHANGED
@@ -28,23 +28,26 @@ And then execute:
28
28
  This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.54)
29
29
 
30
30
  #### Miscellaneous information
31
- * /api/v1/info
31
+ * [/api/v1/info](#info)
32
32
 
33
33
  #### Authentication
34
- * /api/v1/login
35
- * /api/v1/logout
34
+ * [/api/v1/login](#authentication)
35
+ * [/api/v1/logout](#authentication)
36
36
  * /api/v1/me
37
37
 
38
38
  ### Users
39
- * /api/v1/users.create
40
- * /api/v1/users.delete
41
- * /api/v1/users.info
42
- * /api/v1/users.setAvatar
43
- * /api/v1/users.update
39
+ * [/api/v1/users.create](docs/users.md#userscreate)
40
+ * [/api/v1/users.delete](docs/users.md#usersdelete)
41
+ * [/api/v1/users.getPresence](docs/users.md#usersgetpresence)
42
+ * [/api/v1/users.info](docs/users.md#usersinfo)
43
+ * [/api/v1/users.list](docs/users.md#userslist)
44
+ * [/api/v1/users.setAvatar](docs/users.md#userssetavatar)
45
+ * [/api/v1/users.update](docs/users.md#usersupdate)
44
46
 
45
47
 
46
48
  ## Usage
47
49
 
50
+ #### info
48
51
  To get Rocket.Chat version
49
52
 
50
53
  ```ruby
@@ -55,7 +58,7 @@ info = rocket_server.info
55
58
  puts "Rocket.Chat version: #{info.version}"
56
59
  ```
57
60
 
58
-
61
+ #### authentication
59
62
  To logout from a server:
60
63
 
61
64
  ```ruby
@@ -68,78 +71,9 @@ session.logout
68
71
  ```
69
72
 
70
73
 
71
- To create a user:
72
-
73
- ```ruby
74
- require 'rocketchat'
75
-
76
- rocket_server = RocketChat::Server.new('http://your.server.address/')
77
- session = rocket_server.login('username', 'password')
78
- user = session.users.create('new_username', 'user@example.com', 'New User', '123456',
79
- active: true, send_welcome_email: false)
80
- ```
81
-
82
- Optional parameters for create are:
83
-
84
- :active, :roles, :join_default_channels, :require_password_change, :send_welcome_email, :verified, :custom_fields
85
-
86
-
87
- To update a user:
88
-
89
- ```ruby
90
- require 'rocketchat'
91
-
92
- rocket_server = RocketChat::Server.new('http://your.server.address/')
93
- session = rocket_server.login('username', 'password')
94
- user = session.users.update('LAjzCDLqggCT7B82M',
95
- email: 'updated@example.com',
96
- name: 'Updated Name',
97
- roles: ['user', 'moderator']
98
- )
99
- ```
100
-
101
- Optional parameters for update are:
102
-
103
- :username, :email, :password, :name, :active, :roles, :join_default_channels, :require_password_change, :send_welcome_email, :verified, :custom_fields
104
-
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
- user = session.users.info(username: 'some_username')
114
- ```
115
-
116
- Either user_id (RocketChat's ID) or username can be used.
117
-
118
-
119
- To delete a user, the same options as an info request can be used (`user_id` or `username`).
120
-
121
- To search for (list) users:
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
- users = session.users.list(query: { email: 'foo@example.com' })
129
- ```
130
-
131
-
132
- To set a user's avatar:
133
-
134
- ```ruby
135
- require 'rocketchat'
136
-
137
- rocket_server = RocketChat::Server.new('http://your.server.address/')
138
- session = rocket_server.login('username', 'password')
139
- success = session.users.set_avatar('http://image_url')
140
- ```
74
+ For details of specific APIs:
141
75
 
142
- There is an optional parameter user_id, that works if the setting user is allowed to set other's avatar.
76
+ * [Users](docs/users.md)
143
77
 
144
78
 
145
79
  ## Contributing
@@ -1,3 +1,3 @@
1
1
  module RocketChat
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
@@ -65,7 +65,7 @@ module RocketChat
65
65
  session.request_json(
66
66
  '/api/v1/users.delete',
67
67
  method: :post,
68
- body: user_id ? { userId: user_id } : { username: username },
68
+ body: user_params(user_id, username),
69
69
  upstreamed_errors: ['error-invalid-user']
70
70
  )['success']
71
71
  end
@@ -81,16 +81,9 @@ module RocketChat
81
81
  # @raise [HTTPError, StatusError]
82
82
  #
83
83
  def list(offset: nil, count: nil, sort: nil, fields: nil, query: nil)
84
- body = {}
85
- body[:offset] = offset.to_i if offset.is_a? Integer
86
- body[:count] = count.to_i if count.is_a? Integer
87
- body[:sort] = sort.to_json if sort.is_a? Hash
88
- body[:fields] = fields.to_json if fields.is_a? Hash
89
- body[:query] = query.to_json if query.is_a? Hash
90
-
91
84
  response = session.request_json(
92
85
  '/api/v1/users.list',
93
- body: body
86
+ body: build_list_body(offset, count, sort, fields, query)
94
87
  )
95
88
 
96
89
  response['users'].map { |hash| RocketChat::User.new hash } if response['success']
@@ -106,13 +99,29 @@ module RocketChat
106
99
  def info(user_id: nil, username: nil)
107
100
  response = session.request_json(
108
101
  '/api/v1/users.info',
109
- body: user_id ? { userId: user_id } : { username: username },
102
+ body: user_params(user_id, username),
110
103
  upstreamed_errors: ['error-invalid-user']
111
104
  )
112
105
 
113
106
  RocketChat::User.new response['user'] if response['success']
114
107
  end
115
108
 
109
+ #
110
+ # users.getPresence REST API
111
+ # @param [String] user_id Rocket.Chat user id
112
+ # @param [String] username Username
113
+ # @return [PresenceStatus]
114
+ # @raise [HTTPError, StatusError]
115
+ #
116
+ def get_presence(user_id: nil, username: nil)
117
+ response = session.request_json(
118
+ '/api/v1/users.getPresence',
119
+ body: user_params(user_id, username)
120
+ )
121
+
122
+ RocketChat::PresenceStatus.new response if response['success']
123
+ end
124
+
116
125
  #
117
126
  # users.setAvatar REST API
118
127
  # @param [String] avatar_url URL to use for avatar
@@ -146,6 +155,26 @@ module RocketChat
146
155
  options.each { |key, value| new_hash[Util.camelize(key)] = value }
147
156
  new_hash
148
157
  end
158
+
159
+ def build_list_body(offset, count, sort, fields, query)
160
+ body = {}
161
+
162
+ body[:offset] = offset.to_i if offset.is_a? Integer
163
+ body[:count] = count.to_i if count.is_a? Integer
164
+ body[:sort] = sort.to_json if sort.is_a? Hash
165
+ body[:fields] = fields.to_json if fields.is_a? Hash
166
+ body[:query] = query.to_json if query.is_a? Hash
167
+
168
+ body
169
+ end
170
+
171
+ def user_params(id, username)
172
+ if id
173
+ { userId: id }
174
+ elsif username
175
+ { username: username }
176
+ end
177
+ end
149
178
  end
150
179
  end
151
180
  end
@@ -0,0 +1,42 @@
1
+ module RocketChat
2
+ #
3
+ # Rocket.Chat PresenceStatus
4
+ #
5
+ class PresenceStatus
6
+ # Raw presence status data
7
+ attr_reader :data
8
+
9
+ #
10
+ # @param [Hash] data Raw presence status data
11
+ #
12
+ def initialize(data)
13
+ @data = Util.stringify_hash_keys data
14
+ end
15
+
16
+ # Presence
17
+ def presence
18
+ data['presence']
19
+ end
20
+
21
+ # Connection status
22
+ def connection_status
23
+ data['connectionStatus']
24
+ end
25
+
26
+ # Last login
27
+ def last_login
28
+ DateTime.parse data['lastLogin']
29
+ rescue
30
+ nil
31
+ end
32
+
33
+ def inspect
34
+ format(
35
+ '#<%s:0x%p @presence="%s">',
36
+ self.class.name,
37
+ object_id,
38
+ presence
39
+ )
40
+ end
41
+ end
42
+ end
data/lib/rocketchat.rb CHANGED
@@ -12,4 +12,5 @@ require 'rocket_chat/server'
12
12
  require 'rocket_chat/session'
13
13
  require 'rocket_chat/info'
14
14
  require 'rocket_chat/token'
15
+ require 'rocket_chat/presence_status'
15
16
  require 'rocket_chat/user'
data/rocketchat.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.homepage = 'https://github.com/abrom/rocketchat-ruby'
17
17
  spec.license = 'MIT'
18
18
 
19
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|docs)/}) }
20
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
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.7
4
+ version: 0.0.8
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-29 00:00:00.000000000 Z
12
+ date: 2017-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -116,6 +116,7 @@ files:
116
116
  - lib/rocket_chat/gem_version.rb
117
117
  - lib/rocket_chat/info.rb
118
118
  - lib/rocket_chat/messages/user.rb
119
+ - lib/rocket_chat/presence_status.rb
119
120
  - lib/rocket_chat/request_helper.rb
120
121
  - lib/rocket_chat/server.rb
121
122
  - lib/rocket_chat/session.rb