
(function(window, document, $, bam, undefined) {

    var PROXY_ENDPOINT = "/pubajax/wf/flow/social.facebook.apiProxy";

    function executeOpenGraphOperation(operation, method) {
        method = (method) ? method.substring(0, 1).toUpperCase() + method.substring(1) : "Get";

        return $.ajax({
            url : PROXY_ENDPOINT,
            data : {
                httpName : "facebook" + method,
                operation : operation
            },
            dataType : "json",
            success : function() {},
            error : function() {}
        });
    }

    bam.opengraph = {
        /**
         * Returns authorized information for a Facebook app for the connected user
         *
         * @returns {AjaxPromiseObject}
         */
        me : function() {
            return executeOpenGraphOperation("/me");
        },
        
          /**
         * Returns authorized information for a Facebook app for the connected user
         *
         * @returns {AjaxPromiseObject}
         */
        likes : function() {
            return executeOpenGraphOperation("/me/likes");
        },

        /**
         * Returns an array of application requests for the connecgted user
         *
         * @returns {AjaxPromiseObject}
         */
        apprequests : function() {
            return executeOpenGraphOperation("/me/apprequests");
        },

        /**
         * Deletes a handled request for the connecgted user
         *
         * @param {String} requestID 
         *
         * @returns {AjaxPromiseObject}
         */
        deleteRequest : function(requestID) {
            return executeOpenGraphOperation("/" + requestID + "&method=delete", "post");
        }
    };

})(this, this.document, this.jQuery, this.bam);


