Method: App42::User::UserService#create_or_update_profile

Defined in:
lib/user/UserService.rb

#create_or_update_profile(user) ⇒ Object

Creates or Updates User Profile. First time the Profile for the user is created and in future calls user profile will be updated. This will always update the profile with new value passed in profile object. Call to this method should have all the values you want to retain in user profile object, otherwise old values of profile will get updated with null.

Method only updates the profile of user, passing email/password in user object does not have any significance for this method call.

contain the userName and profile object in it.

Parameters:

  • user
    • User for which profile has to be updated, this should

Returns:

  • User Object with updated Profile information

Raises:

  • App42Exception

See Also:



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/user/UserService.rb', line 279

def create_or_update_profile(user)
  puts "Base url #{@base_url}"
  response = nil
  userResponse = nil
  userResponse = User.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(user, "User")
  util.throwExceptionIfNullOrBlank(user.userName, "UserName")
  util.throwExceptionIfNullOrBlank(user.profile, "Profile Data")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    profile = user.profile()
    profileObj = {}
    profileObj.store("firstName", profile.firstName())
    profileObj.store("lastName", profile.lastName())
    profileObj.store("sex", profile.sex())
    profileObj.store("mobile", profile.mobile())
    profileObj.store("line1", profile.line1())
    profileObj.store("line2", profile.line2())
    profileObj.store("city", profile.city())
    profileObj.store("state", profile.state())
    profileObj.store("country", profile.country())
    profileObj.store("pincode", profile.pincode())
    profileObj.store("homeLandLine", profile.homeLandLine())
    profileObj.store("officeLandLine", profile.officeLandLine())
    if profile.dateOfBirth != nil
      profileObj.store("dateOfBirth", util.get_timestamp_utc_from_date(profile.dateOfBirth))
    end
    body = {
      'app42'=>{"user"=>{
      "userName"=>user.userName,
      "profileData"=>profileObj
      }
      }
    }.to_json
    puts "Body #{body}"
    query_params = {}
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/profile"
    response = connection.put(signature, resource_url, query_params, body)
    user = UserResponseBuilder.new
    userResponse = user.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise e
  end
  return userResponse
end