예제 #1
0
        public async Task DeleteSubscriptionAsync(APICollectionType collection, string uniqueSubscriptionId, string subscriberId = null)
        {
            var collectionString = string.Empty;

            if (collection == APICollectionType.user)
            {
                collectionString = string.Empty;
            }
            else
            {
                collectionString = collection.ToString() + @"/";
            }

            string url     = "/1/user/-/{2}apiSubscriptions/{1}.json";
            string apiCall = FitbitClientHelperExtensions.ToFullUrl(url, args: new object[] { uniqueSubscriptionId, collectionString });

            if (subscriberId != null)
            {
                HttpClient.DefaultRequestHeaders.Add(Constants.Headers.XFitbitSubscriberId, subscriberId);
            }

            var response = await HttpClient.DeleteAsync(apiCall);

            if (response.StatusCode != HttpStatusCode.NoContent)
            {
                var errors = new JsonDotNetSerializer().ParseErrors(await response.Content.ReadAsStringAsync());
                throw new FitbitException("Unexpected response message", errors);
            }
        }
예제 #2
0
        private string FormatKey(APICollectionType apiCollectionType, string format)
        {
            string strValue = apiCollectionType == APICollectionType.user ? string.Empty : apiCollectionType.ToString();

            return(string.IsNullOrWhiteSpace(strValue) ? strValue : string.Format(format, strValue));
        }