pusher-chatkit-server 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chatkit/client.rb +33 -7
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c38bcb5591e423012d33b2c024594b3a49895afd
4
- data.tar.gz: efdb74f954c7f05fead3249ddfd969b33770d58d
3
+ metadata.gz: 3d8705e035eae037bd66b18d5d86cb8d7acc8e52
4
+ data.tar.gz: 4ec9d238c823dbb29b43240e1494f3a9959dbe23
5
5
  SHA512:
6
- metadata.gz: fea4b09d6ecc0c62f7d380eb54c5641cb427e77a82ab18b875e6b650bb3c14e8882cab3487e4ca1080cab7674f82a875037e4f9d3c2f3b26c0652ded13189ca6
7
- data.tar.gz: 937c0bd8497fb72f60380df4bc11cd356af33e051fec96ffa5bf83879ed08e6d8cb17ef3d65a3294462e1721defc4378c278f6093a2cb1fc62e040167dcac950
6
+ metadata.gz: 2f3dd6653c0f38d26cb5245af0c5331b9bea874b2aedb1677a1197632f34d9fb61052a928b11be0e9caf607071541bbeae1eacf143716b1889850143ea5f80c7
7
+ data.tar.gz: 3b838cc62123214d0a0c81ae7e5dda9841f7ba4929ae9305aec078809b92736f7777e4c09b6c4127e3419013fc639187c2bdae35a799a62c1ffd107ce772db1d
@@ -65,7 +65,7 @@ module Chatkit
65
65
  "Content-Type": "application/json",
66
66
  },
67
67
  body: body,
68
- jwt: generate_access_token(user_id: id, su: true)
68
+ jwt: generate_access_token(su: true)
69
69
  )
70
70
  end
71
71
 
@@ -73,7 +73,7 @@ module Chatkit
73
73
  @api_instance.request(
74
74
  method: "DELETE",
75
75
  path: "/users/#{id}",
76
- jwt: generate_access_token(user_id: id, su: true)
76
+ jwt: generate_access_token(su: true)
77
77
  )
78
78
  end
79
79
 
@@ -211,14 +211,32 @@ module Chatkit
211
211
  get_permissions_for_role(role_name, ROOM_SCOPE)
212
212
  end
213
213
 
214
+ def update_role_permissions(role_name, scope, permissions_to_add, permissions_to_remove)
215
+ check_permissions(permissions_to_add+permissions_to_remove)
216
+
217
+ if permissions_to_add.empty? && permissions_to_remove.empty?
218
+ raise Chatkit::Error.new("permissions_to_add and permissions_to_remove cannot both be empty")
219
+ end
220
+
221
+ body = {}
222
+ body[:add_permissions] = permissions_to_add unless permissions_to_add.empty?
223
+ body[:remove_permissions] = permissions_to_remove unless permissions_to_remove.empty?
224
+
225
+ @authorizer_instance.request(
226
+ method: "PUT",
227
+ path: "/roles/#{role_name}/scope/#{scope}/permissions"
228
+ headers: {
229
+ "Content-Type": "application/json"
230
+ },
231
+ body: body,
232
+ jwt: generate_access_token(su: true)
233
+ )
234
+ end
235
+
214
236
  private
215
237
 
216
238
  def create_role(name, scope, permissions)
217
- permissions.each do |permission|
218
- unless VALID_PERMISSIONS[scope.to_sym].include?(permission)
219
- raise Chatkit::Error.new("Permission value #{permission} is invalid")
220
- end
221
- end
239
+ check_permissions(permissions)
222
240
 
223
241
  @authorizer_instance.request(
224
242
  method: "POST",
@@ -306,5 +324,13 @@ module Chatkit
306
324
 
307
325
  JSON.parse(resp.body)
308
326
  end
327
+
328
+ def check_permissions(permissions)
329
+ permissions.each do |permission|
330
+ unless VALID_PERMISSIONS[scope.to_sym].include?(permission)
331
+ raise Chatkit::Error.new("Permission value #{permission} is invalid")
332
+ end
333
+ end
334
+ end
309
335
  end
310
336
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-chatkit-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pusher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2017-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pusher-platform
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 2.6.13
56
+ rubygems_version: 2.6.12
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: Pusher Chatkit Ruby SDK