Skip to content

Commit adb5f60

Browse files
authored
Merge pull request #30 from GetStream/add-check-user-profile
[MOD2-712] add check usr profile method
2 parents 29a8b00 + 7edcab1 commit adb5f60

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎lib/getstream_ruby/client.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_relative 'generated/common_client'
1010
require_relative 'generated/feeds_client'
1111
require_relative 'generated/moderation_client'
12+
require_relative 'extensions/moderation_extensions'
1213
require_relative 'generated/feed'
1314
require_relative 'stream_response'
1415

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
module GetStream
4+
5+
module Generated
6+
7+
class ModerationClient
8+
9+
# Experimental: Check user profile
10+
#
11+
# Warning: This is an experimental feature and the API is subject to change.
12+
#
13+
# This function is used to check a user profile for moderation.
14+
# This will not create any review queue items for the user profile.
15+
# You can just use this to check whether to allow a certain user profile
16+
# to be created or not.
17+
#
18+
# @param user_id [String] User ID to be checked
19+
# @param profile [Hash] Profile data to be checked
20+
# @option profile [String] :username Username to be checked
21+
# @option profile [String] :image Image URL to be checked
22+
# @return [Models::CheckResponse]
23+
#
24+
# @example
25+
# client.moderation.check_user_profile('user-id',
26+
# { username: 'bad_username', image: 'https://example.com/profile.jpg' })
27+
def check_user_profile(user_id, profile)
28+
if profile[:username].nil? && profile[:image].nil?
29+
raise ArgumentError, 'Either username or image must be provided'
30+
end
31+
32+
moderation_payload = Models::ModerationPayload.new
33+
moderation_payload.texts = [profile[:username]] if profile[:username]
34+
moderation_payload.images = [profile[:image]] if profile[:image]
35+
36+
check_request = Models::CheckRequest.new(
37+
entity_type: 'userprofile',
38+
entity_id: user_id,
39+
entity_creator_id: user_id,
40+
moderation_payload: moderation_payload,
41+
config_key: 'user_profile:default',
42+
options: { force_sync: true, test_mode: true },
43+
)
44+
45+
check(check_request)
46+
end
47+
48+
end
49+
50+
end
51+
52+
end

0 commit comments

Comments
 (0)