public Api(ApiData apiData, String accessToken, ICache cache, ILogger logger, PrismicHttpClient client) { this.apiData = apiData; this.accessToken = accessToken; this.cache = cache; this.logger = logger; this.prismicHttpClient = client; }
/** * Entry point to get an {@link Api} object. * Example: <code>API api = API.get("https://lesbonneschoses.prismic.io/api", null, new Cache.BuiltInCache(999), new Logger.PrintlnLogger());</code> * * @param endpoint the endpoint of your prismic.io content repository, typically https://yourrepoid.prismic.io/api * @param accessToken Your Oauth access token if you wish to use one (to access future content releases, for instance) * @param cache instance of a class that implements the {@link Cache} interface, and will handle the cache * @param logger instance of a class that implements the {@link Logger} interface, and will handle the logging * @return the usable API object */ public static async Task <Api> Get(String endpoint, String accessToken, ICache cache, ILogger logger, HttpClient client) { String url = (accessToken == null ? endpoint : (endpoint + "?access_token=" + HttpUtility.UrlEncode(accessToken))); PrismicHttpClient prismicHttpClient = new PrismicHttpClient(client); JToken json = cache.Get(url); if (json == null) { json = await prismicHttpClient.fetch(url, logger, cache); cache.Set(url, 5000L, json); } ApiData apiData = ApiData.Parse(json); return(new Api(apiData, accessToken, cache, logger, prismicHttpClient)); }
/** * Entry point to get an {@link Api} object. * Example: <code>API api = API.get("https://lesbonneschoses.prismic.io/api", null, new Cache.BuiltInCache(999), new Logger.PrintlnLogger());</code> * * @param endpoint the endpoint of your prismic.io content repository, typically https://yourrepoid.prismic.io/api * @param accessToken Your Oauth access token if you wish to use one (to access future content releases, for instance) * @param cache instance of a class that implements the {@link Cache} interface, and will handle the cache * @param logger instance of a class that implements the {@link Logger} interface, and will handle the logging * @return the usable API object */ public static async Task<Api> Get(String endpoint, String accessToken, ICache cache, ILogger logger, HttpClient client) { String url = (accessToken == null ? endpoint : (endpoint + "?access_token=" + HttpUtility.UrlEncode(accessToken))); PrismicHttpClient prismicHttpClient = new PrismicHttpClient(client); JToken json = cache.Get(url); if (json == null) { json = await prismicHttpClient.fetch(url, logger, cache); cache.Set(url, 5000L, json); } ApiData apiData = ApiData.Parse(json); return new Api(apiData, accessToken, cache, logger, prismicHttpClient); }