Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We now adhere to new subscription url format #166

Open
wants to merge 1 commit into
base: async-portable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Fitbit.Portable.Tests/AddSubscriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async void AddSubscription_ActivitiesEndPoint_WithoutSubscriberId()
Assert.AreEqual(0, message.Headers.Count());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/activities/apiSubscriptions/323-activities.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/activities/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.activities, "323");

Expand All @@ -93,7 +93,7 @@ public async void AddSubscription_ActivitiesEndPoint_WithSubscriberId()
Assert.AreEqual(SubScriberId, headerValues.First());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/activities/apiSubscriptions/323-activities.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/activities/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.activities, "323", SubScriberId);

Expand All @@ -109,7 +109,7 @@ public async void AddSubscription_BodyEndPoint_WithoutSubscriberId()
Assert.AreEqual(0, message.Headers.Count());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/body/apiSubscriptions/323-body.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/body/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.body, "323");

Expand All @@ -131,7 +131,7 @@ public async void AddSubscription_BodyEndPoint_WithSubscriberId()
Assert.AreEqual(SubScriberId, headerValues.First());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/body/apiSubscriptions/323-body.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/body/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.body, "323", SubScriberId);

Expand All @@ -147,7 +147,7 @@ public async void AddSubscription_FoodEndPoint_WithoutSubscriberId()
Assert.AreEqual(0, message.Headers.Count());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/foods/apiSubscriptions/323-foods.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/foods/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.foods, "323");

Expand All @@ -169,7 +169,7 @@ public async void AddSubscription_FoodEndPoint_WithSubscriberId()
Assert.AreEqual(SubScriberId, headerValues.First());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/foods/apiSubscriptions/323-foods.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/foods/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.foods, "323", SubScriberId);

Expand All @@ -185,7 +185,7 @@ public async void AddSubscription_MealsEndPoint_WithoutSubscriberId()
Assert.AreEqual(0, message.Headers.Count());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/meals/apiSubscriptions/323-meals.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/meals/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.meals, "323");

Expand All @@ -207,7 +207,7 @@ public async void AddSubscription_MealsEndPoint_WithSubscriberId()
Assert.AreEqual(SubScriberId, headerValues.First());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/meals/apiSubscriptions/323-meals.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/meals/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.meals, "323", SubScriberId);

Expand All @@ -223,7 +223,7 @@ public async void AddSubscription_SleepEndPoint_WithoutSubscriberId()
Assert.AreEqual(0, message.Headers.Count());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/sleep/apiSubscriptions/323-sleep.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/sleep/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.sleep, "323");

Expand All @@ -245,7 +245,7 @@ public async void AddSubscription_SleepEndPoint_WithSubscriberId()
Assert.AreEqual(SubScriberId, headerValues.First());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/sleep/apiSubscriptions/323-sleep.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/sleep/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.sleep, "323", SubScriberId);

Expand All @@ -261,7 +261,7 @@ public async void AddSubscription_WeightEndPoint_WithoutSubscriberId()
Assert.AreEqual(0, message.Headers.Count());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/weight/apiSubscriptions/323-weight.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/weight/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.weight, "323");

Expand All @@ -283,7 +283,7 @@ public async void AddSubscription_WeightEndPoint_WithSubscriberId()
Assert.AreEqual(SubScriberId, headerValues.First());
};

var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/weight/apiSubscriptions/323-weight.json", HttpMethod.Post, additionalChecks);
var fitbitClient = SetupFitbitClient("AddSubscriptionResponse.json", "https://api.fitbit.com/1/user/-/weight/apiSubscriptions/323.json", HttpMethod.Post, additionalChecks);

var response = await fitbitClient.AddSubscriptionAsync(APICollectionType.weight, "323", SubScriberId);

Expand Down
9 changes: 6 additions & 3 deletions Fitbit.Portable/FitbitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,14 @@ public async Task<List<ApiSubscription>> GetSubscriptionsAsync()
/// <returns></returns>
public async Task<ApiSubscription> AddSubscriptionAsync(APICollectionType apiCollectionType, string uniqueSubscriptionId, string subscriberId = default(string))
{
//This function is smart enough to know when to return an empty string (for apiCollectionType.user) or the proper collection type suffixed by a slash
string path = FormatKey(apiCollectionType, Constants.Formatting.TrailingSlash);
string resource = FormatKey(apiCollectionType, Constants.Formatting.LeadingDash);

string url = "/1/user/-/{1}apiSubscriptions/{3}{2}.json";
string apiCall = FitbitClientHelperExtensions.ToFullUrl(url, args: new object[] {path, resource, uniqueSubscriptionId});
//sometimes {path} will be an empty string but when it is not, it will have a slash suffix is in foods/apiSubscriptions
string url = $"/1/user/-/{path}apiSubscriptions/{uniqueSubscriptionId}.json";

//TODO:
string apiCall = FitbitClientHelperExtensions.ToFullUrl(url, args: new object[] {path});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The construction of the url and then passing it through to the FitbitClientHelperExtensions doesn't look right passing in "path" again as there is no string formatting to use it.

if (!string.IsNullOrWhiteSpace(subscriberId))
{
HttpClient.DefaultRequestHeaders.Add(Constants.Headers.XFitbitSubscriberId, subscriberId);
Expand Down