Exemple #1
0
  /**
   * Create a Parse API URL using the provided data.
   *
   * @param endPoint The end point
   * @param objectId The optional objectId
   * @return The Parse API URL of the format {@code https://api.parse.com/<endpoint>[/<objectId>]}.
   */
  protected static String getUrl(final String endPoint, final String objectId) {
    String url = Parse.getParseAPIUrl(endPoint) + (objectId != null ? "/" + objectId : "");

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Request URL: " + url);
    }

    return url;
  }
Exemple #2
0
 /**
  * Adds the default headers (e.g., {@link ParseConstants#HEADER_APPLICATION_ID} and {@link
  * ParseConstants#HEADER_CLIENT_KEY}) associated with Parse REST API calls.
  *
  * @param addJson If true, the corresponding content-type header field is also set.
  * @throws ParseException if anything goes wrong.
  */
 protected void setupDefaultHeaders(boolean addJson) throws ParseException {
   try {
     headers.put(ParseConstants.HEADER_APPLICATION_ID, Parse.getApplicationId());
     headers.put(ParseConstants.HEADER_CLIENT_KEY, Parse.getClientKey());
     if (addJson) {
       headers.put(ParseConstants.HEADER_CONTENT_TYPE, ParseConstants.CONTENT_TYPE_JSON);
     }
     if (!data.has(ParseConstants.FIELD_SESSION_TOKEN) && ParseUser.getCurrent() != null) {
       data.put(ParseConstants.FIELD_SESSION_TOKEN, ParseUser.getCurrent().getSessionToken());
     }
     if (data.has(ParseConstants.FIELD_SESSION_TOKEN)) {
       headers.put(
           ParseConstants.HEADER_SESSION_TOKEN,
           data.getString(ParseConstants.FIELD_SESSION_TOKEN));
     }
   } catch (JSONException ex) {
     throw new ParseException(
         ParseException.INVALID_JSON, ParseException.ERR_PREPARING_REQUEST, ex);
   }
 }