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

add skuToken library and logic #1367

Merged
merged 9 commits into from
Sep 13, 2019
Merged
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ public class CachingWebFileSource : IFileSource, IDisposable
private bool _disposed;
private List<ICache> _caches = new List<ICache>();
private string _accessToken;
private Func<string> _getMapsSkuToken;
private bool _autoRefreshCache;


public CachingWebFileSource(string accessToken, bool autoRefreshCache)
public CachingWebFileSource(string accessToken, Func<string> getMapsSkuToken, bool autoRefreshCache)
{
#if MAPBOX_DEBUG_CACHE
_className = this.GetType().Name;
#endif
_accessToken = accessToken;
_getMapsSkuToken = getMapsSkuToken;
_autoRefreshCache = autoRefreshCache;
}

Expand Down Expand Up @@ -138,13 +140,14 @@ string uri
if (!string.IsNullOrEmpty(_accessToken))
{
string accessTokenQuery = "access_token=" + _accessToken;
string mapsSkuToken = "sku=" + _getMapsSkuToken();
if (uriBuilder.Query != null && uriBuilder.Query.Length > 1)
{
uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + accessTokenQuery;
uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + accessTokenQuery + "&" + mapsSkuToken;
}
else
{
uriBuilder.Query = accessTokenQuery;
uriBuilder.Query = accessTokenQuery + "&" + mapsSkuToken;
}
}
string finalUrl = uriBuilder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// </copyright>
//-----------------------------------------------------------------------

using Mapbox.Unity;

namespace Mapbox.Platform
{
using Mapbox.Map;
Expand Down Expand Up @@ -39,7 +41,7 @@ namespace Mapbox.Platform
public sealed class FileSource : IFileSource
{


private Func<string> _getMapsSkuToken;
private readonly Dictionary<IAsyncRequest, int> _requests = new Dictionary<IAsyncRequest, int>();
private readonly string _accessToken;
private readonly object _lock = new object();
Expand All @@ -54,8 +56,9 @@ public sealed class FileSource : IFileSource
#pragma warning restore 0414


public FileSource(string acessToken = null)
public FileSource(Func<string> getMapsSkuToken, string acessToken = null)
{
_getMapsSkuToken = getMapsSkuToken;
if (string.IsNullOrEmpty(acessToken))
{
_accessToken = Environment.GetEnvironmentVariable("MAPBOX_ACCESS_TOKEN");
Expand Down Expand Up @@ -86,13 +89,14 @@ string url
{
var uriBuilder = new UriBuilder(url);
string accessTokenQuery = "access_token=" + _accessToken;
string skuToken = "sku=" + _getMapsSkuToken();
if (uriBuilder.Query != null && uriBuilder.Query.Length > 1)
{
uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + accessTokenQuery;
uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + accessTokenQuery + "&" + skuToken;;
}
else
{
uriBuilder.Query = accessTokenQuery;
uriBuilder.Query = accessTokenQuery + "&" + skuToken;
}

url = uriBuilder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class CompressionTest
public void SetUp()
{
#if UNITY_5_6_OR_NEWER
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.AccessToken);
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken);
_timeout = Unity.MapboxAccess.Instance.Configuration.DefaultTimeout;
#else
// when run outside of Unity FileSource gets the access token from environment variable 'MAPBOX_ACCESS_TOKEN'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class DirectionsTest

private string _basicResponse = "{\"routes\":[{\"legs\":[{\"steps\":[],\"summary\":\"\",\"duration\":214.4,\"distance\":1318.2,\"annotation\":null}],\"geometry\":\"_urwFt}qbMuLp_@jWzPoHhRMK\",\"duration\":214.4,\"distance\":1318.2,\"weight\":0.0,\"weight_name\":null}],\"waypoints\":[{\"name\":\"East 13th Street\",\"location\":[-73.988909,40.733122]},{\"name\":\"6th Avenue\",\"location\":[-74.00001,40.733004]}],\"code\":\"Ok\"}";
private string _responseWithSteps = "{\"routes\":[{\"legs\":[{\"steps\":[{\"intersections\":[{\"out\":0,\"entry\":[true],\"bearings\":[299],\"location\":[-73.988909,40.733122]},{\"out\":3,\"entry\":[true,false,false,true],\"bearings\":[15,120,195,300],\"location\":[-73.989868,40.733528],\"in\":1},{\"out\":3,\"entry\":[false,false,true,true],\"bearings\":[15,120,195,300],\"location\":[-73.990945,40.733978],\"in\":1},{\"out\":3,\"entry\":[true,false,false,true],\"bearings\":[30,120,210,300],\"location\":[-73.992266,40.734532],\"in\":1}],\"geometry\":\"_urwFt}qbMqA~DyAvEmBfG{CpJ\",\"maneuver\":{\"bearing_after\":299,\"type\":\"depart\",\"modifier\":\"left\",\"bearing_before\":0,\"Location\":[40.733122,-73.988909],\"instruction\":\"Head northwest on East 13th Street\"},\"duration\":90.5,\"distance\":502.1,\"name\":\"East 13th Street\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":2,\"entry\":[false,false,true,true],\"bearings\":[30,120,210,300],\"location\":[-73.994118,40.735313],\"in\":1},{\"out\":2,\"entry\":[false,true,true,false],\"bearings\":[30,120,210,300],\"location\":[-73.994585,40.734672],\"in\":0},{\"out\":2,\"entry\":[false,false,true,true],\"bearings\":[30,120,210,300],\"location\":[-73.99505,40.734034],\"in\":0},{\"out\":2,\"entry\":[false,true,true,false],\"bearings\":[30,120,210,300],\"location\":[-73.995489,40.733437],\"in\":0},{\"out\":2,\"entry\":[false,false,true,true],\"bearings\":[30,120,210,300],\"location\":[-73.995914,40.732847],\"in\":0},{\"out\":2,\"entry\":[false,true,true,false],\"bearings\":[30,120,210,300],\"location\":[-73.996351,40.732255],\"in\":0}],\"geometry\":\"ubswFf~rbM~B|A~BzAtBvAtBrAtBvAh@Vd@`@lAx@JH\",\"maneuver\":{\"bearing_after\":209,\"type\":\"turn\",\"modifier\":\"left\",\"bearing_before\":299,\"Location\":[40.735313,-73.994118],\"instruction\":\"Turn left onto 5th Avenue\"},\"duration\":67.8,\"distance\":496.3,\"name\":\"5th Avenue\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":2,\"entry\":[false,true,true],\"bearings\":[30,120,300],\"location\":[-73.996976,40.731414],\"in\":0}],\"geometry\":\"ijrwFbpsbMKPoChHEH\",\"maneuver\":{\"bearing_after\":305,\"type\":\"end of road\",\"modifier\":\"right\",\"bearing_before\":212,\"Location\":[40.731414,-73.996976],\"instruction\":\"Turn right onto Washington Square North\"},\"duration\":21.0,\"distance\":164.2,\"name\":\"Washington Square North\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":3,\"entry\":[false,false,true,true],\"bearings\":[30,120,210,300],\"location\":[-73.998612,40.732215],\"in\":1}],\"geometry\":\"korwFhzsbMmCbH\",\"maneuver\":{\"bearing_after\":303,\"type\":\"new name\",\"modifier\":\"straight\",\"bearing_before\":303,\"Location\":[40.732215,-73.998612],\"instruction\":\"Continue straight onto Waverly Place\"},\"duration\":34.5,\"distance\":146.0,\"name\":\"Waverly Place\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":0,\"entry\":[true,false,false,true],\"bearings\":[30,120,210,300],\"location\":[-74.000066,40.732929],\"in\":1}],\"geometry\":\"ysrwFlctbMMK\",\"maneuver\":{\"bearing_after\":30,\"type\":\"turn\",\"modifier\":\"right\",\"bearing_before\":303,\"Location\":[40.732929,-74.000066],\"instruction\":\"Turn right onto 6th Avenue\"},\"duration\":0.6,\"distance\":9.6,\"name\":\"6th Avenue\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":0,\"entry\":[true],\"bearings\":[210],\"location\":[-74.00001,40.733004],\"in\":0}],\"geometry\":\"gtrwF`ctbM\",\"maneuver\":{\"bearing_after\":0,\"type\":\"arrive\",\"modifier\":null,\"bearing_before\":30,\"Location\":[40.732929,-74.000066],\"instruction\":\"You have arrived at your destination\"},\"duration\":0.0,\"distance\":0.0,\"name\":\"6th Avenue\",\"mode\":\"driving\"}],\"summary\":\"East 13th Street, 5th Avenue\",\"duration\":214.4,\"distance\":1318.2,\"annotation\":null}],\"geometry\":\"_urwFt}qbMuLp_@jWzPoHhRMK\",\"duration\":214.4,\"distance\":1318.2,\"weight\":0.0,\"weight_name\":null}],\"waypoints\":[{\"name\":\"East 13th Street\",\"location\":[-73.988909,40.733122]},{\"name\":\"6th Avenue\",\"location\":[-74.00001,40.733004]}],\"code\":\"Ok\"}";
private Directions _directions = new Directions(new FileSource());
private Directions _directions = new Directions(new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken));



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class FileSourceTest
public void SetUp()
{
#if UNITY_5_6_OR_NEWER
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.AccessToken);
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken);
_timeout = Unity.MapboxAccess.Instance.Configuration.DefaultTimeout;
#else
// when run outside of Unity FileSource gets the access token from environment variable 'MAPBOX_ACCESS_TOKEN'
Expand Down
Loading