Пример #1
0
        ///// <summary>
        ///// Ping Datto's profile to see if we have a valid connection to the API
        ///// </summary>
        ///// <returns></returns>
        //[Command("api")]
        //public async Task ApiTest()
        //{
        //    Destiny d = user.Destiny;
        //    if (d == null)
        //    {
        //        Console.WriteLine("Fetching user character base details");
        //        await GetDestinyProfile(user, Types.Component.Characters);
        //        d = user.Destiny;
        //        if (d == null)
        //        {
        //            Console.WriteLine("Failed to load user destiny data");
        //            return;
        //        }
        //    }
        //    foreach (var (key, value) in d.Response.Characters.Data)
        //    {
        //        try
        //        {
        //            Console.WriteLine($"Fetching character data for {value.CharacterId}");
        //            var url = $"{BaseUrl}/{user.DestinyAccountType}/Profile/{user.DestinyId}/Character/{value.CharacterId}/?components={(int)component}";

        //            string[] content = await MakeApiCall(url);

        //            if (component == Types.Component.CharacterEquipment)
        //            {
        //                Console.WriteLine(content[0]);
        //                Console.WriteLine(content[1]);
        //            }

        //            dynamic r = JsonConvert.DeserializeObject(content[1]);
        //            try
        //            {
        //                //throws binding error here
        //                dynamic character = r.Response.character.data;
        //                Console.WriteLine($"Character {character.membershipId}");
        //                Datum currChar = Datum.FromJson(character);
        //                Console.WriteLine($"new character {currChar.CharacterId}, {currChar.ClassType}");
        //                if (!user.Destiny.Response.Characters.Data.ContainsKey(currChar.CharacterId))
        //                    user.Destiny.Response.Characters.Data.Add(currChar.CharacterId, currChar);
        //            }
        //            catch (Exception e)
        //            {
        //                Console.WriteLine(e);
        //            }

        //        }
        //        catch (Exception e)
        //        {
        //            Console.WriteLine(e);
        //            throw;
        //        }
        //    }
        //    var url = "https://www.bungie.net/Platform/Destiny2/SearchDestinyPlayer/-1/dattowatto/";
        //    var resp = await MakeApiCall(url);
        //    Console.WriteLine(resp[0]);
        //    Console.WriteLine(resp[1]);
        //}

        /// <summary>
        /// Get simple user data based on their battletag
        /// </summary>
        /// <param name="battletag"></param>
        /// <returns></returns>
        public static async Task <DestinyUser> GetDestinyUser(string battletag)
        {
            battletag = battletag.Replace("#", "%23");
            var url = $"{BaseUrl}/SearchDestinyPlayer/-1/{battletag}/";

            Console.WriteLine($"Requesting user data with {url}");
            var content = await MakeApiCall(url);

            dynamic obj = JsonConvert.DeserializeObject(content[1]);

            return(DestinyUser.FromJson(obj.Response[0]));
        }
Пример #2
0
        /// <summary>
        /// Get the full user profile based on the component param
        /// </summary>
        /// <param name="user"></param>
        /// <param name="component"></param>
        /// <returns></returns>
        public static async Task GetDestinyProfile(UserAccount user, Types.Component component)
        {
            Console.WriteLine($"Fetching profile data for {user.Destiny.DisplayName}");
            var url = $"{BaseUrl}/{user.Destiny.MembershipType}/Profile/{user.Destiny.MembershipId}/?components={(int) component}";

            string[] content = await MakeApiCall(url);

            Console.WriteLine($"Profile content {content[1]}");

            user.Destiny = DestinyUser.FromJson(content[1]);
            UserAccounts.SaveAccounts();
        }