Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
volley + signpost
import com.android.volley.toolbox.HurlStack;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class OAuthStack extends HurlStack{
private final OAuthConsumer consumer;
public OAuthStack(OAuthConsumer consumer) {
this.consumer = consumer;
}
@Override
protected HttpURLConnection createConnection(URL url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
consumer.sign(connection);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
return connection;
}
}
// OAuthConsumer consumer = ~
// RequestQueue queue = Volley.newRequestQueue(this.getActivity(), new OAuthStack(consumer));

Nicely done 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment