fernandezpablo85/scribe-java — Issue #223: Enhance ServiceBuilder to accept properties file
Author: devashishmamgain
Created: 2012-02-11 20:40:09+00:00
State: open

Currently all the keys like apiKey, secretKey, etc are hard coded.
We can enhance the ServiceBuilder class to accept the properties object / property resource path.
All the oauth properties can be declared in the property file.

Something like the following code can be added to ServiceBuilder.java

public ServiceBuilder propertiesResource(String propertyResource) {
Properties properties = new Properties();
try {
properties.load(ServiceBuilder.class.getClassLoader().getResourceAsStream(propertyResource));
} catch (IOException ex) {
Logger.getLogger(ServiceBuilder.class.getName()).log(Level.SEVERE, null, ex);
}

return properties(properties);
}

public ServiceBuilder properties(Properties properties) {
return apiKey(properties.getProperty(OAuthConstants.CLIENT_ID))
.apiSecret(properties.getProperty(OAuthConstants.CLIENT_SECRET))
.callback(properties.getProperty(OAuthConstants.CALLBACK))
.scope(properties.getProperty(OAuthConstants.SCOPE));
}

How this can be used:

new ServiceBuilder().provider(GoogleApi20.class)
.propertiesResource("oauth_google.properties")
.build();

And oauth_google.properties will contain all the key value pairs for Google Authentication.