/// <summary>
        ///  returns an array of existing package files.
        /// </summary>
        public async Task <JArray> GetPackageList(ApiKeyModel keyParts)
        {
            var url = "Umbraco/Api/ProjectUpload/GetProjectFiles";

            try
            {
                using (var httpClient = GetClientBase(url, keyParts.Token, keyParts.MemberId, keyParts.ProjectId))
                {
                    var httpResponse = await httpClient.GetAsync(url);

                    if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        WriteError(Resources.Push_ApiKeyInvalid);
                        Environment.Exit(5); // ERROR_ACCESS_DENIED
                    }
                    else if (httpResponse.IsSuccessStatusCode)
                    {
                        // Get the JSON string content which gives us a list
                        // of current Umbraco Package .zips for this project
                        var apiResponse = await httpResponse.Content.ReadAsStringAsync();

                        return(JsonConvert.DeserializeObject <JArray>(apiResponse));
                    }
                }
            }
            catch (HttpRequestException ex)
            {
                throw ex;
            }

            return(null);
        }
        public async Task <string> GetCurrentPackageFileId(ApiKeyModel keyParts)
        {
            var url = "Umbraco/Api/ProjectUpload/GetCurrentPackageFileId";

            try
            {
                using (var httpClient = GetClientBase(url, keyParts.Token, keyParts.MemberId, keyParts.ProjectId))
                {
                    var httpResponse = await httpClient.GetAsync(url);

                    if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        WriteError(Resources.Push_ApiKeyInvalid);
                        Environment.Exit(5); // ERROR_ACCESS_DENIED
                    }

                    var apiResponse = await httpResponse.Content.ReadAsStringAsync();

                    return(apiResponse);
                }
            }
            catch (HttpRequestException ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// the API key has the format "packageId-memberId-apiToken", this helper method splits it in the three parts and returns a model with them all
        /// </summary>
        public ApiKeyModel SplitKey(string apiKey)
        {
            var keyParts = apiKey.Split('-');
            var keyModel = new ApiKeyModel();

            if (int.TryParse(keyParts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out int projectId))
            {
                keyModel.ProjectId = projectId;
            }

            if (int.TryParse(keyParts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out int memberId))
            {
                keyModel.MemberId = memberId;
            }

            keyModel.Token = keyParts[2];

            return(keyModel);
        }
        public async Task ArchivePackages(ApiKeyModel keyParts, IEnumerable <int> ids)
        {
            var url = "Umbraco/Api/ProjectUpload/ArchiveProjectFiles";

            try
            {
                using (var httpClient = GetClientBase(url, keyParts.Token, keyParts.MemberId, keyParts.ProjectId))
                {
                    var httpResponse = await httpClient.PostAsJsonAsync(url, ids);

                    if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        WriteError(Resources.Push_ApiKeyInvalid);
                        Environment.Exit(5); // ERROR_ACCESS_DENIED
                    }
                }
            }
            catch (HttpRequestException ex)
            {
                throw ex;
            }
        }