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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 762d05d1acfbb58cc5b20516868c034f7c09903b
4
- data.tar.gz: c58f16cc9e678a8d31da53419c6f785b8f4a43b6
3
+ metadata.gz: 9be0e052345a62ea82a06daeaa3c3ec9d109ef5f
4
+ data.tar.gz: c7ccbdd37e1705558d97c3f010b86755d012f97e
5
5
  SHA512:
6
- metadata.gz: 03184b8414ab04854cf5b8ff0cda1d445ad006dc099b60bc065e7d2eca6c8a50037010d4ce9668fbb217a7c024d74dfc3e663ab5e9754408f5d0e0436fbd6b31
7
- data.tar.gz: 1555a4eb6a1c90524dc19712acb4085bb05533703f9757ef71d955b95a984d0f6e9b9d583ffaca732ff66df122a48c24104fe4ef8601c6b9438f89cf60e83b7d
6
+ metadata.gz: b3f717e2a4455ae459ccba9599074c735f1dd54dd3931135fef6e06ef40f09d50a3c50d707d3eeea58f59c868875deae7569f39ac773943d9d2c021d243bb177
7
+ data.tar.gz: 845f9454268a887c7d764ce655a0b89e9c5fa89f50b61e0ca569121f380f215e04585c3b7dcd25521addebff4dc9eadd91e971fdf05f581d78874f8c498272d5
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  Gemfile.lock
2
+ *.gem
@@ -4,3 +4,6 @@ Metrics/BlockLength:
4
4
 
5
5
  Metrics/LineLength:
6
6
  Max: 120
7
+
8
+ Metrics/MethodLength:
9
+ Max: 12
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.2.5
6
+ - 2.3.0
7
+ - 2.4.0
8
+
9
+ before_install:
10
+ - gem update bundler
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
@@ -1,3 +1,3 @@
1
1
  module RocketChat
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
@@ -7,7 +7,7 @@ module RocketChat
7
7
  attr_reader :data
8
8
 
9
9
  #
10
- # @param [Hash] data Raw version data
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
- @data['version']
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
 
@@ -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
@@ -15,12 +15,12 @@ module RocketChat
15
15
 
16
16
  # Authentication token
17
17
  def auth_token
18
- @data['authToken']
18
+ data['authToken']
19
19
  end
20
20
 
21
21
  # User ID
22
22
  def user_id
23
- @data['userId']
23
+ data['userId']
24
24
  end
25
25
 
26
26
  def inspect
@@ -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
@@ -10,3 +10,4 @@ require 'rocket_chat/server'
10
10
  require 'rocket_chat/session'
11
11
  require 'rocket_chat/info'
12
12
  require 'rocket_chat/token'
13
+ require 'rocket_chat/user'
@@ -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', '~> 1.24'
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.1
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: '1.24'
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: '1.24'
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