Пример #1
0
        public async Task TestUploadDeviceSubscriptionChanges()
        {
            var deviceId = "gPodder.NET-test";
            var testSubscriptionChanges = new SubscriptionChanges
            {
                Add = new List <string>()
                {
                    "https://2bears1cave.libsyn.com/rss",
                },
            };

            var updatedSubscriptions = await client.Subscriptions.UploadDeviceSubscriptionChanges(deviceId, testSubscriptionChanges);

            Assert.IsNotNull(updatedSubscriptions);
        }
Пример #2
0
        /// <summary>
        /// Upload changes to the subscriptions on the device to gPodder.
        /// </summary>
        /// <param name="deviceId">The device ID for the device.</param>
        /// <param name="subscriptionChanges">A <see cref="SubscriptionChanges"/> of the subscription changes for the device.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation. It will contain a <see cref="UpdatedDeviceSubscriptions"/> object if successful.</returns>
        public async Task <UpdatedDeviceSubscriptions> UploadDeviceSubscriptionChanges(string deviceId, SubscriptionChanges subscriptionChanges)
        {
            var subChangesString = JsonSerializer.Serialize(subscriptionChanges);
            var httpContent      = new StringContent(subChangesString);
            var response         = await Utilities.HttpClient.PostAsync(
                new Uri($"{GPodderConfig.BaseApiUrl}/api/2/subscriptions/{this.username}/{deviceId}.json"),
                httpContent);

            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (HttpRequestException)
            {
                switch (response.StatusCode)
                {
                case HttpStatusCode.BadRequest:
                    throw new UpdateSubscriptionConflictException();

                default:
                    throw;
                }
            }

            var contentStream = await response.Content.ReadAsStreamAsync();

            return(await JsonSerializer.DeserializeAsync <UpdatedDeviceSubscriptions>(contentStream));
        }