rocketchat 0.2.2 → 0.2.4

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: 4a6c0288c4420a286b0444dc84749e572fa40806874616673a360a509dfa90f8
4
- data.tar.gz: e6d74695c8e75fa49c51f4de0e6db86476b965351a9a7231d9f57b5a59d70bd1
3
+ metadata.gz: c8dcf3e2e38671372e85fa5f8791ef9014ee5e7a506fa8b4ab896e4e6658afea
4
+ data.tar.gz: ac550d2d5baae28a8dfa2337c67ae4498b05871c9b5089ae57f1dd07cf6aecd7
5
5
  SHA512:
6
- metadata.gz: bbecd274cd60768eb7fcc19a95cd9652d474405bb80047aa16e51a700b2468b1057cdfe907ab093471e4227a6870924b05c89cb41a2be8742c7a5ddb4e6a6248
7
- data.tar.gz: f6e927d6dca42397da5ea9517033e9549f9ebc238e1f994aee63ef5f33644d497330a4dfd74426f3564f71223af257a79678ac346bce5dc4610d5e95423977ba
6
+ metadata.gz: ab31a6c39910bb896658c1ea78342a25b6dcaf1e931260700871ff3b6e90b343a781175cc1115df260e2ce03b7a30373c28c446dc5e02455dc2e5abb62c720e2
7
+ data.tar.gz: 6c173e1f07a55d49ffad6d0c8f9db83b6b0d29340ca475bf0fcfc1792e5f3b5d20af7d1d9fb3f0aa32f059fe963924c35007748082132f6949dd9441d2c8d16b
data/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  ## Unreleased
4
4
  - None
5
5
 
6
+ ## [0.2.4](releases/tag/v0.2.4) - 2023-12-22
7
+ ### Added
8
+ - [#47] Add content-type and filename params for file upload ([@MrRTI][])
9
+
10
+ ## [0.2.3](releases/tag/v0.2.3) - 2023-08-22
11
+ ### Added
12
+ - [#46] Add file upload support using rooms.upload endpoint ([@MrRTI][])
13
+
6
14
  ## [0.2.2](releases/tag/v0.2.2) - 2023-04-21
7
15
  ### Added
8
16
  - [#43] Add Ruby 3.2 support ([@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.2'
4
+ VERSION = '0.2.4'
5
5
  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_array(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,19 @@ 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_array(**params)
349
+ permited_keys_for_file_upload = %i[file msg description tmid]
350
+ hash = Util.slice_hash(params, *permited_keys_for_file_upload).compact
351
+
352
+ # NOTE: https://docs.ruby-lang.org/en/master/Net/HTTPHeader.html#method-i-set_form
353
+ file_options = params.slice(:filename, :content_type).compact
354
+ hash.map do |key, value|
355
+ next [key.to_s, value, file_options] if key == :file && file_options.keys.any?
356
+
357
+ [key.to_s, value]
358
+ end
359
+ end
326
360
  end
327
361
  end
328
362
  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 = 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,13 @@ 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
+ request.set_form(form_data, 'multipart/form-data')
135
+ end
136
+
137
+ def reject_nils(data)
138
+ data&.reject { |_key, value| value.nil? }
139
+ end
129
140
  end
130
141
  end
data/rocketchat.gemspec CHANGED
@@ -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.2
4
+ version: 0.2.4
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: 2023-04-21 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-12-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
@@ -230,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
78
  - !ruby/object:Gem::Version
231
79
  version: '0'
232
80
  requirements: []
233
- rubygems_version: 3.4.1
81
+ rubygems_version: 3.3.7
234
82
  signing_key:
235
83
  specification_version: 4
236
84
  summary: Rocket.Chat REST API v1 for Ruby