Class: UserHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/moesif_rack/update_user.rb

Instance Method Summary collapse

Instance Method Details

#update_user(api_controller, debug, user_profile) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/moesif_rack/update_user.rb', line 2

def update_user(api_controller, debug, )
  if .any?
    if .key?('user_id')
      begin
        api_controller.update_user(MoesifApi::UserModel.from_hash())
        puts 'Update User Successfully' if debug
      rescue MoesifApi::APIException => e
        if e.response_code.between?(401, 403)
          puts 'Unathorized accesss updating user to Moesif. Please verify your Application Id.'
        end
        if debug
          puts 'Error updating user to Moesif, with status code: '
          puts e.response_code
        end
      end
    else
      puts 'To update an user, an user_id field is required'
    end
  else
    puts 'Expecting the input to be of the type - dictionary while updating user'
  end
end

#update_users_batch(api_controller, debug, user_profiles) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/moesif_rack/update_user.rb', line 25

def update_users_batch(api_controller, debug, user_profiles)
  userModels = []
  user_profiles.each do |user|
    if user.key?('user_id')
      userModels << MoesifApi::UserModel.from_hash(user)
    else
      puts 'To update an user, an user_id field is required'
    end
  end

  if userModels.any?
    begin
      api_controller.update_users_batch(userModels)
      puts 'Update Users Successfully' if debug
    rescue MoesifApi::APIException => e
      if e.response_code.between?(401, 403)
        puts 'Unathorized accesss updating user to Moesif. Please verify your Application Id.'
      end
      if debug
        puts 'Error updating user to Moesif, with status code: '
        puts e.response_code
      end
    end
  else
    puts 'Expecting the input to be of the type - Array of hashes while updating users in batch'
  end
end