diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-04-24 00:22:21 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-04-24 00:22:21 +0200 |
commit | 5bb859152e5d9f160baf588e1555e79a4617fa8c (patch) | |
tree | d062d5ce678a3e1cc48cbcccf63dc408aa516fab /src/support | |
parent | 5dd7436fa096d67758a25a713fdd8d70ca8d605c (diff) | |
download | TwitterDataAnalytics-5bb859152e5d9f160baf588e1555e79a4617fa8c.tar.gz |
Refactor consumer key/secret pair into container
Diffstat (limited to 'src/support')
-rw-r--r-- | src/support/ConsumerKeySecret.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/support/ConsumerKeySecret.java b/src/support/ConsumerKeySecret.java new file mode 100644 index 0000000..25bde51 --- /dev/null +++ b/src/support/ConsumerKeySecret.java @@ -0,0 +1,39 @@ +package support; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.Charsets; + +/** + * Container for a pair of consumer key and secret. See + * https://dev.twitter.com/docs/auth/application-only-auth + */ +public class ConsumerKeySecret { + + private final String key; + private final String secret; + + public ConsumerKeySecret(String key, String secret) { + this.key = key; + this.secret = secret; + } + + public String getKey() { + return key; + } + + public String getSecret() { + return secret; + } + + private String getBearerToken() { + return key + ":" + secret; + } + + /** + * @return Base64-encoded bearer token that can should be included in the + * Authorization header for application-only requests. + */ + public String getBearerTokenBase64() { + return Base64.encodeBase64String(getBearerToken().getBytes(Charsets.UTF_8)); + } +} |