本文整理汇总了Java中org.scribe.model.Response.isSuccessful方法的典型用法代码示例。如果您正苦于以下问题:Java Response.isSuccessful方法的具体用法?Java Response.isSuccessful怎么用?Java Response.isSuccessful使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.scribe.model.Response
的用法示例。
在下文中一共展示了Response.isSuccessful方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.scribe.model.Response; //导入方法依赖的package包/类
private String send(Verb verb, String params) throws Exception {
String url = apiUrl + ((params != null) ? params : "");
OAuthRequest request = new OAuthRequest(verb, url);
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, apiAccessToken);
// For more details on the “Bearer” token refer to http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-23
StringBuilder sb = new StringBuilder();
sb.append("Bearer ");
sb.append(apiAccessToken);
request.addHeader("Authorization", sb.toString());
if (LOG.isDebugEnabled()) {
LOG.debug("Yammer request url: {}", request.getCompleteUrl());
}
Response response = request.send();
if (response.isSuccessful()) {
return response.getBody();
} else {
throw new Exception(String.format("Failed to poll %s. Got response code %s and body: %s", getApiUrl(), response.getCode(), response.getBody()));
}
}
示例2: getDevice
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* @param uid
* the cube id to query for
* @return the description of a device
* @throws CubeSensorsException
* when a request fails
*/
public Device getDevice(final String uid) {
final String queryUrl = RESOURCES_ROOT + DEVICES_PATH + uid;
LOGGER.trace("Querying: {}", queryUrl);
final OAuthRequest request = new OAuthRequest(Verb.GET, queryUrl);
request.getHeaders().put(HTTP_HEADER_ACCEPT, MEDIA_TYPE_APPLICATION_JSON);
service.signRequest(accessToken, request);
final Response response = request.send();
LOGGER.trace("Response: {}", response.getBody());
if (!response.isSuccessful()) {
throw new CubeSensorsException(response.getBody());
}
final JsonDeviceResponse queryResponse = parseQuery(response.getBody(), JsonDeviceResponse.class);
if (queryResponse == null) {
return null;
}
LOGGER.debug("Retrieved device {}.", queryResponse.device.uid);
return extractDevice(queryResponse.device);
}
示例3: callback
import org.scribe.model.Response; //导入方法依赖的package包/类
@RequestMapping("/xvscribe/users/callback")
public String callback(@RequestParam("code") String code,
@RequestParam(STATE) String state,
HttpSession session) throws IOException {
// Check the state parameter
String stateFromSession = (String) session.getAttribute(STATE);
session.removeAttribute(STATE);
if (!state.equals(stateFromSession)) {
return "xvia";
}
// Exchange the code for an AccessToken and retrieve the profile
Token accessToken = getAccessToken(code);
Response response = getResponseForProfile(accessToken);
if (!response.isSuccessful()) {
return "xvia";
}
// Store the Xvia user id in the session and redirect the user
// to the page that needs the profile.
String xviaUserId = getXviaUserId(response);
session.setAttribute("xviaUserId", xviaUserId);
return "xvia";
}
示例4: sendVideoChunk
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* Send a chunk of the upload to the vimeo endpoint
*
* @param endpoint
* @param contentLength
* @param contentType
* @param contentRange
* @param chunk
* @param addContentRange
* @return
*/
private static long sendVideoChunk(String endpoint, String contentLength, String contentType, String contentRange,
byte[] chunk, boolean addContentRange){
OAuthRequest req = new OAuthRequest(Verb.PUT, endpoint);
req.addHeader("Content-Length", contentLength);
req.addHeader("Content-Type",contentType);
if (addContentRange){
req.addHeader("Content-Range","bytes " + contentRange);
}
req.addPayload(chunk);
service.signRequest(secretToken, req);
//printRequest(req,"Send Video To" + endpoint); //DEBUG
Response resp = req.send();
if(resp.getCode() != 200 && !resp.isSuccessful()){
return -1;
}
return verifyUpload(endpoint);
}
示例5: getCurrent
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* @param uid
* the cube id to query for
* @return the current state of the cube
* @throws CubeSensorsException
* when a request fails
*/
public State getCurrent(final String uid) {
final String queryUrl = RESOURCES_ROOT + DEVICES_PATH + uid + "/current";
LOGGER.trace("Querying: {}", queryUrl);
final OAuthRequest request = new OAuthRequest(Verb.GET, queryUrl);
request.getHeaders().put(HTTP_HEADER_ACCEPT, MEDIA_TYPE_APPLICATION_JSON);
service.signRequest(accessToken, request);
final Response response = request.send();
LOGGER.trace("Response: {}", response.getBody());
if (!response.isSuccessful()) {
throw new CubeSensorsException(response.getBody());
}
final JsonCurrentResponse queryResponse = parseQuery(response.getBody(), JsonCurrentResponse.class);
if (queryResponse == null) {
return null;
}
final List<State> states = StateParser.parseState(queryResponse.fieldList, queryResponse.results);
// can happen if the cube hasn't reported in recently enough
if (states.isEmpty()) {
return null;
}
return states.get(0);
}
示例6: verifyUpload
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* Verifies the upload and returns whether it's successful
*
* @param endpoint to verify upload to
* @return the last byte on the server
*/
private static long verifyUpload(String endpoint) {
// Verify the upload
OAuthRequest request = new OAuthRequest(Verb.PUT, endpoint);
request.addHeader("Content-Length", "0");
request.addHeader("Content-Range", "bytes */*");
Response response = request.send();
//printResponse(response, "Verify Upload to " + endpoint); //DEBUG
if (response.getCode() != 308 || !response.isSuccessful()) {
return -1;
}
String range = response.getHeader("Range");
return Long.parseLong(range.substring(range.lastIndexOf("-") + 1)) + 1;
//The + 1 at the end is because Vimeo gives you 0-whatever byte where 0 = the first byte
}
示例7: fetchDistanceUnit
import org.scribe.model.Response; //导入方法依赖的package包/类
private Units fetchDistanceUnit() {
Response response = fitbit.fetchProfile();
if (response.isSuccessful()) {
return parseDistanceUnit(response.getBody());
} else {
Log.w(App.TAG, "Error fetching profile: " + response.getMessage()
+ " (" + response.getCode() + ")");
return null;
}
}
示例8: fetchActivities
import org.scribe.model.Response; //导入方法依赖的package包/类
private Activities fetchActivities(Units distanceUnit) {
Response response = fitbit.fetchActivities(
FitbitUtil.getUnits(distanceUnit));
if (response.isSuccessful()) {
return parseActivities(response.getBody(), distanceUnit);
} else {
Log.w(App.TAG, "Error fetching data: " + response.getMessage()
+ " (" + response.getCode() + ")");
if (response.getCode() == 401) {
fitbit.setAccessToken(null);
}
return null;
}
}
示例9: lookupIds
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* Translates a batch of numeric user ids into screen names,
* by looking them up via the Twitter API. The list may not
* be longer than MAX_LOOKUPS users (currently 100).
* @param ids the user ids to be looked up
* @return a map from user ids to the corresponding screen names
*/
public Map<Integer,String> lookupIds (int[] ids) {
if (ids == null) throw new IllegalArgumentException();
if (ids.length == 0) return new HashMap<Integer,String>();
if (ids.length > MAX_LOOKUPS) {
throw new IllegalArgumentException(
"only " + MAX_LOOKUPS + " ids can be resolved at a time "
+ "(parameter array contains " + ids.length + ")"
);
}
OAuthRequest request = new OAuthRequest(
Verb.POST, "https://api.twitter.com/1.1/users/lookup.json"
);
StringBuilder idList = new StringBuilder();
for (int i=0; i<ids.length; i++) {
idList.append(ids[i]);
if (i<ids.length-1) idList.append(",");
}
request.addBodyParameter("user_id", idList.toString());
oauthService.signRequest(accessToken, request);
Response response = request.send();
if (!response.isSuccessful()) throw TwitterException.create(response);
BasicDBList result = (BasicDBList)JSON.parse(response.getBody());
Map<Integer,String> m = new HashMap<Integer,String>();
for (Object o : result) {
DBObject dbo = (DBObject)o;
int id = (Integer)dbo.get("id");
String name = (String)dbo.get("screen_name");
m.put(id, name);
}
if (m.size() == 0) throw new TwitterException("empty response");
return m;
}
示例10: getVerifierThread
import org.scribe.model.Response; //导入方法依赖的package包/类
public static Thread getVerifierThread(final Context context, final String ver, final Deferred<Object, BError, Void> deferred){
return new Thread(new Runnable() {
@Override
public void run() {
accessToken = verify(ver);
if (accessToken == null)
{
handler.sendMessage(MessageObj.getErrorMessage(deferred, BError.getError(BError.Code.ACCESS_TOKEN_REFUSED, "Access token is null")));
return;
}
Response response = getResponse(context, PROTECTED_RESOURCE_URL);
if (!response.isSuccessful())
{
handler.sendMessage(MessageObj.getErrorMessage(deferred, BError.getError(BError.Code.BAD_RESPONSE, response.getBody())));
return;
}
try {
JSONObject json = new JSONObject(response.getBody());
if (DEBUG) Timber.d("Twitter Response: %s", json.toString());
userId = json.getString("id");
profileImageUrl = json.getString(BDefines.Keys.ThirdPartyData.ImageURL);
if (DEBUG) Timber.i("profileImageUrl: %s", profileImageUrl);
BNetworkManager.sharedManager().getNetworkAdapter().authenticateWithMap(
AbstractNetworkAdapter.getMap(new String[]{BDefines.Keys.UserId, LoginTypeKey}, json.get("id"), Twitter))
.done(new DoneCallback<Object>() {
@Override
public void onDone(Object o) {
deferred.resolve(o);
}
})
.fail(new FailCallback<BError>() {
@Override
public void onFail(BError bError) {
deferred.reject(bError);
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
}
);
}
示例11: getSpan
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* Queries for a list of states over the time span specified. Leaving a field {@code null} will default to the API defaults.
*
* @param uid
* the UID of the device to request data for
* @param start
* the query start time
* @param end
* the query end time
* @param resolution
* the resolution in minutes
* @return a list of all states returned by the API
* @throws CubeSensorsException
* when a request fails
*/
public List<State> getSpan(final String uid, final ZonedDateTime start, final ZonedDateTime end, final Integer resolution) {
final String queryUrl = RESOURCES_ROOT + DEVICES_PATH + uid + "/span";
LOGGER.trace("Querying: {}", queryUrl);
final OAuthRequest request = new OAuthRequest(Verb.GET, queryUrl);
request.getHeaders().put(HTTP_HEADER_ACCEPT, MEDIA_TYPE_APPLICATION_JSON);
if (start != null) {
final ZonedDateTime startUtc = start.withZoneSameInstant(ZoneId.of("Z")).truncatedTo(ChronoUnit.SECONDS);
request.addQuerystringParameter("start", startUtc.toString());
LOGGER.trace("Adding querystring parameter {}={}", "start", startUtc);
}
if (end != null) {
final ZonedDateTime endUtc = end.withZoneSameInstant(ZoneId.of("Z")).truncatedTo(ChronoUnit.SECONDS);
request.addQuerystringParameter("end", endUtc.toString());
LOGGER.trace("Adding querystring parameter {}={}", "end", endUtc);
}
if (resolution != null) {
request.addQuerystringParameter("resolution", resolution.toString());
LOGGER.trace("Adding querystring parameter {}={}", "resolution", resolution);
}
service.signRequest(accessToken, request);
final Response response = request.send();
LOGGER.trace("Response: {}", response.getBody());
if (!response.isSuccessful()) {
throw new CubeSensorsException(response.getBody());
}
final JsonSpanResponse queryResponse = parseQuery(response.getBody(), JsonSpanResponse.class);
if (queryResponse == null) {
return new ArrayList<>();
}
final List<State> states = StateParser.parseState(queryResponse.fieldList, queryResponse.results);
LOGGER.debug("Retrieved {} states.", states.size());
return states;
}