rocketchat 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +10 -0
- data/README.md +5 -0
- data/lib/rocket_chat/gem_version.rb +1 -1
- data/lib/rocket_chat/info.rb +2 -2
- data/lib/rocket_chat/request_helper.rb +5 -1
- data/lib/rocket_chat/session.rb +11 -0
- data/lib/rocket_chat/token.rb +2 -2
- data/lib/rocket_chat/user.rb +77 -0
- data/lib/rocketchat.rb +1 -0
- data/rocketchat.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9be0e052345a62ea82a06daeaa3c3ec9d109ef5f
|
4
|
+
data.tar.gz: c7ccbdd37e1705558d97c3f010b86755d012f97e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3f717e2a4455ae459ccba9599074c735f1dd54dd3931135fef6e06ef40f09d50a3c50d707d3eeea58f59c868875deae7569f39ac773943d9d2c021d243bb177
|
7
|
+
data.tar.gz: 845f9454268a887c7d764ce655a0b89e9c5fa89f50b61e0ca569121f380f215e04585c3b7dcd25521addebff4dc9eadd91e971fdf05f581d78874f8c498272d5
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[![Travis Build Status](http://img.shields.io/travis/abrom/rocketchat-ruby.svg?style=flat)](https://travis-ci.org/abrom/rocketchat-ruby)
|
2
|
+
[![Code Climate Score](http://img.shields.io/codeclimate/github/abrom/rocketchat-ruby.svg?style=flat)](https://codeclimate.com/github/abrom/rocketchat-ruby)
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/rocketchat-ruby.svg?style=flat)](#)
|
4
|
+
|
1
5
|
# Rocket.Chat REST API for Ruby
|
2
6
|
|
3
7
|
This is a gem wrapping the v1 REST API for [Rocket.Chat](https://rocket.chat/).
|
@@ -29,6 +33,7 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
|
29
33
|
#### Authentication
|
30
34
|
* /api/v1/login
|
31
35
|
* /api/v1/logout
|
36
|
+
* /api/v1/me
|
32
37
|
|
33
38
|
|
34
39
|
## Usage
|
data/lib/rocket_chat/info.rb
CHANGED
@@ -7,7 +7,7 @@ module RocketChat
|
|
7
7
|
attr_reader :data
|
8
8
|
|
9
9
|
#
|
10
|
-
# @param [Hash] data Raw
|
10
|
+
# @param [Hash] data Raw info data
|
11
11
|
#
|
12
12
|
def initialize(data)
|
13
13
|
@data = data.dup.freeze
|
@@ -15,7 +15,7 @@ module RocketChat
|
|
15
15
|
|
16
16
|
# Rocket.Chat version
|
17
17
|
def version
|
18
|
-
|
18
|
+
data['version']
|
19
19
|
end
|
20
20
|
|
21
21
|
def inspect
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
1
3
|
module RocketChat
|
2
4
|
#
|
3
5
|
# Rocket.Chat HTTP request helper
|
@@ -20,6 +22,8 @@ module RocketChat
|
|
20
22
|
|
21
23
|
def request_json(path, options = {})
|
22
24
|
fail_unless_ok = options.delete :fail_unless_ok
|
25
|
+
skip_status_check = options.delete :skip_status_check
|
26
|
+
|
23
27
|
response = request path, options
|
24
28
|
|
25
29
|
if fail_unless_ok && !response.is_a?(Net::HTTPOK)
|
@@ -27,7 +31,7 @@ module RocketChat
|
|
27
31
|
end
|
28
32
|
|
29
33
|
response_json = JSON.parse(response.body)
|
30
|
-
unless response_json['status'] == 'success'
|
34
|
+
unless skip_status_check || response_json['status'] == 'success'
|
31
35
|
raise RocketChat::StatusError, response_json['message']
|
32
36
|
end
|
33
37
|
|
data/lib/rocket_chat/session.rb
CHANGED
@@ -26,5 +26,16 @@ module RocketChat
|
|
26
26
|
server.request_json('/api/v1/logout', method: :post, token: token)
|
27
27
|
nil
|
28
28
|
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# me REST API
|
32
|
+
# @return [User]
|
33
|
+
# @raise [HTTPError, StatusError]
|
34
|
+
#
|
35
|
+
def me
|
36
|
+
response = server.request_json('/api/v1/me', method: :get, token: token, skip_status_check: true)
|
37
|
+
raise RocketChat::StatusError, 'Failed to fetch profile' unless response['success']
|
38
|
+
User.new response
|
39
|
+
end
|
29
40
|
end
|
30
41
|
end
|
data/lib/rocket_chat/token.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
module RocketChat
|
2
|
+
#
|
3
|
+
# Rocket.Chat User
|
4
|
+
#
|
5
|
+
class User
|
6
|
+
# Raw user data
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
#
|
10
|
+
# @param [Hash] data Raw user data
|
11
|
+
#
|
12
|
+
def initialize(data)
|
13
|
+
@data = Util.stringify_hash_keys data
|
14
|
+
end
|
15
|
+
|
16
|
+
# User ID
|
17
|
+
def id
|
18
|
+
data['_id']
|
19
|
+
end
|
20
|
+
|
21
|
+
# User name
|
22
|
+
def name
|
23
|
+
data['name']
|
24
|
+
end
|
25
|
+
|
26
|
+
# User emails
|
27
|
+
def emails
|
28
|
+
data['emails'] || []
|
29
|
+
end
|
30
|
+
|
31
|
+
# User email
|
32
|
+
def email
|
33
|
+
emails.first && emails.first['address']
|
34
|
+
end
|
35
|
+
|
36
|
+
# User email verified
|
37
|
+
def email_verified?
|
38
|
+
emails.first && emails.first['verified']
|
39
|
+
end
|
40
|
+
|
41
|
+
# User status
|
42
|
+
def status
|
43
|
+
data['status']
|
44
|
+
end
|
45
|
+
|
46
|
+
# User connection status
|
47
|
+
def status_connection
|
48
|
+
data['statusConnection']
|
49
|
+
end
|
50
|
+
|
51
|
+
# User username
|
52
|
+
def username
|
53
|
+
data['username']
|
54
|
+
end
|
55
|
+
|
56
|
+
# User UTC offset
|
57
|
+
def utc_offset
|
58
|
+
data['utcOffset']
|
59
|
+
end
|
60
|
+
|
61
|
+
# User active
|
62
|
+
def active?
|
63
|
+
data['active']
|
64
|
+
end
|
65
|
+
|
66
|
+
def inspect
|
67
|
+
format(
|
68
|
+
'#<%s:0x%p @id="%s" @username="%s" @active="%s">',
|
69
|
+
self.class.name,
|
70
|
+
object_id,
|
71
|
+
id,
|
72
|
+
username,
|
73
|
+
active?
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/rocketchat.rb
CHANGED
data/rocketchat.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.11'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
25
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
-
spec.add_development_dependency 'webmock', '~>
|
26
|
+
spec.add_development_dependency 'webmock', '~> 2.3'
|
27
27
|
spec.add_development_dependency 'yard', '~> 0.8.7.6'
|
28
28
|
spec.add_development_dependency 'rubocop', '~> 0.48.1'
|
29
29
|
end
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- int512
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '2.3'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '2.3'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: yard
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +106,7 @@ extra_rdoc_files: []
|
|
106
106
|
files:
|
107
107
|
- ".gitignore"
|
108
108
|
- ".rubocop.yml"
|
109
|
+
- ".travis.yml"
|
109
110
|
- Gemfile
|
110
111
|
- LICENSE
|
111
112
|
- README.md
|
@@ -118,6 +119,7 @@ files:
|
|
118
119
|
- lib/rocket_chat/server.rb
|
119
120
|
- lib/rocket_chat/session.rb
|
120
121
|
- lib/rocket_chat/token.rb
|
122
|
+
- lib/rocket_chat/user.rb
|
121
123
|
- lib/rocket_chat/util.rb
|
122
124
|
- lib/rocketchat.rb
|
123
125
|
- rocketchat.gemspec
|