Example #1
0
        public async Task <MaybeResult <bool, GenericErrorResult> > RegisterPushNotifications(Guid id, PushRegistrationRequest pushRegistration)
        {
            var response = await PostAsJsonAsync($"player/{id.ToString("N")}/push?{GetFunctionCode()}", pushRegistration);

            if (!response.IsSuccessStatusCode)
            {
                Debug.WriteLine($"Failed to register push notifications.");
                return(NetworkMaybeResult.Failure <bool>(response.StatusCode.ToErrorCode()));
            }

            return(NetworkMaybeResult.Success(true));
        }
Example #2
0
        public async Task <MaybeResult <Player, GenericErrorResult> > CreatePlayer(Player player)
        {
            var response = await PostAsJsonAsync($"player?{GetFunctionCode()}", player);

            if (!response.IsSuccessStatusCode)
            {
                Debug.WriteLine($"CreatePlayer failed: HTTP {response.StatusCode}, {await response.Content.ReadAsStringAsync()}");
                return(NetworkMaybeResult.Failure <Player>(response.StatusCode.ToErrorCode()));
            }

            var createdPlayer = JsonConvert.DeserializeObject <Player>(await response.Content.ReadAsStringAsync());

            return(NetworkMaybeResult.Success(createdPlayer));
        }
Example #3
0
        public async Task <MaybeResult <Player, GenericErrorResult> > GetPlayer(Guid playerId)
        {
            var response = await _httpClient.GetAsync($"player/{playerId.ToString("N")}?{GetFunctionCode()}");

            if (!response.IsSuccessStatusCode)
            {
                Debug.WriteLine($"GetPlayer failed: HTTP {response.StatusCode}: {await response.Content.ReadAsStringAsync()}");
                return(NetworkMaybeResult.Failure <Player>(response.StatusCode.ToErrorCode()));
            }

            var player = JsonConvert.DeserializeObject <Player>(await response.Content.ReadAsStringAsync());

            return(NetworkMaybeResult.Success(player));
        }
Example #4
0
        public async Task <MaybeResult <List <Question>, GenericErrorResult> > GetPlayerQuestions(Guid id)
        {
            var response = await _httpClient.GetAsync($"player/{id.ToString("N")}/questions?{GetFunctionCode()}");

            if (!response.IsSuccessStatusCode)
            {
                Debug.WriteLine($"GetPlayerQuestions for {id} failed: HTTP {response.StatusCode}, {await response.Content.ReadAsStringAsync()}");
                return(NetworkMaybeResult.Failure <List <Question> >(response.StatusCode.ToErrorCode()));
            }

            var questionsList = JsonConvert.DeserializeObject <List <Question> >(await response.Content.ReadAsStringAsync())
                                .OrderBy(x => x.SequenceNumber)
                                .ToList();

            return(NetworkMaybeResult.Success(questionsList));
        }
Example #5
0
        public async Task <MaybeResult <PlayerProfile, GenericErrorResult> > GetPlayerProfile(Guid playerId)
        {
            var getPlayerTask     = GetPlayer(playerId);
            var getquestionsTasks = GetPlayerQuestions(playerId);
            await Task.WhenAll(getPlayerTask, getquestionsTasks);

            if (getPlayerTask.Result.IsError || getquestionsTasks.Result.IsError)
            {
                return(NetworkMaybeResult.Failure <PlayerProfile>(GenericErrorResult.NotFound));
            }

            PlayerProfile profile = new PlayerProfile
            {
                PlayerInfo = getPlayerTask.Result.Unwrap(),
                Questions  = getquestionsTasks.Result.Unwrap()
            };

            return(NetworkMaybeResult.Success(profile));
        }