Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
[sku] append sku token to offline download requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jan 17, 2020
1 parent 369c41a commit 9efe6a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public class HttpRequestUrl {

private static final StringBuilder requestBuilder = new StringBuilder();

private HttpRequestUrl() {
}

Expand All @@ -22,20 +24,20 @@ private HttpRequestUrl() {
* @return the adapted resource url
*/
public static String buildResourceUrl(@NonNull String host, String resourceUrl, int querySize, boolean offline) {
requestBuilder.delete(0, requestBuilder.length());
requestBuilder.append(resourceUrl);
if (isValidMapboxEndpoint(host)) {
if (querySize == 0) {
resourceUrl = resourceUrl + "?";
requestBuilder.append("?");
} else {
resourceUrl = resourceUrl + "&";
requestBuilder.append("&");
}
// Only add SKU token to requests not tagged as "offline" usage.
if (offline) {
resourceUrl = resourceUrl + "offline=true";
} else {
resourceUrl = resourceUrl + "sku=" + Mapbox.getSkuToken();
requestBuilder.append("offline=true&");
}
requestBuilder.append("sku=").append(Mapbox.getSkuToken());
}
return resourceUrl;
return requestBuilder.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class HttpRequestUrlTest {

@Test
fun testOfflineFlagMapboxCom() {
val expected = "http://mapbox.com/path/of/no/return.pbf?offline=true"
val expected = "http://mapbox.com/path/of/no/return.pbf?offline=true&sku=foobar"
val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, true)
assertEquals(expected, actual)
}

@Test
fun testOfflineFlagMapboxCn() {
val expected = "http://mapbox.cn/path/of/no/return.pbf?offline=true"
val expected = "http://mapbox.cn/path/of/no/return.pbf?offline=true&sku=foobar"
val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, true)
assertEquals(expected, actual)
}
Expand Down

0 comments on commit 9efe6a9

Please sign in to comment.