示例#1
0
        public ProfileCharactersResponse GetProfileCharacters(ProfileCharactersRequest charactersRequest)
        {
            HttpRequestMessage request = new HttpRequestMessage();

            request.Method     = HttpMethod.Get;
            request.RequestUri = new Uri($"https://www.bungie.net/Platform/Destiny2/{charactersRequest.MembershipType}/Profile/{charactersRequest.DestinyProfileId}/?components=200");
            request.Headers.Add("X-API-KEY", config["Bungie:ApiKey"]);
            HttpResponseMessage response = httpClient.SendAsync(request).Result;

            if (response.IsSuccessStatusCode)
            {
                string json = response.Content.ReadAsStringAsync().Result;
                ProfileCharactersResponse charactersResponse = JsonConvert.DeserializeObject <ProfileCharactersResponse>(json);
                return(charactersResponse);
            }
            else if (response.StatusCode == HttpStatusCode.InternalServerError)
            {
                dynamic errorResponse = JObject.Parse(response.Content.ReadAsStringAsync().Result);
                throw new BungieApiException($"{errorResponse.ErrorStatus}: {errorResponse.Message}");
            }
            else
            {
                throw new BungieApiException($"{response.StatusCode}: {response.Content.ReadAsStringAsync().Result}");
            }
        }
示例#2
0
        private long GetMostRecentlyPlayedCharacterId(int destinyMembershipType, long destinyProfileId)
        {
            ProfileCharactersRequest  charactersRequest           = new ProfileCharactersRequest(destinyMembershipType, destinyProfileId);
            ProfileCharactersResponse charactersResponse          = bungieApiService.GetProfileCharacters(charactersRequest);
            DestinyCharacter          mostRecentlyPlayedCharacter = charactersResponse.Characters.Values.Aggregate((c1, c2) => c1.DateLastPlayed > c2.DateLastPlayed ? c1 : c2);
            long mostRecentlyPlayedCharacterId = mostRecentlyPlayedCharacter.CharacterId;

            return(mostRecentlyPlayedCharacterId);
        }