Class: AuthingRuby::UsersManagementClient

Inherits:
Object
  • Object
show all
Defined in:
lib/authing_ruby/management/UsersManagementClient.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, graphqlClient = nil, httpClient = nil, tokenProvider = nil, publicKeyManager = nil) ⇒ UsersManagementClient

Returns a new instance of UsersManagementClient.



7
8
9
10
11
12
13
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 7

def initialize(options = {}, graphqlClient = nil, httpClient = nil, tokenProvider = nil, publicKeyManager = nil)
  @options = options
  @graphqlClient = graphqlClient
  @httpClient = httpClient
  @tokenProvider = tokenProvider
  @publicKeyManager = publicKeyManager
end

Instance Method Details

#batchObject

TODO 批量获取用户



101
102
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 101

def batch
end

#create(userInfo = {}, options = {}) ⇒ Object

创建用户



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 16

def create(userInfo = {}, options = {})
  keepPassword = options.fetch(:keepPassword, false)
  password = userInfo.fetch(:password, nil)
  # 先对密码进行处理
  if password
    publicKey = @publicKeyManager.getPublicKey()
    encryptedPassword = AuthingRuby::Utils.encrypt(password, publicKey)
    userInfo[:password] = encryptedPassword
  end

  # 然后再发请求
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  variables = {
    "userInfo": userInfo,
    "keepPassword": keepPassword,
  }
  res = graphqlAPI.createUser(@graphqlClient, @tokenProvider, variables)
  return res
end

#delete(user_id) ⇒ Object

删除用户



67
68
69
70
71
72
73
74
75
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 67

def delete(user_id)
  variables = {
    "id": user_id,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  res = graphqlAPI.deleteUser(@graphqlClient, @tokenProvider, variables)
  return res
  # {"data":{"deleteUser":{"message":"删除成功!","code":200}}}
end

#deleteMany(user_ids = []) ⇒ Object

批量删除用户



78
79
80
81
82
83
84
85
86
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 78

def deleteMany(user_ids = [])
  variables = {
    "ids": user_ids,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  res = graphqlAPI.deleteUsers(@graphqlClient, @tokenProvider, variables)
  return res
  # {"data":{"deleteUsers":{"message":"删除成功!","code":200}}}
end

#detail(user_id) ⇒ Object

通过 ID 获取用户信息



57
58
59
60
61
62
63
64
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 57

def detail(user_id)
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  variables = {
    "id": user_id,
  }
  res = graphqlAPI.user(@graphqlClient, @tokenProvider, variables)
  return res
end

#exists(options = {}) ⇒ Object

检查用户是否存在



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 105

def exists(options = {})
  username = options.fetch(:username, nil)
  email = options.fetch(:email, nil)
  phone = options.fetch(:phone, nil)
  if username == nil && email == nil && phone == nil
    throw "缺少参数, 请至少传入一个选项: username, email, phone"
  end

  variables = {
    "username": username,
    "email": email,
    "phone": phone,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  res = graphqlAPI.isUserExists(@graphqlClient, @tokenProvider, variables)
  json = JSON.parse(res)
  return json.dig('data', "isUserExists")
end

#find(options = {}) ⇒ Object

查找用户



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 125

def find(options = {})
  username = options.fetch(:username, nil)
  email = options.fetch(:email, nil)
  phone = options.fetch(:phone, nil)
  externalId = options.fetch(:externalId, nil)
  if username == nil && email == nil && phone == nil && externalId == nil
    throw "缺少参数, 请至少传入一个选项: username, email, phone, externalId"
  end

  variables = {
    "username": username,
    "email": email,
    "phone": phone,
    "externalId": externalId,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  res = graphqlAPI.findUser(@graphqlClient, @tokenProvider, variables)
  json = JSON.parse(res)
  return json
end

#list(page = 1, limit = 10) ⇒ Object

获取用户列表



89
90
91
92
93
94
95
96
97
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 89

def list(page = 1, limit = 10)
  variables = {
    "page": page,
    "limit": limit,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  res = graphqlAPI.users(@graphqlClient, @tokenProvider, variables)
  return res
end

#listRoles(user_id) ⇒ Object



157
158
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 157

def listRoles(user_id)
end

#refreshTokenObject

TODO



151
152
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 151

def refreshToken
end

#searchObject

TODO



147
148
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 147

def search
end

#update(id, updates = {}) ⇒ Object

修改用户资料



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/authing_ruby/management/UsersManagementClient.rb', line 37

def update(id, updates = {})
  # 预处理密码(如果有的话)
  password = updates.fetch(:password, nil)
  if password
    publicKey = @publicKeyManager.getPublicKey()
    encryptedPassword = AuthingRuby::Utils.encrypt(password, publicKey)
    updates[:password] = encryptedPassword
  end

  # 然后再发请求
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  variables = {
    "id": id,
    "input": updates
  }
  res = graphqlAPI.updateUser(@graphqlClient, @tokenProvider, variables)
  return res
end