using Mapbox.Unity; namespace Mapbox.Tokens { using Mapbox.Platform; using System; using System.ComponentModel; using Mapbox.VectorTile.Geometry; public enum MapboxTokenStatus { /// The token is valid and active [Description("The token is valid and active")] TokenValid, /// the token can not be parsed [Description("the token can not be parsed")] TokenMalformed, /// the signature for the token does not validate [Description("the signature for the token does not validate")] TokenInvalid, /// the token was temporary and expired [Description("the token was temporary and expired")] TokenExpired, /// the token's authorization has been revoked [Description("the token's authorization has been revoked")] TokenRevoked, /// inital value StatusNotYetSet } /// /// Wrapper class to retrieve details about a token /// public class MapboxTokenApi { public MapboxTokenApi() { } // use internal FileSource without(!) passing access token from config into constructor // otherwise access token would be appended to url twice // https://www.mapbox.com/api-documentation/accounts/#retrieve-a-token // if we should ever implement other API methods: creating, deleting, updating ... tokens // we will need another FileSource with the token from the config private FileSource _fs; public void Retrieve(Func skuToken, string accessToken, Action callback) { if (_fs == null) { _fs = new FileSource(skuToken); } _fs.Request( Utils.Constants.BaseAPI + "tokens/v2?access_token=" + accessToken, (Response response) => { if (response.HasError) { callback(new MapboxToken() { HasError = true, ErrorMessage = response.ExceptionsAsString }); return; } callback(MapboxToken.FromResponseData(response.Data)); } ); } } }