Beispiel #1
0
        private async Task <CommandRequestStatus> MonitorCommand(string monitoringUrl)
        {
            OuterCommandResponse commandResponse = null;

            do
            {
                System.Threading.Thread.Sleep(5 * 1000);
                var commandQueryResponse = await client.GetAsync(monitoringUrl);

                var commandQueryResponseStr = await commandQueryResponse.Content.ReadAsStringAsync();

                logger(commandQueryResponseStr);
                commandResponse = serializer.Deserialize <OuterCommandResponse>(commandQueryResponseStr);
            } while (commandResponse.commandResponse.status == "inProgress");

            if (commandResponse.commandResponse.status == "failure")
            {
                logger(commandResponse.commandResponse.body.error.description);

                return(CommandRequestStatus.GetFailed(commandResponse.commandResponse.body.error.description));
            }
            else
            {
                return(CommandRequestStatus.GetSuccessful());
            }
        }
Beispiel #2
0
        private async Task <CommandRequestStatus <DetailedVehialInfo> > LogInAndGetDetailedVehicalInfo()
        {
            var authObject = new DeviceAuth()
            {
                client_id  = ClientId,
                device_id  = DeviceId,
                grant_type = "password",
                username   = username,
                password   = password,
            };

            CreateHttClient();

            var loginResponse = await Login(authObject);

            if (loginResponse.Successful == false)
            {
                return(CommandRequestStatus <DetailedVehialInfo> .GetFailed(loginResponse.ErrorMessage));
            }

            logger("Getting vehicals...");
            var getResponse = await client.GetAsync("https://api.gm.com/api/v1/account/vehicles");

            var responseBody = await getResponse.Content.ReadAsStringAsync();

            var vehicals = serializer.Deserialize <VehicalList>(responseBody);

            var firstCar = vehicals.vehicles.vehicle.First();

            logger($"Getting detailed info on {firstCar.vin}");
            var vehicalDetailsReply = await client.GetAsync($"https://api.gm.com/api/v1/account/vehicles/{firstCar.vin}?includeCommands=true&includeFeatures=true&includeDealers=true&includeCarrierAccount=true");

            var vehicalDetailsString = await vehicalDetailsReply.Content.ReadAsStringAsync();

            var detailedVehicalInfo = serializer.Deserialize <DetailedVehialInfo>(vehicalDetailsString);

            foreach (var item in detailedVehicalInfo.vehicle.commands.command)
            {
                logger(item.name);
                logger(item.description);
            }

            return(CommandRequestStatus <DetailedVehialInfo> .GetSuccessful(detailedVehicalInfo));
        }