|
| 1 | +package com.github.scribejava.apis; |
| 2 | + |
| 3 | +import android.util.Log; |
| 4 | + |
| 5 | +import com.github.scribejava.core.builder.api.DefaultApi20; |
| 6 | +import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; |
| 7 | +import com.github.scribejava.core.extractors.TokenExtractor; |
| 8 | +import com.github.scribejava.core.model.OAuth2AccessToken; |
| 9 | +import com.github.scribejava.core.model.Verb; |
| 10 | + |
| 11 | +public class ConfigurableApi extends DefaultApi20 { |
| 12 | + |
| 13 | + private String accessTokenEndpoint; |
| 14 | + |
| 15 | + private String authorizationBaseUrl; |
| 16 | + |
| 17 | + private Verb accessTokenVerb = Verb.GET; |
| 18 | + |
| 19 | + protected ConfigurableApi() { |
| 20 | + } |
| 21 | + |
| 22 | + private static class InstanceHolder { |
| 23 | + private static final ConfigurableApi INSTANCE = new ConfigurableApi(); |
| 24 | + } |
| 25 | + |
| 26 | + public static ConfigurableApi instance() { |
| 27 | + return InstanceHolder.INSTANCE; |
| 28 | + } |
| 29 | + |
| 30 | + public ConfigurableApi setAccessTokenEndpoint(String endpoint) { |
| 31 | + accessTokenEndpoint = endpoint; |
| 32 | + return this; |
| 33 | + } |
| 34 | + |
| 35 | + public ConfigurableApi setAuthorizationBaseUrl(String baseUrl) { |
| 36 | + authorizationBaseUrl = baseUrl; |
| 37 | + return this; |
| 38 | + } |
| 39 | + |
| 40 | + public ConfigurableApi setAccessTokenVerb(String verb) { |
| 41 | + if (verb.equalsIgnoreCase("GET")) { |
| 42 | + accessTokenVerb = Verb.GET; |
| 43 | + } else if (verb.equalsIgnoreCase("POST")) { |
| 44 | + accessTokenVerb = Verb.POST; |
| 45 | + } else { |
| 46 | + Log.e("ConfigurableApi", "Expected GET or POST string values for accessTokenVerb."); |
| 47 | + } |
| 48 | + |
| 49 | + return this; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public Verb getAccessTokenVerb() { |
| 54 | + return accessTokenVerb; |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public String getAccessTokenEndpoint() { |
| 59 | + return accessTokenEndpoint; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + protected String getAuthorizationBaseUrl() { |
| 64 | + return authorizationBaseUrl; |
| 65 | + } |
| 66 | +} |
0 commit comments