Example #1
0
        /// <summary>
        /// Retrieves the URL of manage, account settings and user profile page.
        /// </summary>
        /// <param name="userId">The user identifier, as returned by the user creation API or retrieved from the API to fetch users. To get the details for the token owner, UserId can be replaced by \&quot;me\&quot; without quotes.</param>
        /// <param name="userViewInfo">Name of the required view and its desired configuration.</param>
        /// <param name="xApiUser">The userId or email of API caller using the account or group token in the format &lt;b&gt;userid:{userId} OR email:{email}.&lt;/b&gt; If it is not specified, then the caller is inferred from the token.</param>
        /// <param name="xOnBehalfOfUser">The userId or email in the format &lt;b&gt;userid:{userId} OR email:{email}.&lt;/b&gt; of the user that has shared his/her account</param>
        /// <returns>UserViewResponse</returns>
        public UserViewResponse GetUserViews(string userId, UserViewInfo userViewInfo, string xApiUser = null, string xOnBehalfOfUser = null)
        {
            // verify the required parameter 'authorization' is set


            // verify the required parameter 'userId' is set
            if (userId == null)
            {
                throw new ApiException(400, "Missing required parameter 'userId' when calling GetUserViews");
            }

            // verify the required parameter 'userViewInfo' is set
            if (userViewInfo == null)
            {
                throw new ApiException(400, "Missing required parameter 'userViewInfo' when calling GetUserViews");
            }


            var path = "/users/{userId}/views";

            path = path.Replace("{format}", "json");
            path = path.Replace("{" + "userId" + "}", ApiClient.ParameterToString(userId));

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;


            if (xApiUser != null)
            {
                headerParams.Add("x-api-user", ApiClient.ParameterToString(xApiUser));                   // header parameter
            }
            if (xOnBehalfOfUser != null)
            {
                headerParams.Add("x-on-behalf-of-user", ApiClient.ParameterToString(xOnBehalfOfUser)); // header parameter
            }
            postBody = ApiClient.Serialize(userViewInfo);                                              // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] { };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling GetUserViews: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling GetUserViews: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((UserViewResponse)ApiClient.Deserialize(response.Content, typeof(UserViewResponse), response.Headers));
        }
Example #2
0
 private void FillViewFields(User user, UserViewInfo userInfo, Tuple <long, long, long> userRanks)
 {
     userInfo.CompletedMissionIdsCount = user.CompletedMissionIds?.Count ?? 0;
     userInfo.FailedMissionIdsCount    = user.FailedMissionIds?.Count ?? 0;
     userInfo.FiveRepostsBadge         = user.VkRepostCount >= 5;
     userInfo.FiveSetsBadge            = user.CompletedMissionSetIds?.Count >= 5;
     userInfo.KindScaleBadge           = user.KindScaleHighMaxDays >= 5;
     userInfo.RatingGrowthBadge        = user.UpInRatingMaxDays >= 5;
     userInfo.ThreeFiveStarsBadge      = user.ThreeStarsMissionSpreeMaxCount >= 5;
     userInfo.GlobalRank  = userRanks.Item1;
     userInfo.CountryRank = userRanks.Item2;
     userInfo.CityRank    = userRanks.Item3;
 }
Example #3
0
        /// <summary>
        /// Gets user the by identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <UserViewInfo> GetById(string id)
        {
            var userViewInfo = new UserViewInfo();
            var user         = await _userService.GetUser(id);

            if (user == null)
            {
                return(null);
            }
            var userRanks = await _ratingService.GetUserRanks(user);

            user.CopyTo(userViewInfo);
            FillViewFields(user, userViewInfo, userRanks);
            return(userViewInfo);
        }