Beispiel #1
0
  /**
   * Parses the passed JSON string into an OpenSocialResponse object -- if the
   * passed string represents a JSON object, it is added to the returned
   * object keyed on the passed ID.
   * 
   * @param  _in The complete JSON string returned from an OpenSocial container
   *            _in response to a request for data
   * @param  id The string ID to tag the JSON object string with as it is added
   *            to the OpenSocialResponse object
   * @throws JSONException
   */
  public static OpenSocialResponse getResponse(String _in, String id)
    {

    OpenSocialResponse r = null;

    if (_in[0] == '{') {
      r = new OpenSocialResponse();
      r.addItem(id, escape(_in));
    } else if (_in[0] == '[') {
      return getResponse(_in);
    }

    return r;
  }
Beispiel #2
0
    /**
     * Parses the passed JSON string into an OpenSocialResponse object -- if the
     * passed string represents a JSON object, it is added to the returned
     * object keyed on the passed ID.
     *
     * @param  _in The complete JSON string returned from an OpenSocial container
     *            _in response to a request for data
     * @param  id The string ID to tag the JSON object string with as it is added
     *            to the OpenSocialResponse object
     * @throws JSONException
     */
    public static OpenSocialResponse getResponse(String _in, String id)
    {
        OpenSocialResponse r = null;

        if (_in[0] == '{')
        {
            r = new OpenSocialResponse();
            r.addItem(id, escape(_in));
        }
        else if (_in[0] == '[')
        {
            return(getResponse(_in));
        }

        return(r);
    }
Beispiel #3
0
  /**
   * Parses the passed JSON string into an OpenSocialResponse object -- if the
   * passed string represents a JSON array, each object _in the array is added
   * to the returned object keyed on its "id" property.
   * 
   * @param  _in The complete JSON string returned from an OpenSocial container
   *            _in response to a request for data
   * @throws JSONException
   */
  public static OpenSocialResponse getResponse(String _in)
     {

    OpenSocialResponse r = null;

    if (_in[0] == '[') {
      JsonArray responseArray = new JsonArray(_in);
      r = new OpenSocialResponse();

      for (int i=0; i<responseArray.Length; i++) {
        JsonObject o = responseArray.GetObject(i);

        if (o.Contains("id")) {
          String id = o["id"].ToString();
          r.addItem(id, escape(o.ToString()));
        }
      }
    }


    return r;
  }
Beispiel #4
0
    /**
     * Parses the passed JSON string into an OpenSocialResponse object -- if the
     * passed string represents a JSON array, each object _in the array is added
     * to the returned object keyed on its "id" property.
     *
     * @param  _in The complete JSON string returned from an OpenSocial container
     *            _in response to a request for data
     * @throws JSONException
     */
    public static OpenSocialResponse getResponse(String _in)
    {
        OpenSocialResponse r = null;

        if (_in[0] == '[')
        {
            JsonArray responseArray = new JsonArray(_in);
            r = new OpenSocialResponse();

            for (int i = 0; i < responseArray.Length; i++)
            {
                JsonObject o = responseArray.GetObject(i);

                if (o.Contains("id"))
                {
                    String id = o["id"].ToString();
                    r.addItem(id, escape(o.ToString()));
                }
            }
        }


        return(r);
    }
    /**
     * Requests the persistent key-value pairs comprising a given user's "App
     * Data for the application with the passed ID and returns a specialized
     * OpenSocialObject instance mapping each pair to a field.
     *
     * @param  userId OpenSocial ID of user whose App Data is to be fetched
     * @param  appId The ID of the application to fetch user App Data for
     *         or "@app" for the current application
     * @throws OpenSocialRequestException if there are any runtime issues with
     *         establishing a RESTful or JSON-RPC connection or parsing the
     *         response that the container returns
     * @throws JSONException
     * @throws OAuthException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws IOException
     * @throws URISyntaxException
     */
    public OpenSocialAppData fetchPersonAppData(String userId, String appId)
    {
        OpenSocialResponse response = fetchAppData(userId, "@self", appId);

        return(response.getItemAsAppData("appdata"));
    }
    /**
     * Requests profile details for the friends of a given user and returns a
     * Java Collection of OpenSocialPerson instances representing the friends
     * with all of the corresponding information.
     *
     * @param  userId OpenSocial ID of user whose friend list is to be fetched
     * @throws OpenSocialRequestException if there are any runtime issues with
     *         establishing a RESTful or JSON-RPC connection or parsing the
     *         response that the container returns
     * @throws JSONException
     * @throws OAuthException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws IOException
     * @throws URISyntaxException
     */
    public List <OpenSocialPerson> fetchFriends(String userId)
    {
        OpenSocialResponse response = fetchPeople(userId, "@friends");

        return(response.getItemAsPersonCollection("people"));
    }
    /**
     * Requests a user's profile details and returns an OpenSocialPerson
     * instance with all of the corresponding information.
     *
     * @param  userId OpenSocial ID of user whose profile details are to be
     *         fetched
     * @throws OpenSocialRequestException if there are any runtime issues with
     *         establishing a RESTful or JSON-RPC connection or parsing the
     *         response that the container returns
     * @throws JSONException
     * @throws OAuthException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws IOException
     * @throws URISyntaxException
     */
    public OpenSocialPerson fetchPerson(String userId)
    {
        OpenSocialResponse response = fetchPeople(userId, "@self");

        return(response.getItemAsPerson("people"));
    }