Response(Request request, HttpURLConnection connection, String rawResponse, GraphObject graphObject, GraphObjectList<GraphObject> graphObjects, boolean isFromCache, FacebookRequestError error) { this.request = request; this.connection = connection; this.rawResponse = rawResponse; this.graphObject = graphObject; this.graphObjectList = graphObjects; this.isFromCache = isFromCache; this.error = error; }
private static Response createResponseFromObject(Request request, HttpURLConnection connection, Object object, boolean isFromCache, Object originalResult) throws JSONException { if (object instanceof JSONObject) { JSONObject jsonObject = (JSONObject) object; FacebookRequestError error = FacebookRequestError.checkResponseAndCreateError(jsonObject, originalResult, connection); if (error != null) { if (error.getErrorCode() == INVALID_SESSION_FACEBOOK_ERROR_CODE) { Session session = request.getSession(); if (session != null) { session.closeAndClearTokenInformation(); } } return new Response(request, connection, error); } Object body = Utility.getStringPropertyAsJSON(jsonObject, BODY_KEY, NON_JSON_RESPONSE_PROPERTY); if (body instanceof JSONObject) { GraphObject graphObject = GraphObject.Factory.create((JSONObject) body); return new Response(request, connection, body.toString(), graphObject, isFromCache); } else if (body instanceof JSONArray) { GraphObjectList<GraphObject> graphObjectList = GraphObject.Factory.createList( (JSONArray) body, GraphObject.class); return new Response(request, connection, body.toString(), graphObjectList, isFromCache); } // We didn't get a body we understand how to handle, so pretend we got nothing. object = JSONObject.NULL; } if (object == JSONObject.NULL) { return new Response(request, connection, object.toString(), (GraphObject)null, isFromCache); } else { throw new FacebookException("Got unexpected object type in response, class: " + object.getClass().getSimpleName()); } }
private void addResults(Response response) { SimpleGraphObjectCursor<T> cursorToModify = (cursor == null || !appendResults) ? new SimpleGraphObjectCursor<T>() : new SimpleGraphObjectCursor<T>(cursor); PagedResults result = response.getGraphObjectAs(PagedResults.class); boolean fromCache = response.getIsFromCache(); GraphObjectList<T> data = result.getData().castToListOf(graphObjectClass); boolean haveData = data.size() > 0; if (haveData) { nextRequest = response.getRequestForPagedResults(Response.PagingDirection.NEXT); cursorToModify.addGraphObjects(data, fromCache); cursorToModify.setMoreObjectsAvailable(true); } if (!haveData) { cursorToModify.setMoreObjectsAvailable(false); cursorToModify.setFromCache(fromCache); nextRequest = null; } // Once we get any set of results NOT from the cache, stop trying to get any future ones // from it. if (!fromCache) { skipRoundtripIfCached = false; } deliverResult(cursorToModify); }
Response(Request request, HttpURLConnection connection, GraphObjectList<GraphObject> graphObjects, boolean isFromCache) { this.request = request; this.connection = connection; this.graphObject = null; this.graphObjectList = graphObjects; this.isFromCache = isFromCache; this.error = null; }
private static Response createResponseFromObject(Request request, HttpURLConnection connection, Object object, boolean isFromCache, Object originalResult) throws JSONException { if (object instanceof JSONObject) { JSONObject jsonObject = (JSONObject) object; FacebookRequestError error = FacebookRequestError.checkResponseAndCreateError(jsonObject, originalResult, connection); if (error != null) { if (error.getErrorCode() == INVALID_SESSION_FACEBOOK_ERROR_CODE) { Session session = request.getSession(); if (session != null) { session.closeAndClearTokenInformation(); } } return new Response(request, connection, error); } Object body = Utility.getStringPropertyAsJSON(jsonObject, BODY_KEY, NON_JSON_RESPONSE_PROPERTY); if (body instanceof JSONObject) { GraphObject graphObject = GraphObject.Factory.create((JSONObject) body); return new Response(request, connection, graphObject, isFromCache); } else if (body instanceof JSONArray) { GraphObjectList<GraphObject> graphObjectList = GraphObject.Factory.createList( (JSONArray) body, GraphObject.class); return new Response(request, connection, graphObjectList, isFromCache); } // We didn't get a body we understand how to handle, so pretend we got nothing. object = JSONObject.NULL; } if (object == JSONObject.NULL) { return new Response(request, connection, (GraphObject)null, isFromCache); } else { throw new FacebookException("Got unexpected object type in response, class: " + object.getClass().getSimpleName()); } }
private static <T extends GraphObject> List<T> typedListFromResponse(Response response, Class<T> clazz) { GraphMultiResult multiResult = response.getGraphObjectAs(GraphMultiResult.class); if (multiResult == null) { return null; } GraphObjectList<GraphObject> data = multiResult.getData(); if (data == null) { return null; } return data.castToListOf(clazz); }
void updateObjectAttachmentUrls(String objectProperty, List<String> attachmentUrls, boolean isUserGenerated) { final OpenGraphObject object; try { object = action.getPropertyAs(objectProperty, OpenGraphObject.class); if (object == null) { throw new IllegalArgumentException("Action does not contain a property '" + objectProperty + "'"); } } catch (FacebookGraphObjectException exception) { throw new IllegalArgumentException("Property '" + objectProperty + "' is not a graph object"); } if (!object.getCreateObject()) { throw new IllegalArgumentException( "The Open Graph object in '" + objectProperty + "' is not marked for creation"); } GraphObjectList<GraphObject> attachments = object.getImage(); if (attachments == null) { attachments = GraphObject.Factory.createList(GraphObject.class); } for (String url : attachmentUrls) { GraphObject graphObject = GraphObject.Factory.create(); graphObject.setProperty(NativeProtocol.IMAGE_URL_KEY, url); if (isUserGenerated) { graphObject.setProperty(NativeProtocol.IMAGE_USER_GENERATED_KEY, true); } attachments.add(graphObject); } object.setImage(attachments); }
private void addResults(Response response) { SimpleGraphObjectCursor<T> cursorToModify = (cursor == null || !appendResults) ? new SimpleGraphObjectCursor<T>() : new SimpleGraphObjectCursor<T>(cursor); PagedResults result = response.getGraphObjectAs(PagedResults.class); boolean fromCache = response.getIsFromCache(); GraphObjectList<T> data = result.getData().castToListOf(graphObjectClass); boolean haveData = data.size() > 0; if (haveData) { nextRequest = response.getRequestForPagedResults(Response.PagingDirection.NEXT); cursorToModify.addGraphObjects(data, fromCache); if (nextRequest != null) { cursorToModify.setMoreObjectsAvailable(true); } else { cursorToModify.setMoreObjectsAvailable(false); } } if (!haveData) { cursorToModify.setMoreObjectsAvailable(false); cursorToModify.setFromCache(fromCache); nextRequest = null; } // Once we get any set of results NOT from the cache, stop trying to get any future ones // from it. if (!fromCache) { skipRoundtripIfCached = false; } deliverResult(cursorToModify); }
private static Response createResponseFromObject(Request paramRequest, HttpURLConnection paramHttpURLConnection, Object paramObject1, boolean paramBoolean, Object paramObject2) { if ((paramObject1 instanceof JSONObject)) { JSONObject localJSONObject = (JSONObject)paramObject1; FacebookRequestError localFacebookRequestError = FacebookRequestError.checkResponseAndCreateError(localJSONObject, paramObject2, paramHttpURLConnection); if (localFacebookRequestError != null) { if (localFacebookRequestError.getErrorCode() == 190) { Session localSession = paramRequest.getSession(); if (localSession != null) localSession.closeAndClearTokenInformation(); } return new Response(paramRequest, paramHttpURLConnection, localFacebookRequestError); } Object localObject = Utility.getStringPropertyAsJSON(localJSONObject, "body", "FACEBOOK_NON_JSON_RESULT"); if ((localObject instanceof JSONObject)) { GraphObject localGraphObject = GraphObject.Factory.create((JSONObject)localObject); return new Response(paramRequest, paramHttpURLConnection, localObject.toString(), localGraphObject, paramBoolean); } if ((localObject instanceof JSONArray)) { GraphObjectList localGraphObjectList = GraphObject.Factory.createList((JSONArray)localObject, GraphObject.class); return new Response(paramRequest, paramHttpURLConnection, localObject.toString(), localGraphObjectList, paramBoolean); } paramObject1 = JSONObject.NULL; } if (paramObject1 == JSONObject.NULL) return new Response(paramRequest, paramHttpURLConnection, paramObject1.toString(), null, paramBoolean); throw new FacebookException("Got unexpected object type in response, class: " + paramObject1.getClass().getSimpleName()); }
private void addResults(Response paramResponse) { SimpleGraphObjectCursor localSimpleGraphObjectCursor; if ((this.cursor == null) || (!this.appendResults)) localSimpleGraphObjectCursor = new SimpleGraphObjectCursor(); else localSimpleGraphObjectCursor = new SimpleGraphObjectCursor(this.cursor); PagedResults localPagedResults = (PagedResults)paramResponse.getGraphObjectAs(PagedResults.class); boolean bool = paramResponse.getIsFromCache(); GraphObjectList localGraphObjectList = localPagedResults.getData().castToListOf(this.graphObjectClass); int i; if (localGraphObjectList.size() > 0) i = 1; else i = 0; int j = i; if (i != 0) { this.nextRequest = paramResponse.getRequestForPagedResults(Response.PagingDirection.NEXT); localSimpleGraphObjectCursor.addGraphObjects(localGraphObjectList, bool); localSimpleGraphObjectCursor.setMoreObjectsAvailable(true); } if (j == 0) { localSimpleGraphObjectCursor.setMoreObjectsAvailable(false); localSimpleGraphObjectCursor.setFromCache(bool); this.nextRequest = null; } if (!bool) this.skipRoundtripIfCached = false; deliverResult(localSimpleGraphObjectCursor); }