Class: Thron::Gateway::VUserManager

Inherits:
Session show all
Defined in:
lib/thron/gateway/v_user_manager.rb

Constant Summary collapse

PACKAGE =
Package.new(:xsso, :resources, self.service_name)

Constants inherited from Base

Base::NO_ACTIVE_SESSION

Instance Attribute Summary

Attributes inherited from Base

#token_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#initialize

Methods included from Pageable

included

Methods inherited from Base

#check_session, client_id, #client_id, service_name

Methods included from Routable

included, info, #route

Constructor Details

This class inherits a constructor from Thron::Gateway::Session

Class Method Details

.routesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/thron/gateway/v_user_manager.rb', line 12

def self.routes
  @routes ||= {
    create_user: Route::factory(name: 'create', package: PACKAGE),
    user_detail: Route::factory(name: 'detail', package: PACKAGE, verb: Route::Verbs::GET),
    find_users: Route::factory(name: 'findByProperties', package: PACKAGE),
    check_credentials: Route::factory(name: 'login', package: PACKAGE),
    temporary_token: Route::factory(name: 'resetPassword', package: PACKAGE),
    update_password: Route::factory(name: 'changePassword', package: PACKAGE),
    update_status: Route::factory(name: 'changeUserStatus', package: PACKAGE),
    update_capabilities_and_roles: Route::factory(name: 'updateCapabilitiesAndRoles', package: PACKAGE),
    update_external_id: Route::lazy_factory(name: 'updateExternalId', package: PACKAGE),
    update_image: Route::factory(name: 'updateImage', package: PACKAGE),
    update_settings: Route::factory(name: 'updateSettings', package: PACKAGE),
    update_user: Route::lazy_factory(name: 'updateUser', package: PACKAGE),
    upgrade_user: Route::factory(name: 'upgradeUser', package: PACKAGE)
  }
end

Instance Method Details

#check_credentials(options = {}) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/thron/gateway/v_user_manager.rb', line 82

def check_credentials(options = {})
  username = options[:username]
  password = options[:password]
  query = { 
    clientId: client_id,
    username: username,
    password: password
  }
  route(to: __callee__, query: query, token_id: token_id, dash: false) do |response|
    user = response.body.delete('user') { {} }
    response.body = Entity::Base::factory(response.body.merge!(user))
  end
end

#create_user(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/thron/gateway/v_user_manager.rb', line 30

def create_user(options = {})
  username = options[:username]
  password = options[:password]
  data = options[:data]
  body = { 
    clientId: client_id,
    newUser: {
      username: username,
      password: password
    }
  }.merge(data)
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('user') { {} })
  end
end

#find_users(options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/thron/gateway/v_user_manager.rb', line 63

def find_users(options = {})
  criteria = options.fetch(:criteria) { {} }
  order_by = options[:order_by]
  fields_option = options.fetch(:fields_option) { {} }
  offset = options[:offset].to_i
  limit = options[:limit].to_i
  body = { 
    clientId: client_id,
    criteria: criteria,
    orderBy: order_by,
    fieldsOption: fields_option,
    offset: offset.to_i,
    numberOfResult: limit.to_i
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('users') { [] })
  end
end

#temporary_token(options = {}) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/thron/gateway/v_user_manager.rb', line 96

def temporary_token(options = {})
  username = options[:username]
  body = { 
    clientId: client_id,
    username: username,
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = response.body['tmpToken']
  end
end

#update_capabilities_and_roles(options = {}) ⇒ Object



129
130
131
132
133
134
135
136
137
138
# File 'lib/thron/gateway/v_user_manager.rb', line 129

def update_capabilities_and_roles(options = {})
  username = options[:username]
  capabilities = options[:capabilities]
  body = { 
    clientId: client_id,
    username: username,
    userCapabilities: capabilities
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#update_external_id(options = {}) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/thron/gateway/v_user_manager.rb', line 140

def update_external_id(options = {})
  username = options[:username]
  external_id = options[:external_id]
  body = {
    externalId: external_id
  }
  route(to: __callee__, body: body, token_id: token_id, params: [client_id, username])
end

#update_image(options = {}) ⇒ Object



149
150
151
152
153
154
155
156
157
158
# File 'lib/thron/gateway/v_user_manager.rb', line 149

def update_image(options = {})
  username = options[:username]
  image = options[:image]
  body = {
    clientId: client_id,
    username: username,
    buffer: image
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#update_password(options = {}) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/thron/gateway/v_user_manager.rb', line 107

def update_password(options = {})
  username = options[:username]
  password = options[:password]
  query = { 
    clientId: client_id,
    username: username,
    newpassword: password
  }
  route(to: __callee__, query: query, token_id: token_id, dash: false)
end

#update_settings(options = {}) ⇒ Object



160
161
162
163
164
165
166
167
168
169
# File 'lib/thron/gateway/v_user_manager.rb', line 160

def update_settings(options = {})
  username = options[:username]
  settings = options[:settings]
  body = {
    clientId: client_id,
    username: username,
    settings: settings
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#update_status(options = {}) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/thron/gateway/v_user_manager.rb', line 118

def update_status(options = {})
  username = options[:username]
  data = options[:data]
  body = { 
    clientId: client_id,
    username: username,
    properties: data
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#update_user(options = {}) ⇒ Object



171
172
173
174
175
176
177
178
# File 'lib/thron/gateway/v_user_manager.rb', line 171

def update_user(options = {})
  username = options[:username]
  data = options[:data]
  body = {
    update: data
  }
  route(to: __callee__, body: body, token_id: token_id, params: [client_id, username])
end

#upgrade_user(options = {}) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/thron/gateway/v_user_manager.rb', line 180

def upgrade_user(options = {})
  username = options[:username]
  password = options[:password]
  data = options[:data]
  body = { 
    clientId: client_id,
    username: username,
    newPassword: password
  }.merge(data)
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('user') { {} })
  end
end

#user_detail(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/thron/gateway/v_user_manager.rb', line 46

def user_detail(options = {})
  username = options[:username]
  extra = options.fetch(:extra) { {} }
  offset = options[:offset].to_i
  limit = options[:limit].to_i
  query = {
    clientId: client_id,
    username: username,
    offset: offset.to_i,
    numberOfResults: limit.to_i
  }.merge(extra)
  route(to: __callee__, query: query, token_id: token_id, dash: false) do |response|
    user = response.body.delete('user') { {} }
    response.body = Entity::Base::factory(response.body.merge!(user))
  end
end