App42_Ruby_API 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.gitignore +21 -0
 - data/App42_Ruby_API.gemspec +33 -0
 - data/Gemfile +3 -0
 - data/LICENSE.txt +22 -0
 - data/README.md +29 -0
 - data/Rakefile +1 -0
 - data/TODO.rb +3 -0
 - data/lib/App42_Ruby_API.rb +232 -0
 - data/lib/App42_Ruby_API/App42BadParameterException.rb +31 -0
 - data/lib/App42_Ruby_API/App42Exception.rb +39 -0
 - data/lib/App42_Ruby_API/App42LimitException.rb +15 -0
 - data/lib/App42_Ruby_API/App42NotFoundException.rb +15 -0
 - data/lib/App42_Ruby_API/App42Response.rb +13 -0
 - data/lib/App42_Ruby_API/App42ResponseBuilder.rb +67 -0
 - data/lib/App42_Ruby_API/App42SecurityException.rb +15 -0
 - data/lib/App42_Ruby_API/version.rb +3 -0
 - data/lib/connection/RESTConnection.rb +713 -0
 - data/lib/email/Email.rb +51 -0
 - data/lib/email/EmailMIME.rb +51 -0
 - data/lib/email/EmailResponseBuilder.rb +76 -0
 - data/lib/email/EmailService.rb +244 -0
 - data/lib/gallery/Album.rb +56 -0
 - data/lib/gallery/AlbumResponseBuilder.rb +168 -0
 - data/lib/gallery/AlbumService.rb +337 -0
 - data/lib/gallery/PhotoService.rb +591 -0
 - data/lib/game/Game.rb +39 -0
 - data/lib/game/GameResponseBuilder.rb +106 -0
 - data/lib/game/GameService.rb +268 -0
 - data/lib/game/Reward.rb +24 -0
 - data/lib/game/RewardResponseBuilder.rb +85 -0
 - data/lib/game/RewardService.rb +440 -0
 - data/lib/game/ScoreBoardService.rb +433 -0
 - data/lib/game/ScoreService.rb +157 -0
 - data/lib/geo/Geo.rb +51 -0
 - data/lib/geo/GeoPoint.rb +43 -0
 - data/lib/geo/GeoResponseBuilder.rb +145 -0
 - data/lib/geo/GeoService.rb +505 -0
 - data/lib/imageProcessor/Image.rb +42 -0
 - data/lib/imageProcessor/ImageProcessorResponseBuilder.rb +40 -0
 - data/lib/imageProcessor/ImageProcessorService.rb +1054 -0
 - data/lib/log/Log.rb +49 -0
 - data/lib/log/LogResponseBuilder.rb +61 -0
 - data/lib/log/LogService.rb +920 -0
 - data/lib/message/Queue.rb +50 -0
 - data/lib/message/QueueResponseBuilder.rb +64 -0
 - data/lib/message/QueueService.rb +469 -0
 - data/lib/push/DeviceType.rb +56 -0
 - data/lib/push/PushNotification.rb +38 -0
 - data/lib/push/PushNotificationResposneBuilder.rb +74 -0
 - data/lib/push/PushNotificationService.rb +458 -0
 - data/lib/recommend/PreferenceData.rb +25 -0
 - data/lib/recommend/Recommender.rb +48 -0
 - data/lib/recommend/RecommenderResponseBuilder.rb +70 -0
 - data/lib/recommend/RecommenderService.rb +1092 -0
 - data/lib/recommend/RecommenderSimilarity.rb +52 -0
 - data/lib/review/Review.rb +38 -0
 - data/lib/review/ReviewResponseBuilder.rb +76 -0
 - data/lib/review/ReviewService.rb +590 -0
 - data/lib/session/Session.rb +43 -0
 - data/lib/session/SessionResponseBuilder.rb +70 -0
 - data/lib/session/SessionService.rb +427 -0
 - data/lib/shopping/Cart.rb +77 -0
 - data/lib/shopping/CartResponseBuilder.rb +118 -0
 - data/lib/shopping/CartService.rb +902 -0
 - data/lib/shopping/Catalogue.rb +79 -0
 - data/lib/shopping/CatalogueResponseBuilder.rb +170 -0
 - data/lib/shopping/CatalogueService.rb +649 -0
 - data/lib/shopping/ItemData.rb +29 -0
 - data/lib/shopping/PaymentStatus.rb +60 -0
 - data/lib/social/Social.rb +35 -0
 - data/lib/social/SocialResponseBuilder.rb +38 -0
 - data/lib/social/SocialService.rb +585 -0
 - data/lib/storage/OrderByType.rb +29 -0
 - data/lib/storage/Query.rb +39 -0
 - data/lib/storage/QueryBuilder.rb +118 -0
 - data/lib/storage/Storage.rb +45 -0
 - data/lib/storage/StorageResponseBuilder.rb +86 -0
 - data/lib/storage/StorageService.rb +775 -0
 - data/lib/upload/Upload.rb +40 -0
 - data/lib/upload/UploadFileType.rb +83 -0
 - data/lib/upload/UploadResponseBuilder.rb +58 -0
 - data/lib/upload/UploadService.rb +960 -0
 - data/lib/user/User.rb +102 -0
 - data/lib/user/UserResponseBuilder.rb +105 -0
 - data/lib/user/UserService.rb +1209 -0
 - data/lib/util/util.rb +244 -0
 - data/question.rb +79 -0
 - metadata +204 -0
 
    
        data/lib/user/User.rb
    ADDED
    
    | 
         @@ -0,0 +1,102 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -----------------------------------------------------------------------
         
     | 
| 
      
 2 
     | 
    
         
            +
            #  Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # -----------------------------------------------------------------------
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require 'App42_Ruby_API/App42Response'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            #
         
     | 
| 
      
 8 
     | 
    
         
            +
            #
         
     | 
| 
      
 9 
     | 
    
         
            +
            # This User object is the value object which contains the properties of User
         
     | 
| 
      
 10 
     | 
    
         
            +
            # along with the setter & getter for those properties.
         
     | 
| 
      
 11 
     | 
    
         
            +
            #
         
     | 
| 
      
 12 
     | 
    
         
            +
            #
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            module App42
         
     | 
| 
      
 15 
     | 
    
         
            +
              module User
         
     | 
| 
      
 16 
     | 
    
         
            +
                class User < App42Response
         
     | 
| 
      
 17 
     | 
    
         
            +
                  attr_accessor :userName, :password,:email, :profile, :accountLocked, :roleList
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  @userName
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @password
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @email
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @profile
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @roleList = Array.new()
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @accountLocked = false
         
     | 
| 
      
 25 
     | 
    
         
            +
                  #
         
     | 
| 
      
 26 
     | 
    
         
            +
                  # Returns the User Response in JSON format.
         
     | 
| 
      
 27 
     | 
    
         
            +
                  #
         
     | 
| 
      
 28 
     | 
    
         
            +
                  # @return the response in JSON format.
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #
         
     | 
| 
      
 30 
     | 
    
         
            +
                  #
         
     | 
| 
      
 31 
     | 
    
         
            +
                  def to_s
         
     | 
| 
      
 32 
     | 
    
         
            +
                    return strResponse
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  #
         
     | 
| 
      
 36 
     | 
    
         
            +
                  # An enum that contains the User Gender either MALE or FEMALE.
         
     | 
| 
      
 37 
     | 
    
         
            +
                  #
         
     | 
| 
      
 38 
     | 
    
         
            +
                  #
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  class UserGender
         
     | 
| 
      
 41 
     | 
    
         
            +
                    unless (const_defined?(:MALE))
         
     | 
| 
      
 42 
     | 
    
         
            +
                      MALE ="Male"
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
                    unless (const_defined?(:FEMALE))
         
     | 
| 
      
 45 
     | 
    
         
            +
                      FEMALE = "Female"
         
     | 
| 
      
 46 
     | 
    
         
            +
                    end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    #
         
     | 
| 
      
 49 
     | 
    
         
            +
                    # Sets the value of the UserGender. MALE or FEMALE.
         
     | 
| 
      
 50 
     | 
    
         
            +
                    #
         
     | 
| 
      
 51 
     | 
    
         
            +
                    # @param value
         
     | 
| 
      
 52 
     | 
    
         
            +
                    # - the value of UserGender either MALE or FEMALE.
         
     | 
| 
      
 53 
     | 
    
         
            +
                    #
         
     | 
| 
      
 54 
     | 
    
         
            +
                    def enum(string)
         
     | 
| 
      
 55 
     | 
    
         
            +
                      return UserGender.const_get(string)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                    #
         
     | 
| 
      
 59 
     | 
    
         
            +
                    # Returns the value of the UserGender. MALE or FEMALE.
         
     | 
| 
      
 60 
     | 
    
         
            +
                    #
         
     | 
| 
      
 61 
     | 
    
         
            +
                    # @return the value of UserGender.
         
     | 
| 
      
 62 
     | 
    
         
            +
                    #
         
     | 
| 
      
 63 
     | 
    
         
            +
                    #
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                    def isAvailable(string)
         
     | 
| 
      
 66 
     | 
    
         
            +
                      if(string == "Male")
         
     | 
| 
      
 67 
     | 
    
         
            +
                        return "Male"
         
     | 
| 
      
 68 
     | 
    
         
            +
                      elsif(string == "Female")
         
     | 
| 
      
 69 
     | 
    
         
            +
                        return "Female";
         
     | 
| 
      
 70 
     | 
    
         
            +
                      else
         
     | 
| 
      
 71 
     | 
    
         
            +
                        return nil
         
     | 
| 
      
 72 
     | 
    
         
            +
                      end
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                class Profile
         
     | 
| 
      
 79 
     | 
    
         
            +
                  attr_accessor :firstName, :lastName,:mobile,:line1,:line2,:city,:state,:country,:pincode,:homeLandLine,:officeLandLine,:sex,:dateOfBirth
         
     | 
| 
      
 80 
     | 
    
         
            +
                  @firstName
         
     | 
| 
      
 81 
     | 
    
         
            +
                  @lastName
         
     | 
| 
      
 82 
     | 
    
         
            +
                  @mobile
         
     | 
| 
      
 83 
     | 
    
         
            +
                  @line1
         
     | 
| 
      
 84 
     | 
    
         
            +
                  @line2
         
     | 
| 
      
 85 
     | 
    
         
            +
                  @city
         
     | 
| 
      
 86 
     | 
    
         
            +
                  @state
         
     | 
| 
      
 87 
     | 
    
         
            +
                  @country
         
     | 
| 
      
 88 
     | 
    
         
            +
                  @pincode
         
     | 
| 
      
 89 
     | 
    
         
            +
                  @homeLandLine
         
     | 
| 
      
 90 
     | 
    
         
            +
                  @officeLandLine
         
     | 
| 
      
 91 
     | 
    
         
            +
                  @sex
         
     | 
| 
      
 92 
     | 
    
         
            +
                  @dateOfBirth
         
     | 
| 
      
 93 
     | 
    
         
            +
                  #
         
     | 
| 
      
 94 
     | 
    
         
            +
                  # This is a constructor that takes no parameter
         
     | 
| 
      
 95 
     | 
    
         
            +
                  #
         
     | 
| 
      
 96 
     | 
    
         
            +
                  def initialize(user)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    user.profile = (self)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                end
         
     | 
| 
      
 101 
     | 
    
         
            +
              end
         
     | 
| 
      
 102 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,105 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -----------------------------------------------------------------------
         
     | 
| 
      
 2 
     | 
    
         
            +
            #  Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # -----------------------------------------------------------------------
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require 'json/pure'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'App42_Ruby_API/App42ResponseBuilder'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'user/User'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            module App42
         
     | 
| 
      
 10 
     | 
    
         
            +
              module User
         
     | 
| 
      
 11 
     | 
    
         
            +
                #
         
     | 
| 
      
 12 
     | 
    
         
            +
                #
         
     | 
| 
      
 13 
     | 
    
         
            +
                # UserResponseBuilder class converts the JSON response retrieved from the
         
     | 
| 
      
 14 
     | 
    
         
            +
                # server to the value object i.e User
         
     | 
| 
      
 15 
     | 
    
         
            +
                #
         
     | 
| 
      
 16 
     | 
    
         
            +
                #
         
     | 
| 
      
 17 
     | 
    
         
            +
                class UserResponseBuilder < App42ResponseBuilder
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  #
         
     | 
| 
      
 20 
     | 
    
         
            +
                  # Converts the response in JSON format to the value object i.e User
         
     | 
| 
      
 21 
     | 
    
         
            +
                  #
         
     | 
| 
      
 22 
     | 
    
         
            +
                  # @param json
         
     | 
| 
      
 23 
     | 
    
         
            +
                  #     - response in JSON format
         
     | 
| 
      
 24 
     | 
    
         
            +
                  #
         
     | 
| 
      
 25 
     | 
    
         
            +
                  # @return User object filled with json data
         
     | 
| 
      
 26 
     | 
    
         
            +
                  #
         
     | 
| 
      
 27 
     | 
    
         
            +
                  def buildResponse(json)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    users_JSON_obj = getServiceJSONObject("users", json)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    users_JSON_obj = users_JSON_obj["user"]
         
     | 
| 
      
 30 
     | 
    
         
            +
                    user = buildUserObject(users_JSON_obj);
         
     | 
| 
      
 31 
     | 
    
         
            +
                    user.strResponse=json
         
     | 
| 
      
 32 
     | 
    
         
            +
                    user.isResponseSuccess = isResponseSuccess(json)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    return user
         
     | 
| 
      
 34 
     | 
    
         
            +
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  #
         
     | 
| 
      
 37 
     | 
    
         
            +
                  # Converts the User JSON object to the value object i.e User
         
     | 
| 
      
 38 
     | 
    
         
            +
                  #
         
     | 
| 
      
 39 
     | 
    
         
            +
                  # @param userJSONObj
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #      - user data as JSONObject
         
     | 
| 
      
 41 
     | 
    
         
            +
                  #
         
     | 
| 
      
 42 
     | 
    
         
            +
                  # @return User object filled with json data
         
     | 
| 
      
 43 
     | 
    
         
            +
                  #
         
     | 
| 
      
 44 
     | 
    
         
            +
                  #
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  def buildUserObject(userJSONObj)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    user = User.new
         
     | 
| 
      
 48 
     | 
    
         
            +
                    buildObjectFromJSONTree(user,userJSONObj)
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                    if userJSONObj.key?('profile')
         
     | 
| 
      
 51 
     | 
    
         
            +
                      profileJSONObj = userJSONObj["profile"]
         
     | 
| 
      
 52 
     | 
    
         
            +
                      profile = App42::User::Profile.new(user)
         
     | 
| 
      
 53 
     | 
    
         
            +
                      buildObjectFromJSONTree(profile, profileJSONObj);
         
     | 
| 
      
 54 
     | 
    
         
            +
                    end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                    if userJSONObj.key?("role")
         
     | 
| 
      
 57 
     | 
    
         
            +
                      roleList = Array.new
         
     | 
| 
      
 58 
     | 
    
         
            +
                      if userJSONObj.fetch("role").instance_of?(Array)
         
     | 
| 
      
 59 
     | 
    
         
            +
                        roleArr = userJSONObj.fetch("role");
         
     | 
| 
      
 60 
     | 
    
         
            +
                        roleArr.length.times do |i|
         
     | 
| 
      
 61 
     | 
    
         
            +
                          roleList.push(roleArr.fetch(i))
         
     | 
| 
      
 62 
     | 
    
         
            +
                        end
         
     | 
| 
      
 63 
     | 
    
         
            +
                      else
         
     | 
| 
      
 64 
     | 
    
         
            +
                        roleList.push(userJSONObj.fetch("role"));
         
     | 
| 
      
 65 
     | 
    
         
            +
                      end
         
     | 
| 
      
 66 
     | 
    
         
            +
                      user.roleList = roleList
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
                    return user;
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                  #
         
     | 
| 
      
 72 
     | 
    
         
            +
                  # Converts the response in JSON format to the list of value objects i.e User
         
     | 
| 
      
 73 
     | 
    
         
            +
                  #
         
     | 
| 
      
 74 
     | 
    
         
            +
                  # @param json
         
     | 
| 
      
 75 
     | 
    
         
            +
                  #      - response in JSON format
         
     | 
| 
      
 76 
     | 
    
         
            +
                  #
         
     | 
| 
      
 77 
     | 
    
         
            +
                  # @return List of User object filled with json data
         
     | 
| 
      
 78 
     | 
    
         
            +
                  #
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                  def buildArrayResponse(json)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    usersJSONObj = getServiceJSONObject("users", json);
         
     | 
| 
      
 82 
     | 
    
         
            +
                    userList = Array.new
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                    if usersJSONObj["user"].instance_of?(Array)
         
     | 
| 
      
 85 
     | 
    
         
            +
                      userJSONArray = usersJSONObj["user"]
         
     | 
| 
      
 86 
     | 
    
         
            +
                      userJSONArray.length.times do |i|
         
     | 
| 
      
 87 
     | 
    
         
            +
                        userJSONObject = userJSONArray[i]
         
     | 
| 
      
 88 
     | 
    
         
            +
                        user = buildUserObject(userJSONObject);
         
     | 
| 
      
 89 
     | 
    
         
            +
                        user.strResponse=json
         
     | 
| 
      
 90 
     | 
    
         
            +
                        user.isResponseSuccess = isResponseSuccess(json)
         
     | 
| 
      
 91 
     | 
    
         
            +
                        userList.push(user)
         
     | 
| 
      
 92 
     | 
    
         
            +
                      end
         
     | 
| 
      
 93 
     | 
    
         
            +
                    else
         
     | 
| 
      
 94 
     | 
    
         
            +
                      userJSONObject = usersJSONObj["user"]
         
     | 
| 
      
 95 
     | 
    
         
            +
                      user = buildUserObject(userJSONObject);
         
     | 
| 
      
 96 
     | 
    
         
            +
                      user.strResponse=json
         
     | 
| 
      
 97 
     | 
    
         
            +
                      user.isResponseSuccess = isResponseSuccess(json)
         
     | 
| 
      
 98 
     | 
    
         
            +
                      userList.push(user)
         
     | 
| 
      
 99 
     | 
    
         
            +
                    end
         
     | 
| 
      
 100 
     | 
    
         
            +
                    return userList
         
     | 
| 
      
 101 
     | 
    
         
            +
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                end
         
     | 
| 
      
 104 
     | 
    
         
            +
              end
         
     | 
| 
      
 105 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,1209 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -----------------------------------------------------------------------
         
     | 
| 
      
 2 
     | 
    
         
            +
            #  Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # -----------------------------------------------------------------------
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'connection/RESTConnection'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'util/util'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'json/pure'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'App42_Ruby_API/App42Response'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'user/UserResponseBuilder'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'user/User'
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            module App42
         
     | 
| 
      
 15 
     | 
    
         
            +
              module User
         
     | 
| 
      
 16 
     | 
    
         
            +
                #
         
     | 
| 
      
 17 
     | 
    
         
            +
                # Creates User for the App. App42 Cloud API's provides a complete User
         
     | 
| 
      
 18 
     | 
    
         
            +
                # Management for any Mobile or Web App. It supports User registration,
         
     | 
| 
      
 19 
     | 
    
         
            +
                # retrieval, state management e.g. lock, delete and Authentication.
         
     | 
| 
      
 20 
     | 
    
         
            +
                #
         
     | 
| 
      
 21 
     | 
    
         
            +
                # Along with User Management the platform provides API's for persistent
         
     | 
| 
      
 22 
     | 
    
         
            +
                # SessionManagement
         
     | 
| 
      
 23 
     | 
    
         
            +
                #
         
     | 
| 
      
 24 
     | 
    
         
            +
                # @see SessionService
         
     | 
| 
      
 25 
     | 
    
         
            +
                # @see User
         
     | 
| 
      
 26 
     | 
    
         
            +
                # @see App42Response
         
     | 
| 
      
 27 
     | 
    
         
            +
                #
         
     | 
| 
      
 28 
     | 
    
         
            +
                class UserService
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #
         
     | 
| 
      
 30 
     | 
    
         
            +
                  # this is a constructor that takes
         
     | 
| 
      
 31 
     | 
    
         
            +
                  #
         
     | 
| 
      
 32 
     | 
    
         
            +
                  # @param apiKey
         
     | 
| 
      
 33 
     | 
    
         
            +
                  # @param secretKey
         
     | 
| 
      
 34 
     | 
    
         
            +
                  # @param baseURL
         
     | 
| 
      
 35 
     | 
    
         
            +
                  #
         
     | 
| 
      
 36 
     | 
    
         
            +
                  def initialize(api_key, secret_key, base_url)
         
     | 
| 
      
 37 
     | 
    
         
            +
                    puts "UserService->initialize"
         
     | 
| 
      
 38 
     | 
    
         
            +
                    @api_key = api_key
         
     | 
| 
      
 39 
     | 
    
         
            +
                    @secret_key = secret_key
         
     | 
| 
      
 40 
     | 
    
         
            +
                    @base_url = base_url
         
     | 
| 
      
 41 
     | 
    
         
            +
                    @resource = "user"
         
     | 
| 
      
 42 
     | 
    
         
            +
                    @version = "1.0"
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  #
         
     | 
| 
      
 46 
     | 
    
         
            +
                  # Create User for the App
         
     | 
| 
      
 47 
     | 
    
         
            +
                  #
         
     | 
| 
      
 48 
     | 
    
         
            +
                  # @param uName
         
     | 
| 
      
 49 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 50 
     | 
    
         
            +
                  # @param pwd
         
     | 
| 
      
 51 
     | 
    
         
            +
                  #      - Password for the User
         
     | 
| 
      
 52 
     | 
    
         
            +
                  # @param emailAddress
         
     | 
| 
      
 53 
     | 
    
         
            +
                  #      - Email address of the user
         
     | 
| 
      
 54 
     | 
    
         
            +
                  #
         
     | 
| 
      
 55 
     | 
    
         
            +
                  # @return The created User Object.
         
     | 
| 
      
 56 
     | 
    
         
            +
                  #
         
     | 
| 
      
 57 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 58 
     | 
    
         
            +
                  #
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  # Variable should be snake case
         
     | 
| 
      
 61 
     | 
    
         
            +
                  def create_user(user_name, pwd, email_address)
         
     | 
| 
      
 62 
     | 
    
         
            +
                    puts "Create User Called "
         
     | 
| 
      
 63 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 64 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 65 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 66 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 67 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(pwd, "Password")
         
     | 
| 
      
 68 
     | 
    
         
            +
                    util.throwExceptionIfEmailNotValid(email_address, "EmailAddress")
         
     | 
| 
      
 69 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(email_address, "EmailAddress")
         
     | 
| 
      
 70 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 71 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new @base_url
         
     | 
| 
      
 72 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 73 
     | 
    
         
            +
                        "userName" => user_name,
         
     | 
| 
      
 74 
     | 
    
         
            +
                        "password" => pwd,
         
     | 
| 
      
 75 
     | 
    
         
            +
                        "email" => email_address
         
     | 
| 
      
 76 
     | 
    
         
            +
                        }}}.to_json
         
     | 
| 
      
 77 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 78 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 79 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 80 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 81 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 82 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 83 
     | 
    
         
            +
                      }
         
     | 
| 
      
 84 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 85 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 86 
     | 
    
         
            +
                      puts params
         
     | 
| 
      
 87 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 88 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 89 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}"
         
     | 
| 
      
 90 
     | 
    
         
            +
                      response = connection.post(signature, resource_url, query_params, body)
         
     | 
| 
      
 91 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 92 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 93 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 94 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 95 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 96 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    end
         
     | 
| 
      
 98 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 99 
     | 
    
         
            +
                  end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                  #
         
     | 
| 
      
 102 
     | 
    
         
            +
                  # Gets user details based on userName
         
     | 
| 
      
 103 
     | 
    
         
            +
                  #
         
     | 
| 
      
 104 
     | 
    
         
            +
                  # @param userName
         
     | 
| 
      
 105 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 106 
     | 
    
         
            +
                  #
         
     | 
| 
      
 107 
     | 
    
         
            +
                  # @return Returns User Object
         
     | 
| 
      
 108 
     | 
    
         
            +
                  #
         
     | 
| 
      
 109 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 110 
     | 
    
         
            +
                  #
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                  def get_user(user_name)
         
     | 
| 
      
 113 
     | 
    
         
            +
                    puts "Get User Called "
         
     | 
| 
      
 114 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 115 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 116 
     | 
    
         
            +
                    usr, util  = User.new, Util.new
         
     | 
| 
      
 117 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 118 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 119 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 120 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 121 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 122 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 123 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 124 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 125 
     | 
    
         
            +
                      }
         
     | 
| 
      
 126 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 127 
     | 
    
         
            +
                      params.store("userName", user_name)
         
     | 
| 
      
 128 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 129 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/#{user_name}"
         
     | 
| 
      
 130 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 131 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 132 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 133 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 134 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 135 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 136 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 137 
     | 
    
         
            +
                    end
         
     | 
| 
      
 138 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 139 
     | 
    
         
            +
                  end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                  #
         
     | 
| 
      
 142 
     | 
    
         
            +
                  # Gets All users details
         
     | 
| 
      
 143 
     | 
    
         
            +
                  #
         
     | 
| 
      
 144 
     | 
    
         
            +
                  # @return Returns the list that contains all User Object
         
     | 
| 
      
 145 
     | 
    
         
            +
                  #
         
     | 
| 
      
 146 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 147 
     | 
    
         
            +
                  #
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                  def get_all_users()
         
     | 
| 
      
 150 
     | 
    
         
            +
                    puts "Get All Users Called"
         
     | 
| 
      
 151 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 152 
     | 
    
         
            +
                    response, userList = nil
         
     | 
| 
      
 153 
     | 
    
         
            +
                    user_list, util = [], Util.new
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 156 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 157 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 158 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 159 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 160 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 161 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 162 
     | 
    
         
            +
                      }
         
     | 
| 
      
 163 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 164 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 165 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}"
         
     | 
| 
      
 166 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 167 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 168 
     | 
    
         
            +
                      user_list = user.buildArrayResponse(response)
         
     | 
| 
      
 169 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 170 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 171 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 172 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 173 
     | 
    
         
            +
                    end
         
     | 
| 
      
 174 
     | 
    
         
            +
                    return user_list
         
     | 
| 
      
 175 
     | 
    
         
            +
                  end
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                  #
         
     | 
| 
      
 178 
     | 
    
         
            +
                  # Gets user details based on emailId
         
     | 
| 
      
 179 
     | 
    
         
            +
                  #
         
     | 
| 
      
 180 
     | 
    
         
            +
                  # @param emailId
         
     | 
| 
      
 181 
     | 
    
         
            +
                  #      - EmailId of the user to be retrieved
         
     | 
| 
      
 182 
     | 
    
         
            +
                  #
         
     | 
| 
      
 183 
     | 
    
         
            +
                  # @return Returns User Object
         
     | 
| 
      
 184 
     | 
    
         
            +
                  #
         
     | 
| 
      
 185 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 186 
     | 
    
         
            +
                  #
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
                  def get_user_by_email_id(email_id)
         
     | 
| 
      
 189 
     | 
    
         
            +
                    puts "Get All Users Called"
         
     | 
| 
      
 190 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 191 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 192 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 193 
     | 
    
         
            +
                    util.throwExceptionIfEmailNotValid(email_id, "EmailId")
         
     | 
| 
      
 194 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(email_id, "EmailId")
         
     | 
| 
      
 195 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 196 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 197 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 198 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 199 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 200 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 201 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 202 
     | 
    
         
            +
                      }
         
     | 
| 
      
 203 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 204 
     | 
    
         
            +
                      params.store("emailId", email_id)
         
     | 
| 
      
 205 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 206 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/email/#{email_id}"
         
     | 
| 
      
 207 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 208 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 209 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 210 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 211 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 212 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 213 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 214 
     | 
    
         
            +
                    end
         
     | 
| 
      
 215 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 216 
     | 
    
         
            +
                  end
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                  #
         
     | 
| 
      
 219 
     | 
    
         
            +
                  # Deletes a particular user based on userName.
         
     | 
| 
      
 220 
     | 
    
         
            +
                  #
         
     | 
| 
      
 221 
     | 
    
         
            +
                  # @param userName
         
     | 
| 
      
 222 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 223 
     | 
    
         
            +
                  #
         
     | 
| 
      
 224 
     | 
    
         
            +
                  # @return App42Response Object if user deleted successfully
         
     | 
| 
      
 225 
     | 
    
         
            +
                  #
         
     | 
| 
      
 226 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 227 
     | 
    
         
            +
                  #
         
     | 
| 
      
 228 
     | 
    
         
            +
             
     | 
| 
      
 229 
     | 
    
         
            +
                  def delete_user(user_name)
         
     | 
| 
      
 230 
     | 
    
         
            +
                    puts "Delete User Called "
         
     | 
| 
      
 231 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 232 
     | 
    
         
            +
                    response ,response_obj, util = nil, App42Response.new, Util.new
         
     | 
| 
      
 233 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 234 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 235 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 236 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 237 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 238 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 239 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 240 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 241 
     | 
    
         
            +
                      }
         
     | 
| 
      
 242 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 243 
     | 
    
         
            +
                      params.store("userName", user_name)
         
     | 
| 
      
 244 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 245 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/#{user_name}"
         
     | 
| 
      
 246 
     | 
    
         
            +
                      response = connection.delete(signature, resource_url, query_params)
         
     | 
| 
      
 247 
     | 
    
         
            +
                      response_obj.strResponse=(response)
         
     | 
| 
      
 248 
     | 
    
         
            +
                      response_obj.isResponseSuccess=(true)
         
     | 
| 
      
 249 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 250 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 251 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 252 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 253 
     | 
    
         
            +
                    end
         
     | 
| 
      
 254 
     | 
    
         
            +
                    return response_obj
         
     | 
| 
      
 255 
     | 
    
         
            +
                  end
         
     | 
| 
      
 256 
     | 
    
         
            +
             
     | 
| 
      
 257 
     | 
    
         
            +
                  #
         
     | 
| 
      
 258 
     | 
    
         
            +
                  # Creates or Updates User Profile. First time the Profile for the user is
         
     | 
| 
      
 259 
     | 
    
         
            +
                  # created and in future calls user profile will be updated. This will
         
     | 
| 
      
 260 
     | 
    
         
            +
                  # always update the profile with new value passed in profile object. Call
         
     | 
| 
      
 261 
     | 
    
         
            +
                  # to this method should have all the values you want to retain in user
         
     | 
| 
      
 262 
     | 
    
         
            +
                  # profile object, otherwise old values of profile will get updated with
         
     | 
| 
      
 263 
     | 
    
         
            +
                  # null.
         
     | 
| 
      
 264 
     | 
    
         
            +
                  #
         
     | 
| 
      
 265 
     | 
    
         
            +
                  # Method only updates the profile of user, passing email/password in user
         
     | 
| 
      
 266 
     | 
    
         
            +
                  # object does not have any significance for this method call.
         
     | 
| 
      
 267 
     | 
    
         
            +
                  #
         
     | 
| 
      
 268 
     | 
    
         
            +
                  # @param user
         
     | 
| 
      
 269 
     | 
    
         
            +
                  #       - User for which profile has to be updated, this should
         
     | 
| 
      
 270 
     | 
    
         
            +
                  # contain the userName and profile object in it.
         
     | 
| 
      
 271 
     | 
    
         
            +
                  #
         
     | 
| 
      
 272 
     | 
    
         
            +
                  # @return User Object with updated Profile information
         
     | 
| 
      
 273 
     | 
    
         
            +
                  #
         
     | 
| 
      
 274 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 275 
     | 
    
         
            +
                  #
         
     | 
| 
      
 276 
     | 
    
         
            +
                  # @see Profile
         
     | 
| 
      
 277 
     | 
    
         
            +
                  #
         
     | 
| 
      
 278 
     | 
    
         
            +
             
     | 
| 
      
 279 
     | 
    
         
            +
                  def create_or_update_profile(user)
         
     | 
| 
      
 280 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 281 
     | 
    
         
            +
                    response = nil
         
     | 
| 
      
 282 
     | 
    
         
            +
                    userResponse = nil
         
     | 
| 
      
 283 
     | 
    
         
            +
                    userResponse = User.new
         
     | 
| 
      
 284 
     | 
    
         
            +
                    util = Util.new
         
     | 
| 
      
 285 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user, "User")
         
     | 
| 
      
 286 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user.userName, "UserName")
         
     | 
| 
      
 287 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user.profile, "Profile Data")
         
     | 
| 
      
 288 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 289 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 290 
     | 
    
         
            +
                      profile = user.profile()
         
     | 
| 
      
 291 
     | 
    
         
            +
                      profileObj = {}
         
     | 
| 
      
 292 
     | 
    
         
            +
                      profileObj.store("firstName", profile.firstName())
         
     | 
| 
      
 293 
     | 
    
         
            +
                      profileObj.store("lastName", profile.lastName())
         
     | 
| 
      
 294 
     | 
    
         
            +
                      profileObj.store("sex", profile.sex())
         
     | 
| 
      
 295 
     | 
    
         
            +
                      profileObj.store("mobile", profile.mobile())
         
     | 
| 
      
 296 
     | 
    
         
            +
                      profileObj.store("line1", profile.line1())
         
     | 
| 
      
 297 
     | 
    
         
            +
                      profileObj.store("line2", profile.line2())
         
     | 
| 
      
 298 
     | 
    
         
            +
                      profileObj.store("city", profile.city())
         
     | 
| 
      
 299 
     | 
    
         
            +
                      profileObj.store("state", profile.state())
         
     | 
| 
      
 300 
     | 
    
         
            +
                      profileObj.store("country", profile.country())
         
     | 
| 
      
 301 
     | 
    
         
            +
                      profileObj.store("pincode", profile.pincode())
         
     | 
| 
      
 302 
     | 
    
         
            +
                      profileObj.store("homeLandLine", profile.homeLandLine())
         
     | 
| 
      
 303 
     | 
    
         
            +
                      profileObj.store("officeLandLine", profile.officeLandLine())
         
     | 
| 
      
 304 
     | 
    
         
            +
                      if profile.dateOfBirth != nil
         
     | 
| 
      
 305 
     | 
    
         
            +
                        profileObj.store("dateOfBirth", util.get_timestamp_utc_from_date(profile.dateOfBirth))
         
     | 
| 
      
 306 
     | 
    
         
            +
                      end
         
     | 
| 
      
 307 
     | 
    
         
            +
                      body = {
         
     | 
| 
      
 308 
     | 
    
         
            +
                        'app42'=>{"user"=>{
         
     | 
| 
      
 309 
     | 
    
         
            +
                        "userName"=>user.userName,
         
     | 
| 
      
 310 
     | 
    
         
            +
                        "profileData"=>profileObj
         
     | 
| 
      
 311 
     | 
    
         
            +
                        }
         
     | 
| 
      
 312 
     | 
    
         
            +
                        }
         
     | 
| 
      
 313 
     | 
    
         
            +
                      }.to_json
         
     | 
| 
      
 314 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 315 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 316 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 317 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 318 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 319 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 320 
     | 
    
         
            +
                      }
         
     | 
| 
      
 321 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 322 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 323 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 324 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/profile"
         
     | 
| 
      
 325 
     | 
    
         
            +
                      response = connection.put(signature, resource_url, query_params, body)
         
     | 
| 
      
 326 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 327 
     | 
    
         
            +
                      userResponse = user.buildResponse(response)
         
     | 
| 
      
 328 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 329 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 330 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 331 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 332 
     | 
    
         
            +
                    end
         
     | 
| 
      
 333 
     | 
    
         
            +
                    return userResponse
         
     | 
| 
      
 334 
     | 
    
         
            +
                  end
         
     | 
| 
      
 335 
     | 
    
         
            +
             
     | 
| 
      
 336 
     | 
    
         
            +
                  #
         
     | 
| 
      
 337 
     | 
    
         
            +
                  # Authenticate user based on userName and password
         
     | 
| 
      
 338 
     | 
    
         
            +
                  #
         
     | 
| 
      
 339 
     | 
    
         
            +
                  # @param user_name
         
     | 
| 
      
 340 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 341 
     | 
    
         
            +
                  # @param pwd
         
     | 
| 
      
 342 
     | 
    
         
            +
                  #      - Password for the User
         
     | 
| 
      
 343 
     | 
    
         
            +
                  #
         
     | 
| 
      
 344 
     | 
    
         
            +
                  # @return Whether the user is authenticated or not.
         
     | 
| 
      
 345 
     | 
    
         
            +
                  #
         
     | 
| 
      
 346 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 347 
     | 
    
         
            +
                  # if authentication fails or username/password is blank or null
         
     | 
| 
      
 348 
     | 
    
         
            +
                  #
         
     | 
| 
      
 349 
     | 
    
         
            +
             
     | 
| 
      
 350 
     | 
    
         
            +
                  def authenticate(uName, pwd)
         
     | 
| 
      
 351 
     | 
    
         
            +
                    puts "authenticateUser Called "
         
     | 
| 
      
 352 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 353 
     | 
    
         
            +
                    response,usr = nil
         
     | 
| 
      
 354 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 355 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(uName, "UserName")
         
     | 
| 
      
 356 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(pwd, "Password")
         
     | 
| 
      
 357 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 358 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 359 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 360 
     | 
    
         
            +
                        "userName" => uName,
         
     | 
| 
      
 361 
     | 
    
         
            +
                        "password" => pwd
         
     | 
| 
      
 362 
     | 
    
         
            +
                        }}}.to_json
         
     | 
| 
      
 363 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 364 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 365 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 366 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 367 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 368 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 369 
     | 
    
         
            +
                      }
         
     | 
| 
      
 370 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 371 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 372 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 373 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/authenticate"
         
     | 
| 
      
 374 
     | 
    
         
            +
                      response = connection.post(signature, resource_url, query_params, body)
         
     | 
| 
      
 375 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 376 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 377 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 378 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 379 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 380 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 381 
     | 
    
         
            +
                    end
         
     | 
| 
      
 382 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 383 
     | 
    
         
            +
                  end
         
     | 
| 
      
 384 
     | 
    
         
            +
             
     | 
| 
      
 385 
     | 
    
         
            +
                  #
         
     | 
| 
      
 386 
     | 
    
         
            +
                  # Gets All the locked users details
         
     | 
| 
      
 387 
     | 
    
         
            +
                  #
         
     | 
| 
      
 388 
     | 
    
         
            +
                  # @return Returns the list that contains locked User Objects
         
     | 
| 
      
 389 
     | 
    
         
            +
                  #
         
     | 
| 
      
 390 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 391 
     | 
    
         
            +
                  #
         
     | 
| 
      
 392 
     | 
    
         
            +
             
     | 
| 
      
 393 
     | 
    
         
            +
                  def get_locked_users()
         
     | 
| 
      
 394 
     | 
    
         
            +
                    puts "Get Locked Users Called"
         
     | 
| 
      
 395 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 396 
     | 
    
         
            +
                    response, user_list = nil
         
     | 
| 
      
 397 
     | 
    
         
            +
                    user_list, util = [], Util.new
         
     | 
| 
      
 398 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 399 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 400 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 401 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 402 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 403 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 404 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 405 
     | 
    
         
            +
                      }
         
     | 
| 
      
 406 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 407 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 408 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/locked"
         
     | 
| 
      
 409 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 410 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 411 
     | 
    
         
            +
                      user_list = user.buildArrayResponse(response)
         
     | 
| 
      
 412 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 413 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 414 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 415 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 416 
     | 
    
         
            +
                    end
         
     | 
| 
      
 417 
     | 
    
         
            +
                    return user_list
         
     | 
| 
      
 418 
     | 
    
         
            +
                  end
         
     | 
| 
      
 419 
     | 
    
         
            +
             
     | 
| 
      
 420 
     | 
    
         
            +
                  #
         
     | 
| 
      
 421 
     | 
    
         
            +
                  # Updates the User based on userName.
         
     | 
| 
      
 422 
     | 
    
         
            +
                  # Note: Only email can be updated. Username cannot be updated.
         
     | 
| 
      
 423 
     | 
    
         
            +
                  #
         
     | 
| 
      
 424 
     | 
    
         
            +
                  # @param uName
         
     | 
| 
      
 425 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 426 
     | 
    
         
            +
                  # @param emailAddress
         
     | 
| 
      
 427 
     | 
    
         
            +
                  #      - Email address of the user
         
     | 
| 
      
 428 
     | 
    
         
            +
                  #
         
     | 
| 
      
 429 
     | 
    
         
            +
                  # @return updated User Object
         
     | 
| 
      
 430 
     | 
    
         
            +
                  #
         
     | 
| 
      
 431 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 432 
     | 
    
         
            +
                  #
         
     | 
| 
      
 433 
     | 
    
         
            +
             
     | 
| 
      
 434 
     | 
    
         
            +
                  def update_email(user_name,  email_id)
         
     | 
| 
      
 435 
     | 
    
         
            +
                    puts "Update User Called "
         
     | 
| 
      
 436 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 437 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 438 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 439 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 440 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(email_id, "EmailAddress")
         
     | 
| 
      
 441 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(email_id, "Email Address")
         
     | 
| 
      
 442 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 443 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 444 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 445 
     | 
    
         
            +
                        "userName" => user_name,
         
     | 
| 
      
 446 
     | 
    
         
            +
                        "email" => email_id
         
     | 
| 
      
 447 
     | 
    
         
            +
                        }}}.to_json
         
     | 
| 
      
 448 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 449 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 450 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 451 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 452 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 453 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 454 
     | 
    
         
            +
                      }
         
     | 
| 
      
 455 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 456 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 457 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 458 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 459 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}"
         
     | 
| 
      
 460 
     | 
    
         
            +
                      response = connection.put(signature, resource_url, query_params, body)
         
     | 
| 
      
 461 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 462 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 463 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 464 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 465 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 466 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 467 
     | 
    
         
            +
                    end
         
     | 
| 
      
 468 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 469 
     | 
    
         
            +
                  end
         
     | 
| 
      
 470 
     | 
    
         
            +
             
     | 
| 
      
 471 
     | 
    
         
            +
                  #
         
     | 
| 
      
 472 
     | 
    
         
            +
                  # Locks the user based on the userName. Apps can use these feature to lock a user because of reasons specific to their
         
     | 
| 
      
 473 
     | 
    
         
            +
                  # usercase e.g. If payment not received and the App wants the user to be inactive
         
     | 
| 
      
 474 
     | 
    
         
            +
                  #
         
     | 
| 
      
 475 
     | 
    
         
            +
                  # @param uName
         
     | 
| 
      
 476 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 477 
     | 
    
         
            +
                  #
         
     | 
| 
      
 478 
     | 
    
         
            +
                  # @return Returns the locked User Object
         
     | 
| 
      
 479 
     | 
    
         
            +
                  #
         
     | 
| 
      
 480 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 481 
     | 
    
         
            +
                  #
         
     | 
| 
      
 482 
     | 
    
         
            +
             
     | 
| 
      
 483 
     | 
    
         
            +
                  def lock_user(user_name)
         
     | 
| 
      
 484 
     | 
    
         
            +
                    puts "Lock User Called "
         
     | 
| 
      
 485 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 486 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 487 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 488 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 489 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 490 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 491 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 492 
     | 
    
         
            +
                        "userName" => user_name
         
     | 
| 
      
 493 
     | 
    
         
            +
                        }}}.to_json
         
     | 
| 
      
 494 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 495 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 496 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 497 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 498 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 499 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 500 
     | 
    
         
            +
                      }
         
     | 
| 
      
 501 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 502 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 503 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 504 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/lock"
         
     | 
| 
      
 505 
     | 
    
         
            +
                      response = connection.put(signature, resource_url, query_params, body)
         
     | 
| 
      
 506 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 507 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 508 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 509 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 510 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 511 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 512 
     | 
    
         
            +
                    end
         
     | 
| 
      
 513 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 514 
     | 
    
         
            +
                  end
         
     | 
| 
      
 515 
     | 
    
         
            +
             
     | 
| 
      
 516 
     | 
    
         
            +
                  #
         
     | 
| 
      
 517 
     | 
    
         
            +
                  # Unlock the user based on the userName. Apps can use these feature to unlock a user because of reasons specific to their
         
     | 
| 
      
 518 
     | 
    
         
            +
                  # usercase e.g. If payment received and the App wants to the user to be active.
         
     | 
| 
      
 519 
     | 
    
         
            +
                  #
         
     | 
| 
      
 520 
     | 
    
         
            +
                  # @param uName
         
     | 
| 
      
 521 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 522 
     | 
    
         
            +
                  #
         
     | 
| 
      
 523 
     | 
    
         
            +
                  # @return Returns the unlocked User Object
         
     | 
| 
      
 524 
     | 
    
         
            +
                  #
         
     | 
| 
      
 525 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 526 
     | 
    
         
            +
                  #
         
     | 
| 
      
 527 
     | 
    
         
            +
             
     | 
| 
      
 528 
     | 
    
         
            +
                  def unlock_user(user_name)
         
     | 
| 
      
 529 
     | 
    
         
            +
                    puts "unlockUser Called "
         
     | 
| 
      
 530 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 531 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 532 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 533 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 534 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 535 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 536 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 537 
     | 
    
         
            +
                        "userName" => user_name
         
     | 
| 
      
 538 
     | 
    
         
            +
                        }}}.to_json
         
     | 
| 
      
 539 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 540 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 541 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 542 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 543 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 544 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 545 
     | 
    
         
            +
                      }
         
     | 
| 
      
 546 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 547 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 548 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 549 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/unlock"
         
     | 
| 
      
 550 
     | 
    
         
            +
                      response = connection.put(signature, resource_url, query_params, body)
         
     | 
| 
      
 551 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 552 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 553 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 554 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 555 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 556 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 557 
     | 
    
         
            +
                    end
         
     | 
| 
      
 558 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 559 
     | 
    
         
            +
                  end
         
     | 
| 
      
 560 
     | 
    
         
            +
             
     | 
| 
      
 561 
     | 
    
         
            +
                  #
         
     | 
| 
      
 562 
     | 
    
         
            +
                  # Gets All users By Paging
         
     | 
| 
      
 563 
     | 
    
         
            +
                  #
         
     | 
| 
      
 564 
     | 
    
         
            +
                  # @param max
         
     | 
| 
      
 565 
     | 
    
         
            +
                  #      - Maximum number of records to be fetched
         
     | 
| 
      
 566 
     | 
    
         
            +
                  # @param offset
         
     | 
| 
      
 567 
     | 
    
         
            +
                  #     - From where the records are to be fetched
         
     | 
| 
      
 568 
     | 
    
         
            +
                  #
         
     | 
| 
      
 569 
     | 
    
         
            +
                  # @return Returns User Information
         
     | 
| 
      
 570 
     | 
    
         
            +
                  #
         
     | 
| 
      
 571 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 572 
     | 
    
         
            +
                  #
         
     | 
| 
      
 573 
     | 
    
         
            +
             
     | 
| 
      
 574 
     | 
    
         
            +
                  def get_all_users_by_paging(max, offset)
         
     | 
| 
      
 575 
     | 
    
         
            +
                    puts "getAllUsersByPaging Called "
         
     | 
| 
      
 576 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 577 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 578 
     | 
    
         
            +
                    user_list, util = User.new, Util.new
         
     | 
| 
      
 579 
     | 
    
         
            +
                    util.validateMax(max)
         
     | 
| 
      
 580 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(max, "Max")
         
     | 
| 
      
 581 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(offset, "Offset")
         
     | 
| 
      
 582 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 583 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 584 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 585 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 586 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 587 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 588 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 589 
     | 
    
         
            +
                      }
         
     | 
| 
      
 590 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 591 
     | 
    
         
            +
                      params.store("max", "" + (max.to_i).to_s)
         
     | 
| 
      
 592 
     | 
    
         
            +
                      params.store("offset", "" + (offset.to_i).to_s)
         
     | 
| 
      
 593 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 594 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
         
     | 
| 
      
 595 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 596 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 597 
     | 
    
         
            +
                      user_list = user.buildArrayResponse(response)
         
     | 
| 
      
 598 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 599 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 600 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 601 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 602 
     | 
    
         
            +
                    end
         
     | 
| 
      
 603 
     | 
    
         
            +
                    return user_list
         
     | 
| 
      
 604 
     | 
    
         
            +
                  end
         
     | 
| 
      
 605 
     | 
    
         
            +
             
     | 
| 
      
 606 
     | 
    
         
            +
                  #
         
     | 
| 
      
 607 
     | 
    
         
            +
                  # Gets All the locked users By paging details
         
     | 
| 
      
 608 
     | 
    
         
            +
                  #
         
     | 
| 
      
 609 
     | 
    
         
            +
                  # @param max
         
     | 
| 
      
 610 
     | 
    
         
            +
                  #      - Maximum number of records to be fetched
         
     | 
| 
      
 611 
     | 
    
         
            +
                  # @param offset
         
     | 
| 
      
 612 
     | 
    
         
            +
                  #      - From where the records are to be fetched
         
     | 
| 
      
 613 
     | 
    
         
            +
                  #
         
     | 
| 
      
 614 
     | 
    
         
            +
                  # @return Returns User Information
         
     | 
| 
      
 615 
     | 
    
         
            +
                  #
         
     | 
| 
      
 616 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 617 
     | 
    
         
            +
                  #
         
     | 
| 
      
 618 
     | 
    
         
            +
             
     | 
| 
      
 619 
     | 
    
         
            +
                  def get_locked_users_by_paging(max, offset)
         
     | 
| 
      
 620 
     | 
    
         
            +
                    puts "get_locked_users_by_paging Called "
         
     | 
| 
      
 621 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 622 
     | 
    
         
            +
                    response, user, user_list, util = nil,nil, User.new, Util.new
         
     | 
| 
      
 623 
     | 
    
         
            +
                    util.validateMax(max)
         
     | 
| 
      
 624 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(max, "Max")
         
     | 
| 
      
 625 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(offset, "Offset")
         
     | 
| 
      
 626 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 627 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 628 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 629 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 630 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 631 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 632 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 633 
     | 
    
         
            +
                      }
         
     | 
| 
      
 634 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 635 
     | 
    
         
            +
                      params.store("max", "" + (max.to_i).to_s)
         
     | 
| 
      
 636 
     | 
    
         
            +
                      params.store("offset", "" + (offset.to_i).to_s)
         
     | 
| 
      
 637 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 638 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/locked/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
         
     | 
| 
      
 639 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 640 
     | 
    
         
            +
                      user = UserResponseBuilder.new
         
     | 
| 
      
 641 
     | 
    
         
            +
                      user_list = user.buildArrayResponse(response)
         
     | 
| 
      
 642 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 643 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 644 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 645 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 646 
     | 
    
         
            +
                    end
         
     | 
| 
      
 647 
     | 
    
         
            +
                    return user_list
         
     | 
| 
      
 648 
     | 
    
         
            +
                  end
         
     | 
| 
      
 649 
     | 
    
         
            +
             
     | 
| 
      
 650 
     | 
    
         
            +
                  #
         
     | 
| 
      
 651 
     | 
    
         
            +
                  # Change the password for user based on the userName.
         
     | 
| 
      
 652 
     | 
    
         
            +
                  #
         
     | 
| 
      
 653 
     | 
    
         
            +
                  # @param uName
         
     | 
| 
      
 654 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 655 
     | 
    
         
            +
                  # @param oldPwd
         
     | 
| 
      
 656 
     | 
    
         
            +
                  #      - Old Password for the user for authentication
         
     | 
| 
      
 657 
     | 
    
         
            +
                  # @param newPwd
         
     | 
| 
      
 658 
     | 
    
         
            +
                  #      - New Password for the user to change
         
     | 
| 
      
 659 
     | 
    
         
            +
                  #
         
     | 
| 
      
 660 
     | 
    
         
            +
                  # @return App42Response Object if updated successfully
         
     | 
| 
      
 661 
     | 
    
         
            +
                  #
         
     | 
| 
      
 662 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 663 
     | 
    
         
            +
                  #
         
     | 
| 
      
 664 
     | 
    
         
            +
             
     | 
| 
      
 665 
     | 
    
         
            +
                  def change_user_password(user_name, old_password, new_password)
         
     | 
| 
      
 666 
     | 
    
         
            +
                    puts "changeUserPassword Called "
         
     | 
| 
      
 667 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 668 
     | 
    
         
            +
                    response = nil
         
     | 
| 
      
 669 
     | 
    
         
            +
                    responseObj = App42Response.new()
         
     | 
| 
      
 670 
     | 
    
         
            +
                    util = Util.new
         
     | 
| 
      
 671 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 672 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(old_password, "Old Password")
         
     | 
| 
      
 673 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(new_password, "New Password")
         
     | 
| 
      
 674 
     | 
    
         
            +
                    responseObj = App42Response.new
         
     | 
| 
      
 675 
     | 
    
         
            +
                    if(old_password == new_password)
         
     | 
| 
      
 676 
     | 
    
         
            +
                      raise App42Exception.new("Old password and new password are same")
         
     | 
| 
      
 677 
     | 
    
         
            +
                    end
         
     | 
| 
      
 678 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 679 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 680 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 681 
     | 
    
         
            +
                        "userName" => user_name,
         
     | 
| 
      
 682 
     | 
    
         
            +
                        "oldPassword" => old_password,
         
     | 
| 
      
 683 
     | 
    
         
            +
                        "newPassword" => new_password
         
     | 
| 
      
 684 
     | 
    
         
            +
                        }}}.to_json
         
     | 
| 
      
 685 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 686 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 687 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 688 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 689 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 690 
     | 
    
         
            +
                      }
         
     | 
| 
      
 691 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 692 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 693 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 694 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/changeUserPassword"
         
     | 
| 
      
 695 
     | 
    
         
            +
                      response = connection.put(signature, resource_url, query_params, body)
         
     | 
| 
      
 696 
     | 
    
         
            +
                      responseObj.strResponse=(response)
         
     | 
| 
      
 697 
     | 
    
         
            +
                      responseObj.isResponseSuccess=(true)
         
     | 
| 
      
 698 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 699 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 700 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 701 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 702 
     | 
    
         
            +
                    end
         
     | 
| 
      
 703 
     | 
    
         
            +
                    return responseObj
         
     | 
| 
      
 704 
     | 
    
         
            +
                  end
         
     | 
| 
      
 705 
     | 
    
         
            +
             
     | 
| 
      
 706 
     | 
    
         
            +
                  #
         
     | 
| 
      
 707 
     | 
    
         
            +
                  # Gets the count of all the users
         
     | 
| 
      
 708 
     | 
    
         
            +
                  #
         
     | 
| 
      
 709 
     | 
    
         
            +
                  # @return Returns the count of all User exists
         
     | 
| 
      
 710 
     | 
    
         
            +
                  #
         
     | 
| 
      
 711 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 712 
     | 
    
         
            +
                  #
         
     | 
| 
      
 713 
     | 
    
         
            +
             
     | 
| 
      
 714 
     | 
    
         
            +
                  def get_all_users_count
         
     | 
| 
      
 715 
     | 
    
         
            +
                    puts "getAllUsersCount Called "
         
     | 
| 
      
 716 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 717 
     | 
    
         
            +
                    response = nil
         
     | 
| 
      
 718 
     | 
    
         
            +
                    responseObj, util = App42Response.new, Util.new
         
     | 
| 
      
 719 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 720 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 721 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 722 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 723 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 724 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 725 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 726 
     | 
    
         
            +
                      }
         
     | 
| 
      
 727 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 728 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 729 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/count/all"
         
     | 
| 
      
 730 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 731 
     | 
    
         
            +
                      responseObj.strResponse=(response)
         
     | 
| 
      
 732 
     | 
    
         
            +
                      responseObj.isResponseSuccess=(true)
         
     | 
| 
      
 733 
     | 
    
         
            +
                      responseObj = UserResponseBuilder.new()
         
     | 
| 
      
 734 
     | 
    
         
            +
                      responseObj.getTotalRecords(response)
         
     | 
| 
      
 735 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 736 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 737 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 738 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 739 
     | 
    
         
            +
                    end
         
     | 
| 
      
 740 
     | 
    
         
            +
                    return responseObj
         
     | 
| 
      
 741 
     | 
    
         
            +
                  end
         
     | 
| 
      
 742 
     | 
    
         
            +
             
     | 
| 
      
 743 
     | 
    
         
            +
                  #
         
     | 
| 
      
 744 
     | 
    
         
            +
                  # Gets the count of all the locked users
         
     | 
| 
      
 745 
     | 
    
         
            +
                  #
         
     | 
| 
      
 746 
     | 
    
         
            +
                  # @return Returns the count of locked User exists
         
     | 
| 
      
 747 
     | 
    
         
            +
                  #
         
     | 
| 
      
 748 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 749 
     | 
    
         
            +
                  #
         
     | 
| 
      
 750 
     | 
    
         
            +
             
     | 
| 
      
 751 
     | 
    
         
            +
                  def get_locked_users_count()
         
     | 
| 
      
 752 
     | 
    
         
            +
                    puts "getLockedUsersCount Called "
         
     | 
| 
      
 753 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 754 
     | 
    
         
            +
                    response = nil
         
     | 
| 
      
 755 
     | 
    
         
            +
                    responseObj = App42Response.new()
         
     | 
| 
      
 756 
     | 
    
         
            +
                    util = Util.new
         
     | 
| 
      
 757 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 758 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 759 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 760 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 761 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 762 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 763 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 764 
     | 
    
         
            +
                      }
         
     | 
| 
      
 765 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 766 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 767 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 768 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/count/locked"
         
     | 
| 
      
 769 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 770 
     | 
    
         
            +
                      responseObj.strResponse=(response)
         
     | 
| 
      
 771 
     | 
    
         
            +
                      responseObj.isResponseSuccess=(true)
         
     | 
| 
      
 772 
     | 
    
         
            +
                      responseObj = UserResponseBuilder.new()
         
     | 
| 
      
 773 
     | 
    
         
            +
                      responseObj.getTotalRecords(response)
         
     | 
| 
      
 774 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 775 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 776 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 777 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 778 
     | 
    
         
            +
                    end
         
     | 
| 
      
 779 
     | 
    
         
            +
                    return responseObj
         
     | 
| 
      
 780 
     | 
    
         
            +
                  end
         
     | 
| 
      
 781 
     | 
    
         
            +
             
     | 
| 
      
 782 
     | 
    
         
            +
                  #
         
     | 
| 
      
 783 
     | 
    
         
            +
                  # Create User for the App
         
     | 
| 
      
 784 
     | 
    
         
            +
                  #
         
     | 
| 
      
 785 
     | 
    
         
            +
                  # @param uName
         
     | 
| 
      
 786 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 787 
     | 
    
         
            +
                  # @param pwd
         
     | 
| 
      
 788 
     | 
    
         
            +
                  #      - Password for the User
         
     | 
| 
      
 789 
     | 
    
         
            +
                  # @param emailAddress
         
     | 
| 
      
 790 
     | 
    
         
            +
                  #      - Email address of the user
         
     | 
| 
      
 791 
     | 
    
         
            +
                  # @param roleList
         
     | 
| 
      
 792 
     | 
    
         
            +
                  #      - list of roles to be assigned to User
         
     | 
| 
      
 793 
     | 
    
         
            +
                  #
         
     | 
| 
      
 794 
     | 
    
         
            +
                  # @return The created User Object.
         
     | 
| 
      
 795 
     | 
    
         
            +
                  #
         
     | 
| 
      
 796 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 797 
     | 
    
         
            +
                  #
         
     | 
| 
      
 798 
     | 
    
         
            +
             
     | 
| 
      
 799 
     | 
    
         
            +
                  def create_user_with_role(user_name, pwd, email_address, role_list)
         
     | 
| 
      
 800 
     | 
    
         
            +
                    puts "Create User Called "
         
     | 
| 
      
 801 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 802 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 803 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 804 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 805 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(pwd, "Password")
         
     | 
| 
      
 806 
     | 
    
         
            +
                    util.throwExceptionIfEmailNotValid(email_address, "EmailAddress")
         
     | 
| 
      
 807 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(email_address, "EmailAddress")
         
     | 
| 
      
 808 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(role_list, "RoleList")
         
     | 
| 
      
 809 
     | 
    
         
            +
                    raise App42Exception.new("RoleList cannot be empty.Please assign at least one role") if role_list.size == 0
         
     | 
| 
      
 810 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 811 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 812 
     | 
    
         
            +
                      role_array = []
         
     | 
| 
      
 813 
     | 
    
         
            +
                      for role in role_list do
         
     | 
| 
      
 814 
     | 
    
         
            +
                        role_array.push(role)
         
     | 
| 
      
 815 
     | 
    
         
            +
                      end
         
     | 
| 
      
 816 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 817 
     | 
    
         
            +
                        "email" => email_address,
         
     | 
| 
      
 818 
     | 
    
         
            +
                        "password" => pwd,
         
     | 
| 
      
 819 
     | 
    
         
            +
                        "userName" => user_name, "roles" => {
         
     | 
| 
      
 820 
     | 
    
         
            +
                        "role" => role_array
         
     | 
| 
      
 821 
     | 
    
         
            +
                        }}}}.to_json
         
     | 
| 
      
 822 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 823 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 824 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 825 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 826 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 827 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 828 
     | 
    
         
            +
                      }
         
     | 
| 
      
 829 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 830 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 831 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 832 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 833 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/role"
         
     | 
| 
      
 834 
     | 
    
         
            +
                      response = connection.post(signature, resource_url, query_params, body)
         
     | 
| 
      
 835 
     | 
    
         
            +
                      user = UserResponseBuilder.new()
         
     | 
| 
      
 836 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 837 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 838 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 839 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 840 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 841 
     | 
    
         
            +
                    end
         
     | 
| 
      
 842 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 843 
     | 
    
         
            +
                  end
         
     | 
| 
      
 844 
     | 
    
         
            +
             
     | 
| 
      
 845 
     | 
    
         
            +
                  #
         
     | 
| 
      
 846 
     | 
    
         
            +
                  # Get Roles based on userName
         
     | 
| 
      
 847 
     | 
    
         
            +
                  #
         
     | 
| 
      
 848 
     | 
    
         
            +
                  # @param userName
         
     | 
| 
      
 849 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 850 
     | 
    
         
            +
                  #
         
     | 
| 
      
 851 
     | 
    
         
            +
                  # @return Returns User Object
         
     | 
| 
      
 852 
     | 
    
         
            +
                  #
         
     | 
| 
      
 853 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 854 
     | 
    
         
            +
                  #
         
     | 
| 
      
 855 
     | 
    
         
            +
             
     | 
| 
      
 856 
     | 
    
         
            +
                  def get_roles_by_user(user_name)
         
     | 
| 
      
 857 
     | 
    
         
            +
                    puts "getRolesByUser Called "
         
     | 
| 
      
 858 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 859 
     | 
    
         
            +
                    response, user = nil
         
     | 
| 
      
 860 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 861 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 862 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 863 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 864 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 865 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 866 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 867 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 868 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 869 
     | 
    
         
            +
                      }
         
     | 
| 
      
 870 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 871 
     | 
    
         
            +
                      params.store("userName", user_name)
         
     | 
| 
      
 872 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 873 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 874 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/#{user_name}/roles"
         
     | 
| 
      
 875 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 876 
     | 
    
         
            +
                      user = UserResponseBuilder.new()
         
     | 
| 
      
 877 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 878 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 879 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 880 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 881 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 882 
     | 
    
         
            +
                    end
         
     | 
| 
      
 883 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 884 
     | 
    
         
            +
                  end
         
     | 
| 
      
 885 
     | 
    
         
            +
             
     | 
| 
      
 886 
     | 
    
         
            +
                  #
         
     | 
| 
      
 887 
     | 
    
         
            +
                  # Get Users based on Role
         
     | 
| 
      
 888 
     | 
    
         
            +
                  #
         
     | 
| 
      
 889 
     | 
    
         
            +
                  # @param role
         
     | 
| 
      
 890 
     | 
    
         
            +
                  #      - Role which should be unique for the App
         
     | 
| 
      
 891 
     | 
    
         
            +
                  #
         
     | 
| 
      
 892 
     | 
    
         
            +
                  # @return Returns User Object
         
     | 
| 
      
 893 
     | 
    
         
            +
                  #
         
     | 
| 
      
 894 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 895 
     | 
    
         
            +
                  #
         
     | 
| 
      
 896 
     | 
    
         
            +
             
     | 
| 
      
 897 
     | 
    
         
            +
                  def get_users_by_role(role)
         
     | 
| 
      
 898 
     | 
    
         
            +
                    puts "get_users_by_role Called "
         
     | 
| 
      
 899 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 900 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 901 
     | 
    
         
            +
                    userList, util = [], Util.new
         
     | 
| 
      
 902 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(role, "Role")
         
     | 
| 
      
 903 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 904 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 905 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 906 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 907 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 908 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 909 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 910 
     | 
    
         
            +
                      }
         
     | 
| 
      
 911 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 912 
     | 
    
         
            +
                      params.store("role", role)
         
     | 
| 
      
 913 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 914 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 915 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/role/#{role}"
         
     | 
| 
      
 916 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 917 
     | 
    
         
            +
                      user = UserResponseBuilder.new()
         
     | 
| 
      
 918 
     | 
    
         
            +
                      userList = user.buildArrayResponse(response)
         
     | 
| 
      
 919 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 920 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 921 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 922 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 923 
     | 
    
         
            +
                    end
         
     | 
| 
      
 924 
     | 
    
         
            +
                    return userList
         
     | 
| 
      
 925 
     | 
    
         
            +
                  end
         
     | 
| 
      
 926 
     | 
    
         
            +
             
     | 
| 
      
 927 
     | 
    
         
            +
                  #
         
     | 
| 
      
 928 
     | 
    
         
            +
                  # Revokes the specified role from the user.
         
     | 
| 
      
 929 
     | 
    
         
            +
                  #
         
     | 
| 
      
 930 
     | 
    
         
            +
                  # @param userName
         
     | 
| 
      
 931 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 932 
     | 
    
         
            +
                  #
         
     | 
| 
      
 933 
     | 
    
         
            +
                  # @return App42Response Object if user deleted successfully
         
     | 
| 
      
 934 
     | 
    
         
            +
                  #
         
     | 
| 
      
 935 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 936 
     | 
    
         
            +
                  #
         
     | 
| 
      
 937 
     | 
    
         
            +
             
     | 
| 
      
 938 
     | 
    
         
            +
                  def revoke_role(user_name, role)
         
     | 
| 
      
 939 
     | 
    
         
            +
                    puts "revoke_role Called "
         
     | 
| 
      
 940 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 941 
     | 
    
         
            +
                    response, responseObj, util = nil, App42Response.new, Util.new
         
     | 
| 
      
 942 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 943 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(role, "Role")
         
     | 
| 
      
 944 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 945 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 946 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 947 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 948 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 949 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 950 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 951 
     | 
    
         
            +
                      }
         
     | 
| 
      
 952 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 953 
     | 
    
         
            +
                      params.store("role", role)
         
     | 
| 
      
 954 
     | 
    
         
            +
                      params.store("userName", user_name)
         
     | 
| 
      
 955 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 956 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 957 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/#{user_name}/revoke/#{role}"
         
     | 
| 
      
 958 
     | 
    
         
            +
                      response = connection.delete(signature, resource_url, query_params)
         
     | 
| 
      
 959 
     | 
    
         
            +
                      responseObj.strResponse=(response)
         
     | 
| 
      
 960 
     | 
    
         
            +
                      responseObj.isResponseSuccess=(true)
         
     | 
| 
      
 961 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 962 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 963 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 964 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 965 
     | 
    
         
            +
                    end
         
     | 
| 
      
 966 
     | 
    
         
            +
                    return responseObj
         
     | 
| 
      
 967 
     | 
    
         
            +
                  end
         
     | 
| 
      
 968 
     | 
    
         
            +
             
     | 
| 
      
 969 
     | 
    
         
            +
                  #
         
     | 
| 
      
 970 
     | 
    
         
            +
                  # Revokes the specified role from the user.
         
     | 
| 
      
 971 
     | 
    
         
            +
                  #
         
     | 
| 
      
 972 
     | 
    
         
            +
                  # @param userName
         
     | 
| 
      
 973 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 974 
     | 
    
         
            +
                  #
         
     | 
| 
      
 975 
     | 
    
         
            +
                  # @return App42Response Object if user deleted successfully
         
     | 
| 
      
 976 
     | 
    
         
            +
                  #
         
     | 
| 
      
 977 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 978 
     | 
    
         
            +
                  #
         
     | 
| 
      
 979 
     | 
    
         
            +
             
     | 
| 
      
 980 
     | 
    
         
            +
                  def revoke_all_roles(user_name)
         
     | 
| 
      
 981 
     | 
    
         
            +
                    puts "revoke_all_roles Called "
         
     | 
| 
      
 982 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 983 
     | 
    
         
            +
                    response, response_obj, util = nil, App42Response.new, Util.new
         
     | 
| 
      
 984 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 985 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 986 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 987 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 988 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 989 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 990 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 991 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 992 
     | 
    
         
            +
                      }
         
     | 
| 
      
 993 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 994 
     | 
    
         
            +
                      params.store("userName", user_name)
         
     | 
| 
      
 995 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 996 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 997 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/#{user_name}/revoke"
         
     | 
| 
      
 998 
     | 
    
         
            +
                      response = connection.delete(signature, resource_url, query_params)
         
     | 
| 
      
 999 
     | 
    
         
            +
                      response_obj.strResponse=(response)
         
     | 
| 
      
 1000 
     | 
    
         
            +
                      response_obj.isResponseSuccess=(true)
         
     | 
| 
      
 1001 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 1002 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 1003 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 1004 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 1005 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1006 
     | 
    
         
            +
                    return response_obj
         
     | 
| 
      
 1007 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1008 
     | 
    
         
            +
             
     | 
| 
      
 1009 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1010 
     | 
    
         
            +
                  # Get Users based on Profile Data
         
     | 
| 
      
 1011 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1012 
     | 
    
         
            +
                  # @param profileData
         
     | 
| 
      
 1013 
     | 
    
         
            +
                  #      - Profile Data key/value for which Users need to be retrieved
         
     | 
| 
      
 1014 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1015 
     | 
    
         
            +
                  # @return Returns Arraylist of User Object for that particular role
         
     | 
| 
      
 1016 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1017 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 1018 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1019 
     | 
    
         
            +
             
     | 
| 
      
 1020 
     | 
    
         
            +
                  def get_users_by_profile_data(profileData)
         
     | 
| 
      
 1021 
     | 
    
         
            +
                    puts "get_users_by_profile_data Called "
         
     | 
| 
      
 1022 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 1023 
     | 
    
         
            +
                    response = nil
         
     | 
| 
      
 1024 
     | 
    
         
            +
                    userList = nil
         
     | 
| 
      
 1025 
     | 
    
         
            +
                    userList = []
         
     | 
| 
      
 1026 
     | 
    
         
            +
                    util = Util.new
         
     | 
| 
      
 1027 
     | 
    
         
            +
                    parameters = ""
         
     | 
| 
      
 1028 
     | 
    
         
            +
                    parameters = fill_params_with_profile_data(profileData)
         
     | 
| 
      
 1029 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 1030 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 1031 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 1032 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 1033 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 1034 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 1035 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 1036 
     | 
    
         
            +
                      }
         
     | 
| 
      
 1037 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 1038 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 1039 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 1040 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/profile/#{parameters}"
         
     | 
| 
      
 1041 
     | 
    
         
            +
                      response = connection.get(signature, resource_url, query_params)
         
     | 
| 
      
 1042 
     | 
    
         
            +
                      user = UserResponseBuilder.new()
         
     | 
| 
      
 1043 
     | 
    
         
            +
                      userList = user.buildArrayResponse(response)
         
     | 
| 
      
 1044 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 1045 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 1046 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 1047 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 1048 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1049 
     | 
    
         
            +
                    return userList
         
     | 
| 
      
 1050 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1051 
     | 
    
         
            +
             
     | 
| 
      
 1052 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1053 
     | 
    
         
            +
                  # Updates the User based on userName. Note: Only email can be updated.
         
     | 
| 
      
 1054 
     | 
    
         
            +
                  # Username cannot be updated.
         
     | 
| 
      
 1055 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1056 
     | 
    
         
            +
                  # @param uName
         
     | 
| 
      
 1057 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 1058 
     | 
    
         
            +
                  # @param emailAddress
         
     | 
| 
      
 1059 
     | 
    
         
            +
                  #      - Email address of the user
         
     | 
| 
      
 1060 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1061 
     | 
    
         
            +
                  # @return updated User Object
         
     | 
| 
      
 1062 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1063 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 1064 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1065 
     | 
    
         
            +
             
     | 
| 
      
 1066 
     | 
    
         
            +
                  def reset_user_password(user_name,password)
         
     | 
| 
      
 1067 
     | 
    
         
            +
                    puts "resetUserPassword Called "
         
     | 
| 
      
 1068 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 1069 
     | 
    
         
            +
                    response = nil
         
     | 
| 
      
 1070 
     | 
    
         
            +
                    responseObj, util = App42Response.new, Util.new
         
     | 
| 
      
 1071 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 1072 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(password, "password")
         
     | 
| 
      
 1073 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 1074 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 1075 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 1076 
     | 
    
         
            +
                        "userName" => user_name,
         
     | 
| 
      
 1077 
     | 
    
         
            +
                        "password" => password
         
     | 
| 
      
 1078 
     | 
    
         
            +
                        }}}.to_json
         
     | 
| 
      
 1079 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 1080 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 1081 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 1082 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 1083 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 1084 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 1085 
     | 
    
         
            +
                      }
         
     | 
| 
      
 1086 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 1087 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 1088 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 1089 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 1090 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/resetUserPassword"
         
     | 
| 
      
 1091 
     | 
    
         
            +
                      response = connection.put(signature, resource_url, query_params, body)
         
     | 
| 
      
 1092 
     | 
    
         
            +
                      responseObj.strResponse=(response)
         
     | 
| 
      
 1093 
     | 
    
         
            +
                      responseObj.isResponseSuccess=(true)
         
     | 
| 
      
 1094 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 1095 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 1096 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 1097 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 1098 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1099 
     | 
    
         
            +
                    return responseObj
         
     | 
| 
      
 1100 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1101 
     | 
    
         
            +
             
     | 
| 
      
 1102 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1103 
     | 
    
         
            +
                  # Add Role for the App
         
     | 
| 
      
 1104 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1105 
     | 
    
         
            +
                  # @param uName
         
     | 
| 
      
 1106 
     | 
    
         
            +
                  #      - UserName which should be unique for the App
         
     | 
| 
      
 1107 
     | 
    
         
            +
                  # @param roleList
         
     | 
| 
      
 1108 
     | 
    
         
            +
                  #      - list of roles to be added to User
         
     | 
| 
      
 1109 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1110 
     | 
    
         
            +
                  # @return The created User Object.
         
     | 
| 
      
 1111 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1112 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 1113 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1114 
     | 
    
         
            +
             
     | 
| 
      
 1115 
     | 
    
         
            +
                  def assign_roles(user_name, role_list)
         
     | 
| 
      
 1116 
     | 
    
         
            +
                    puts "assignRoles Called "
         
     | 
| 
      
 1117 
     | 
    
         
            +
                    puts "Base url #{@base_url}"
         
     | 
| 
      
 1118 
     | 
    
         
            +
                    response, usr = nil
         
     | 
| 
      
 1119 
     | 
    
         
            +
                    usr, util = User.new, Util.new
         
     | 
| 
      
 1120 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(user_name, "UserName")
         
     | 
| 
      
 1121 
     | 
    
         
            +
                    util.throwExceptionIfNullOrBlank(role_list, "RoleList")
         
     | 
| 
      
 1122 
     | 
    
         
            +
                    raise App42Exception.new("RoleList cannot be empty.Please assign at least one role") if role_list.size == 0
         
     | 
| 
      
 1123 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 1124 
     | 
    
         
            +
                      connection = App42::Connection::RESTConnection.new(@base_url)
         
     | 
| 
      
 1125 
     | 
    
         
            +
                      body = {'app42' => {"user"=> {
         
     | 
| 
      
 1126 
     | 
    
         
            +
                        "userName" => user_name, "roles" => {
         
     | 
| 
      
 1127 
     | 
    
         
            +
                        "role" => role_list
         
     | 
| 
      
 1128 
     | 
    
         
            +
                        }}}}.to_json
         
     | 
| 
      
 1129 
     | 
    
         
            +
                      puts "Body #{body}"
         
     | 
| 
      
 1130 
     | 
    
         
            +
                      query_params = {}
         
     | 
| 
      
 1131 
     | 
    
         
            +
                      params = {
         
     | 
| 
      
 1132 
     | 
    
         
            +
                        'apiKey'=> @api_key,
         
     | 
| 
      
 1133 
     | 
    
         
            +
                        'version' => @version,
         
     | 
| 
      
 1134 
     | 
    
         
            +
                        'timeStamp' => util.get_timestamp_utc,
         
     | 
| 
      
 1135 
     | 
    
         
            +
                      }
         
     | 
| 
      
 1136 
     | 
    
         
            +
                      query_params = params.clone
         
     | 
| 
      
 1137 
     | 
    
         
            +
                      params.store("body", body)
         
     | 
| 
      
 1138 
     | 
    
         
            +
                      puts query_params
         
     | 
| 
      
 1139 
     | 
    
         
            +
                      signature = util.sign(@secret_key, params)
         
     | 
| 
      
 1140 
     | 
    
         
            +
                      resource_url = "#{@version}/#{@resource}/assignrole"
         
     | 
| 
      
 1141 
     | 
    
         
            +
                      response = connection.post(signature, resource_url, query_params, body)
         
     | 
| 
      
 1142 
     | 
    
         
            +
                      user = UserResponseBuilder.new()
         
     | 
| 
      
 1143 
     | 
    
         
            +
                      usr = user.buildResponse(response)
         
     | 
| 
      
 1144 
     | 
    
         
            +
                    rescue  App42Exception =>e
         
     | 
| 
      
 1145 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 1146 
     | 
    
         
            +
                    rescue  Exception => e
         
     | 
| 
      
 1147 
     | 
    
         
            +
                      raise App42Exception.new(e)
         
     | 
| 
      
 1148 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1149 
     | 
    
         
            +
                    return usr
         
     | 
| 
      
 1150 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1151 
     | 
    
         
            +
             
     | 
| 
      
 1152 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1153 
     | 
    
         
            +
                  # Builds a Parameter string from the profileData.
         
     | 
| 
      
 1154 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1155 
     | 
    
         
            +
                  # @param profileData
         
     | 
| 
      
 1156 
     | 
    
         
            +
                  #      - User.Profile object that contains User's Profile information
         
     | 
| 
      
 1157 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1158 
     | 
    
         
            +
                  # @return String Object which contains the parameter string.
         
     | 
| 
      
 1159 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1160 
     | 
    
         
            +
                  # @raise App42Exception
         
     | 
| 
      
 1161 
     | 
    
         
            +
                  #
         
     | 
| 
      
 1162 
     | 
    
         
            +
             
     | 
| 
      
 1163 
     | 
    
         
            +
                  def fill_params_with_profile_data(profileData)
         
     | 
| 
      
 1164 
     | 
    
         
            +
                    profileDataCond = ""
         
     | 
| 
      
 1165 
     | 
    
         
            +
                    if profileData.city != nil && !profileData.city != ""
         
     | 
| 
      
 1166 
     | 
    
         
            +
                      profileDataCond += "city:"+ profileData.city()+"!"
         
     | 
| 
      
 1167 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1168 
     | 
    
         
            +
                    if profileData.country != nil && !profileData.country != ""
         
     | 
| 
      
 1169 
     | 
    
         
            +
                      profileDataCond += "country:"+ profileData.country()+"!"
         
     | 
| 
      
 1170 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1171 
     | 
    
         
            +
                    if profileData.dateOfBirth != nil && !profileData.dateOfBirth != ""
         
     | 
| 
      
 1172 
     | 
    
         
            +
                      profileDataCond += "date_of_birth:"+ profileData.dateOfBirth()+"!"
         
     | 
| 
      
 1173 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1174 
     | 
    
         
            +
                    if profileData.firstName != nil && !profileData.firstName != ""
         
     | 
| 
      
 1175 
     | 
    
         
            +
                      profileDataCond += "first_name:"+ profileData.firstName()+"!"
         
     | 
| 
      
 1176 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1177 
     | 
    
         
            +
                    if profileData.lastName != nil && !profileData.lastName != ""
         
     | 
| 
      
 1178 
     | 
    
         
            +
                      profileDataCond += "last_name:"+ profileData.lastName()+"!"
         
     | 
| 
      
 1179 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1180 
     | 
    
         
            +
                    if profileData.homeLandLine != nil && !profileData.homeLandLine != ""
         
     | 
| 
      
 1181 
     | 
    
         
            +
                      profileDataCond += "home_land_line:"+ profileData.homeLandLine()+"!"
         
     | 
| 
      
 1182 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1183 
     | 
    
         
            +
                    if profileData.line1 != nil && !profileData.line1 != ""
         
     | 
| 
      
 1184 
     | 
    
         
            +
                      profileDataCond += "line1:"+ profileData.line1()+"!"
         
     | 
| 
      
 1185 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1186 
     | 
    
         
            +
                    if profileData.line2() != nil && !profileData.line2 != ""
         
     | 
| 
      
 1187 
     | 
    
         
            +
                      profileDataCond += "line2:"+ profileData.line2()+"!"
         
     | 
| 
      
 1188 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1189 
     | 
    
         
            +
                    if profileData.mobile != nil && !profileData.mobile != ""
         
     | 
| 
      
 1190 
     | 
    
         
            +
                      profileDataCond += "mobile:"+ profileData.mobile()+"!"
         
     | 
| 
      
 1191 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1192 
     | 
    
         
            +
                    if profileData.officeLandLine() != nil && !profileData.officeLandLine.equals("")
         
     | 
| 
      
 1193 
     | 
    
         
            +
                      profileDataCond += "office_land_line:"+ profileData.officeLandLine()+"!"
         
     | 
| 
      
 1194 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1195 
     | 
    
         
            +
                    if profileData.pincode != nil && !profileData.pincode != ""
         
     | 
| 
      
 1196 
     | 
    
         
            +
                      profileDataCond += "pincode:"+ profileData.pincode()+"!"
         
     | 
| 
      
 1197 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1198 
     | 
    
         
            +
                    if profileData.sex != nil && !profileData.sex != ""
         
     | 
| 
      
 1199 
     | 
    
         
            +
                      profileDataCond += "sex:"+ profileData.sex()+"!"
         
     | 
| 
      
 1200 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1201 
     | 
    
         
            +
                    if profileData.state != nil && !profileData.state != ""
         
     | 
| 
      
 1202 
     | 
    
         
            +
                      profileDataCond += "state:"+ profileData.state()+"!"
         
     | 
| 
      
 1203 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1204 
     | 
    
         
            +
                    return profileDataCond
         
     | 
| 
      
 1205 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1206 
     | 
    
         
            +
             
     | 
| 
      
 1207 
     | 
    
         
            +
                end
         
     | 
| 
      
 1208 
     | 
    
         
            +
              end
         
     | 
| 
      
 1209 
     | 
    
         
            +
            end
         
     |