rocketchat 0.2.1 → 0.2.3

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
  SHA256:
3
- metadata.gz: 23d1c8a93431402bbb37c5c6ec923e77c05aa3aeccab7a0e0cd598c14cabd495
4
- data.tar.gz: b4c605b263d57257cc3285449988ee7bec9272fb24af6ef70c1a759810c65562
3
+ metadata.gz: a9dd649b2ce883c528aaaa759be25034b0bf112b4c5e21ac3c9202fab78a6baa
4
+ data.tar.gz: 23e96835f8b14e4601b78bc10506ee222665acc5409b45380572007db067f765
5
5
  SHA512:
6
- metadata.gz: 2516550605f1ef594a60c13604400f863c36fe7da3f0fd06167c415cd3428f6181d8ff615835c57e3fb41282ac3b8e46b6abcd5a01436bd04068a6bff3566261
7
- data.tar.gz: a897b18924cbd3631e2d071badeb0bfb91ea09e9ef7c2e4a6b17b8f322d45200ddea061026edaad6581d0e4343d0c9a961458160551d29f816937b536b6f5d8c
6
+ metadata.gz: 9977334377d472e5e51b941f4cf359473b588d2572965bde362d79ffe09e3afc8defdfd47904a32e1e12e47f368917447dc8710227c24d76155d74ea6ee301be
7
+ data.tar.gz: 82fe7597f43165cedeae9328e2cf8145d9bc5cc0b39f924dfed7580262c1e112a010e5e5711ca74396ee494ffb7855e6aae51adb8c7f6790f7117be54b297569
@@ -11,7 +11,7 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: ['2.6', '2.7', '3.0', '3.1']
14
+ ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
15
15
 
16
16
  steps:
17
17
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -41,6 +41,9 @@ Metrics/MethodLength:
41
41
  RSpec/ExampleLength:
42
42
  Max: 10
43
43
 
44
+ RSpec/IndexedLet:
45
+ Max: 2
46
+
44
47
  RSpec/MultipleExpectations:
45
48
  Max: 5
46
49
 
data/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  ## Unreleased
4
4
  - None
5
5
 
6
+ ## [0.2.3](releases/tag/v0.2.3) - 2023-08-22
7
+ ### Added
8
+ - [#46] Add file upload support using rooms.upload endpoint ([@MrRTI][])
9
+
10
+ ## [0.2.2](releases/tag/v0.2.2) - 2023-04-21
11
+ ### Added
12
+ - [#43] Add Ruby 3.2 support ([@MrRTI][])
13
+ - [#44] Add support for thread messages ([@MrRTI][])
14
+
15
+ ### Fixed
16
+ - [#45] Fixed some rubocop lints ([@abrom][])
17
+
18
+
6
19
  ## [0.2.1](releases/tag/v0.2.1) - 2022-12-19
7
20
  ### Fixed
8
21
  - [#41] URL-encode param values in GET query strings ([@nmagedman][])
@@ -131,3 +144,4 @@
131
144
  [@christianmoretti]: https://github.com/christianmoretti
132
145
  [@alinavancea]: https://github.com/alinavancea
133
146
  [@nmagedman]: https://github.com/nmagedman
147
+ [@MrRTI]: https://github.com/MrRTi
data/Gemfile CHANGED
@@ -4,3 +4,14 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in rocketchat.gemspec
6
6
  gemspec
7
+
8
+ gem 'bundler', ['>= 1.11', '< 3.0']
9
+ gem 'rake', '>= 12.3.3'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rubocop', '~> 1.28'
12
+ gem 'rubocop-performance', '~> 1.13'
13
+ gem 'rubocop-rake', '~> 0.6'
14
+ gem 'rubocop-rspec', '~> 2.10'
15
+ gem 'simplecov', '~> 0.16', '< 0.18'
16
+ gem 'webmock', '~> 3.12'
17
+ gem 'yard', '~> 0.9.11'
data/README.md CHANGED
@@ -70,6 +70,7 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
70
70
  * [/api/v1/channels.online](docs/channels.md#channelsonline)
71
71
  * [/api/v1/channels.members](docs/channels.md#channelsmembers)
72
72
  * /api/v1/channels.unarchive
73
+ * [/api/v1/rooms.upload](docs/channels.md#channelsupload_file)
73
74
 
74
75
  #### Groups
75
76
  * /api/v1/groups.archive
@@ -92,6 +93,7 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
92
93
  * /api/v1/groups.setType
93
94
  * [/api/v1/groups.members](docs/groups.md#groupsmembers)
94
95
  * /api/v1/groups.unarchive
96
+ * [/api/v1/rooms.upload](docs/groups.md#groupsupload_file)
95
97
 
96
98
  #### Users
97
99
  * [/api/v1/users.create](docs/users.md#userscreate)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RocketChat
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.3'
5
5
  end
@@ -20,6 +20,11 @@ module RocketChat
20
20
  data['_id']
21
21
  end
22
22
 
23
+ # Message thread id
24
+ def tmid
25
+ data['tmid']
26
+ end
27
+
23
28
  # Timestamp
24
29
  def timestamp
25
30
  Time.parse data['ts']
@@ -67,7 +72,8 @@ module RocketChat
67
72
  object_id: object_id,
68
73
  id: id,
69
74
  room_id: room_id,
70
- message: message
75
+ message: message,
76
+ tmid: tmid
71
77
  )
72
78
  end
73
79
  end
@@ -55,7 +55,7 @@ module RocketChat
55
55
  # @param [String] room_id Rocket.Chat room id
56
56
  # @param [String] name Rocket.Chat room name (coming soon)
57
57
  # @param [String] channel Rocket.Chat channel name
58
- # @param [Hash] params Optional params (text, alias, emoji, avatar & attachments)
58
+ # @param [Hash] params Optional params (text, alias, emoji, tmid, avatar & attachments)
59
59
  # @return [RocketChat::Message]
60
60
  # @raise [HTTPError, StatusError]
61
61
  #
@@ -65,7 +65,7 @@ module RocketChat
65
65
  method: :post,
66
66
  body: room_params(room_id, name)
67
67
  .merge(channel: channel)
68
- .merge(Util.slice_hash(params, :text, :alias, :emoji, :avatar, :attachments))
68
+ .merge(Util.slice_hash(params, :text, :alias, :tmid, :emoji, :avatar, :attachments))
69
69
  )
70
70
  RocketChat::Message.new response['message'] if response['success']
71
71
  end
@@ -9,6 +9,8 @@ module RocketChat
9
9
  include RoomSupport
10
10
  include UserSupport
11
11
 
12
+ API_PREFIX = '/api/v1'
13
+
12
14
  def self.inherited(subclass)
13
15
  field = subclass.name.split('::')[-1].downcase
14
16
  collection = "#{field}s"
@@ -27,7 +29,7 @@ module RocketChat
27
29
 
28
30
  # Full API path to call
29
31
  def self.api_path(method)
30
- "/api/v1/#{collection}.#{method}"
32
+ "#{API_PREFIX}/#{collection}.#{method}"
31
33
  end
32
34
 
33
35
  #
@@ -304,6 +306,25 @@ module RocketChat
304
306
  response['members'].map { |hash| RocketChat::User.new hash } if response['success']
305
307
  end
306
308
 
309
+ #
310
+ # *.upload* REST API
311
+ # @param [String] room_id Rocket.Chat room id
312
+ # @param [File] file that should be uploaded to Rocket.Chat room
313
+ # @param [Hash] rest_params Optional params (msg, description, tmid)
314
+ # @return [RocketChat::Message]
315
+ # @raise [HTTPError, StatusError]
316
+ #
317
+ # https://developer.rocket.chat/reference/api/rest-api/endpoints/rooms-endpoints/upload-file-to-a-room
318
+ def upload_file(room_id:, file:, **rest_params)
319
+ response = session.request_json(
320
+ "#{API_PREFIX}/rooms.upload/#{room_id}",
321
+ method: :post,
322
+ form_data: file_upload_hash(file: file, **rest_params)
323
+ )
324
+
325
+ RocketChat::Message.new response['message'] if response['success']
326
+ end
327
+
307
328
  private
308
329
 
309
330
  attr_reader :session
@@ -323,6 +344,11 @@ module RocketChat
323
344
  raise ArgumentError, "Unsettable attribute: #{attribute || 'nil'}" unless \
324
345
  self.class.settable_attributes.include?(attribute)
325
346
  end
347
+
348
+ def file_upload_hash(**params)
349
+ permited_keys_for_file_upload = %i[file msg description tmid]
350
+ Util.slice_hash(params, *permited_keys_for_file_upload)
351
+ end
326
352
  end
327
353
  end
328
354
  end
@@ -104,11 +104,14 @@ module RocketChat
104
104
 
105
105
  def create_request(path, options)
106
106
  headers = get_headers(options)
107
- body = options[:body]&.reject { |_key, value| value.nil? }
107
+ body = reject_nils(options[:body])
108
108
 
109
109
  if options[:method] == :post
110
110
  req = Net::HTTP::Post.new(path, headers)
111
111
  add_body(req, body) if body
112
+
113
+ form_data = reject_nils(options[:form_data])
114
+ add_form_data(req, form_data) if form_data
112
115
  else
113
116
  uri = path
114
117
  uri += "?#{URI.encode_www_form(body)}" if body
@@ -126,5 +129,14 @@ module RocketChat
126
129
  request.body = body.to_s
127
130
  end
128
131
  end
132
+
133
+ def add_form_data(request, form_data)
134
+ form_data = form_data.transform_keys(&:to_s) if form_data.is_a? Hash
135
+ request.set_form(form_data, 'multipart/form-data')
136
+ end
137
+
138
+ def reject_nils(data)
139
+ data&.reject { |_key, value| value.nil? }
140
+ end
129
141
  end
130
142
  end
@@ -32,7 +32,7 @@ module RocketChat
32
32
  # @return Hash filtered by keys
33
33
  #
34
34
  def slice_hash(hash, *keys)
35
- return {} if keys.length.zero?
35
+ return {} if keys.empty?
36
36
 
37
37
  new_hash = {}
38
38
  hash.each do |key, value|
data/rocketchat.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.description = 'Rocket.Chat REST API v1 for Ruby'
16
16
  spec.homepage = 'https://github.com/abrom/rocketchat-ruby'
17
17
  spec.license = 'MIT'
18
- spec.required_ruby_version = ['>= 2.5.0', '< 3.2.0']
18
+ spec.required_ruby_version = ['>= 2.5.0', '< 3.3.0']
19
19
 
20
20
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
21
21
  # delete this section to allow pushing this gem to any host.
@@ -27,15 +27,4 @@ Gem::Specification.new do |spec|
27
27
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|docs)/}) }
28
28
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
-
31
- spec.add_development_dependency 'bundler', ['>= 1.11', '< 3.0']
32
- spec.add_development_dependency 'rake', '>= 12.3.3'
33
- spec.add_development_dependency 'rspec', '~> 3.0'
34
- spec.add_development_dependency 'rubocop', '~> 1.28'
35
- spec.add_development_dependency 'rubocop-performance', '~> 1.13'
36
- spec.add_development_dependency 'rubocop-rake', '~> 0.6'
37
- spec.add_development_dependency 'rubocop-rspec', '~> 2.10'
38
- spec.add_development_dependency 'simplecov', '~> 0.16', '< 0.18'
39
- spec.add_development_dependency 'webmock', '~> 3.12'
40
- spec.add_development_dependency 'yard', '~> 0.9.11'
41
30
  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.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - int512
@@ -9,160 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-12-19 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '1.11'
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: '3.0'
24
- type: :development
25
- prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: '1.11'
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '3.0'
34
- - !ruby/object:Gem::Dependency
35
- name: rake
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 12.3.3
41
- type: :development
42
- prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 12.3.3
48
- - !ruby/object:Gem::Dependency
49
- name: rspec
50
- requirement: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
62
- - !ruby/object:Gem::Dependency
63
- name: rubocop
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.28'
69
- type: :development
70
- prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.28'
76
- - !ruby/object:Gem::Dependency
77
- name: rubocop-performance
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.13'
83
- type: :development
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.13'
90
- - !ruby/object:Gem::Dependency
91
- name: rubocop-rake
92
- requirement: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.6'
97
- type: :development
98
- prerelease: false
99
- version_requirements: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.6'
104
- - !ruby/object:Gem::Dependency
105
- name: rubocop-rspec
106
- requirement: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '2.10'
111
- type: :development
112
- prerelease: false
113
- version_requirements: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '2.10'
118
- - !ruby/object:Gem::Dependency
119
- name: simplecov
120
- requirement: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '0.16'
125
- - - "<"
126
- - !ruby/object:Gem::Version
127
- version: '0.18'
128
- type: :development
129
- prerelease: false
130
- version_requirements: !ruby/object:Gem::Requirement
131
- requirements:
132
- - - "~>"
133
- - !ruby/object:Gem::Version
134
- version: '0.16'
135
- - - "<"
136
- - !ruby/object:Gem::Version
137
- version: '0.18'
138
- - !ruby/object:Gem::Dependency
139
- name: webmock
140
- requirement: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - "~>"
143
- - !ruby/object:Gem::Version
144
- version: '3.12'
145
- type: :development
146
- prerelease: false
147
- version_requirements: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: '3.12'
152
- - !ruby/object:Gem::Dependency
153
- name: yard
154
- requirement: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - "~>"
157
- - !ruby/object:Gem::Version
158
- version: 0.9.11
159
- type: :development
160
- prerelease: false
161
- version_requirements: !ruby/object:Gem::Requirement
162
- requirements:
163
- - - "~>"
164
- - !ruby/object:Gem::Version
165
- version: 0.9.11
12
+ date: 2023-08-22 00:00:00.000000000 Z
13
+ dependencies: []
166
14
  description: Rocket.Chat REST API v1 for Ruby
167
15
  email:
168
16
  - github@int512.net
@@ -223,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
71
  version: 2.5.0
224
72
  - - "<"
225
73
  - !ruby/object:Gem::Version
226
- version: 3.2.0
74
+ version: 3.3.0
227
75
  required_rubygems_version: !ruby/object:Gem::Requirement
228
76
  requirements:
229
77
  - - ">="