com.belladati.sdk.impl.TokenHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-android Show documentation
Show all versions of sdk-android Show documentation
The BellaDati SDK allows accessing a BellaDati server from 3rd-party applications using Java. This project contains the implementation for Android.
package com.belladati.sdk.impl;
import java.io.Serializable;
import java.util.Random;
import oauth.signpost.OAuthConsumer;
import com.belladati.sdk.impl.oauth.BellaDatiOAuthConsumer;
class TokenHolder implements Serializable {
/** The serialVersionUID */
private static final long serialVersionUID = 8122702080702303615L;
private static final Random RANDOM = new Random();
private final String consumerKey;
private final String consumerSecret;
private String token;
private String tokenSecret;
TokenHolder(String consumerKey, String consumerSecret) {
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
}
public OAuthConsumer createConsumer() {
OAuthConsumer consumer = new BellaDatiOAuthConsumer(consumerKey, consumerSecret) {
private static final long serialVersionUID = 2077439267247908434L;
@Override
protected String generateNonce() {
// thread-safe nonce generation
// http://code.google.com/p/oauth-signpost/issues/detail?id=41
return Long.toString(RANDOM.nextLong());
}
};
consumer.setTokenWithSecret(token, tokenSecret);
return consumer;
}
public String getConsumerKey() {
return consumerKey;
}
public boolean hasToken() {
return token != null;
}
public String getToken() {
return token;
}
public void setToken(String token, String tokenSecret) {
this.token = token;
this.tokenSecret = tokenSecret;
}
}