Esempio n. 1
0
    function saveAndContinue(data) {
        var deferred = q.defer();

        var profile = data['profile'];
        var accessToken = data['accessToken'];


        var store = jive.service.persistence();
        jive.service.persistence().find('cloudalyticsTokens', { 'id' : profile }).then(
            function(found) {

                store.save('cloudalyticsTokens', profile, {
                    id : profile,
                    accessToken : accessToken,
                    expires : 'TODO'
                }).then(
                    function() {
                        deferred.resolve(data);
                    },
                    function(error) {
                        deferred.reject(error);
                    }
                );
            }
        );

        return deferred.promise;
    };
Esempio n. 2
0
            instances.forEach( function( instance ) {
                var config = instance['config'];
                if ( config && config['posting'] === 'off' ) {
                    return;
                }

                jive.logger.debug('running pusher for ', instance.name, 'instance', instance.id );

                var store = jive.service.persistence();
                return store.find('exampleStore', {
                    'key':'count'
                }).then(function(count) {
                    count = count.length > 0 ? count[0].count : parseInt(instance.config.startSequence, 10);
                    store.save('exampleStore', 'count', {
                        'key':'count',
                        'count':count+1
                    }).then(function() {
                        jive.extstreams.pushActivity(instance, getFormattedData(count));
                    });
                }, function(err) {
                    //some error
                    jive.logger.debug('Error encountered, push failed', err);
                });

            });
Esempio n. 3
0
exports.doPost = function(query, body, instance) {
    var deferred = q.defer();

    var ticketID = instance['config']['ticketID'];

    var tokenStore = jive.service.persistence();
    tokenStore.find('tokens', {'ticket': ticketID }).then(function (found) {
        if (found) {
            var accessToken = found[0]['accessToken']['access_token'];

            jive.util.buildRequest(
                    "https://api.podio.com/" + query + ( query.indexOf('?') < 0 ? "?" : "&"  ) + "oauth_token=" + accessToken,
                    'POST', body
                ).then(
                // success
                function (response) {
                    deferred.resolve(response);
                },

                // fail
                function (response) {
                    deferred.reject(response);
                }
            );
        }
    });

    return deferred.promise;
};
Esempio n. 4
0
function setupJiveHook(place) {
    if (!place.jive.hookID) {
        var webhookCallback = jive.service.serviceURL() + '/webhooks?place=' + encodeURIComponent(place.placeUrl);
        return jive.community.findByJiveURL(place.jiveUrl).then(function (community) {
            //register Webhook on Jive Instance
            var accessToken = place.jive.access_token;

            return jive.webhooks.register(
                    community, "discussion", place.placeUrl,
                    webhookCallback, accessToken
                ).then(function (webhook) {
                    var webhookEntity = webhook['entity'];
                    var webhookToSave = {
                        'object': webhookEntity['object'],
                        'events': webhookEntity['event'],
                        'callback': webhookEntity['callback'],
                        'url': webhookEntity['resources']['self']['ref'],
                        'id': webhookEntity['id']
                    };

                    //save webhook in service and placeStore to unregister later.
                    return jive.webhooks.save(webhookToSave).then(function () {
                        return placeStore.save(place.placeUrl, {jive: {hookID: webhookEntity.id}});
                    })
                });
        });
    } else {
        return q();
    }
}
Esempio n. 5
0
myOauth.fetchOAuth2Conf = function() {
    var oauthConf = jive.service.options['oauth2-podio'] || {};
    oauthConf = JSON.parse( JSON.stringify( oauthConf ) );
    var clientOAuth2CallbackUrl = oauthConf[ 'clientOAuth2CallbackUrl' ];
    oauthConf[ 'clientOAuth2CallbackUrl' ] =
        clientOAuth2CallbackUrl || jive.service.serviceURL() + '/{{{TILE_NAME_BASE}}}/oauth/oauth2Callback';
    return oauthConf;
};
Esempio n. 6
0
 jive.events.addLocalEventListener( 'registeredJiveInstanceSuccess', function( community ) {
     jive.webhooks.register(
         community['jiveCommunity'],
         'user_account,user_session,user_membership,webhook,social_group',
         undefined,
         jive.service.serviceURL() + '/webhooks'
     );
 });
Esempio n. 7
0
File: get.js Progetto: Bia3/jiveapps
exports.route = function(req, res){
    var conf = jive.service.options;
    res.render('configuration.html', 
      { 
        host: jive.service.serviceURL()
      }
    );
};
Esempio n. 8
0
 function(error) {
     res.render('reports-menu.html',
         {
             host : jive.service.serviceURL(),
             error : error
         }
     );
     deferred.reject();
 }
Esempio n. 9
0
 function(error) {
     console.log('Error: '+error);
     res.render('start.html', {
         error : error,
         profile : profile,
         host: jive.service.serviceURL()
     });
     deferred.reject();
 }
Esempio n. 10
0
 jive.events.addLocalEventListener( 'registeredJiveInstanceSuccess', function( community ) {
     console.log("registering webhook for", community);
     jive.webhooks.register(
         community['jiveCommunity'],
         'webhook',
         undefined,
         jive.service.serviceURL() + '/webhooks'
     );
 } );
Esempio n. 11
0
 function(accessToken) {
     res.render('report-menu.html',
         {
             host : jive.service.serviceURL(),
             profile : profile,
             accessToken : accessToken
         }
     );
     deferred.resolve();
 },
Esempio n. 12
0
/**
 * Handles actually pushing data to the tile instance
 * @param instance
 */
function processTileInstance(instance) {
    jive.logger.debug('running pusher for ', instance.name, 'instance', instance.id);

    // creates a data update structure
    function getFormattedData(count) {
        return {
            data: {
                 "title": "{{{TILE_NAME}}} :"+count,
                 "contents": [
                 {
                    "titleText": "Jive Software - Carousel 1",
                    "titleLink": "http://developer.jivesoftware.com",
                    "image": "http://www.easternct.edu/ctreview/connections/stories/images/carousel_1.jpg",
                    "imageURI": "http://www.easternct.edu/ctreview/connections/stories/images/carousel_1.jpg",
                    "description": "Carousel Horse"
                 },
                 {
                     "titleText": "Jive Software - Carousel 2",
                     "titleLink": "https://community.jivesoftware.com/community/developer",
                     "image": "http://thispublicaddress.com/tPA4/images/06_06/carousel.jpg",
                     "imageURI": "http://thispublicaddress.com/tPA4/images/06_06/carousel.jpg",
                     "description": "Old School Carousel"
                 },
                 {
                     "titleText": "Jive Software - Carousel 3",
                     "titleLink": "https://community.jivesoftware.com/community/developer",
                     "image": "http://upload.wikimedia.org/wikipedia/en/9/9e/Carousel_1945_Bdwy.jpg",
                     "imageURI": "http://upload.wikimedia.org/wikipedia/en/9/9e/Carousel_1945_Bdwy.jpg",
                     "description": "On Broadway"
                 }
                 ],
                 "config": {
                    "autoplay": true,
                    "speed": "medium",
                    "previewPane": true,
                    "transition": "fade"
                 }
                }
        };
    }

    var store = jive.service.persistence();
    return store.find('exampleCarouselStore', { 'key': 'count' } ).then(function(found) {
        found = found.length > 0 ? found[0].count : parseInt(instance.config.startSequence, 10);

        store.save('exampleCarouselStore', 'count', {
            'key':'count',
            'count':found + 1
        }).then(function() {
            return jive.tiles.pushData(instance, getFormattedData(found));
        });
    }, function(err) {
        jive.logger.debug('Error encountered, push failed', err);
    });
}
Esempio n. 13
0
 function doWebhook(community,accessToken) {
     jive.webhooks.register(
             community,
             undefined,
             placeUri,
             jive.service.serviceURL() + '/webhooks',
             accessToken
         ).then(function (webhook) {
            console.log('Successfully created WebHook for Group['+placeUri+']');
         });
 } // end doWebhook
Esempio n. 14
0
            jive.community.find( { 'jiveCommunity' : jiveCommunity }, true).then( function(community) {

                if ( community && community['oauth'] && community['oauth']['access_token'] ) {
                    doWebhook( community['oauth']['access_token']);
                } else {
                    jive.service.persistence().find('tokens', {'ticket': ticketID }).then(function (found) {
                        var accessToken = found ? found[0]['accessToken']['access_token'] : undefined;
                        doWebhook( accessToken );
                    });
                }
            });
Esempio n. 15
0
exports.route = function(req, res) {
    var authStore = jive.service.persistence();
    var body = req.body;
    authStore.save('auth', body.viewer, {
        viewer: body.viewer
    }).then(function(response) {
            res.send({
                "written":true,
            }, 200);
        });
};
Esempio n. 16
0
exports.getPerformance = function() {
  var deferred = q.defer(),
      url = jive.service.serviceURL() + "/performanceservice/last";
  request.get({uri: url, timeout: 2500}, function(err, response, body) {
    if (err) {
      deferred.reject();
    } else {
      deferred.resolve(body);
    }
  });
  return deferred.promise;
}
Esempio n. 17
0
function processRegistration(context) {
    var db = jive.service.persistence();
    var licenseKey = jive.util.guid();
    var tenantID = context['tenantId'];

    // using tenantID as licenseKey table primary key
    db.save( 'licenseKey', tenantID, {
        'licenseKey' : licenseKey
    }).then( function() {
            jive.logger.info('Persisted license key', licenseKey, 'for tenantID', tenantID, '(', context['jiveUrl'], ')');
        });
}
Esempio n. 18
0
    function getAccessToken(profile) {
        var deferred = q.defer();

        jive.service.persistence().find('cloudalyticsTokens', { 'id' : profile }).then(
            function(found) {
                if (found && found.length == 1) {
                    deferred.resolve(found[0]['accessToken']);
                } else {
                    deferred.reject();
                } // end if
            } // end function
        );

        return deferred.promise;
    };
Esempio n. 19
0
    'route': function(req, res) {
        var raw = '<head> <link rel="stylesheet" type="text/css" href="' + jive.service.serviceURL() + '/stylesheets/style.css"></head>';
        raw += '<h1>Webhooked Activity</h1>';

        jive.util.fsexists('webhooks.log').then(function(exists){
            if ( !exists ) {
                res.writeHead(200, { 'Content-Type': 'text/html' });
                res.end( raw + "No data." );
            } else {
                jive.util.fsread('webhooks.log').then( function( data ) {
                    raw += data.toString();

                    res.writeHead(200, { 'Content-Type': 'text/html' });
                    res.end( raw );
                })
            }
        });
    }
Esempio n. 20
0
function processTileInstance(instance) {
    jive.logger.debug('running pusher for ', instance.name, 'instance', instance.id);

    function getFormattedData(count) {
        return {
            data: {
                "title": "Simple Counter",
                "contents": [
                    {
                        "text": "Current count: " + count,
                        "icon": "http://farm4.staticflickr.com/3136/5870956230_2d272d31fd_z.jpg",
                        "linkDescription": "Current counter."
                    }
                ],
                "config": {
                    "listStyle": "contentList"
                },
                "action": {
                    "text": "Add a Todo",
                    "context": {
                        "mode": "add"
                    }
                }
            }
        };
    }

    var store = jive.service.persistence();
    return store.find('exampleStore', {
        'key':'count'
    }).then(function(found) {
        found = found.length > 0 ? found[0].count : parseInt(instance.config.startSequence, 10);

        store.save('exampleStore', 'count', {
            'key':'count',
            'count':found+1
        }).then(function() {
            return jive.tiles.pushData(instance, getFormattedData(found));
        });
    }, function(err) {
        //some error
        jive.logger.debug('Error encountered, push failed', err);
    });
}
Esempio n. 21
0
/**
 * Handles actually pushing data to the tile instance
 * @param instance
 */
function processTileInstance(instance) {
    jive.logger.debug('running pusher for ', instance.name, 'instance', instance.id);

    // creates a data update structure
    function getFormattedData(count) {
        return {
            data: {
                "title": "Simple Counter",
                "contents": [
                    {
                        "text": "Current count: " + count,
                        "icon": "https://community.jivesoftware.com/servlet/JiveServlet/showImage/102-99994-1-1023036/j.png",
                        "linkDescription": "Current counter."
                    }
                ],
                "config": {
                    "listStyle": "contentList"
                },
                "action": {
                    "text": "Share State",
                    "context": {
                        "count": count
                    }
                }
            }
        };
    }

    var store = jive.service.persistence();
    return store.find('exampleStore', { 'key': 'count' } ).then(function(found) {
        found = found.length > 0 ? found[0].count : parseInt(instance.config.startSequence, 10);

        store.save('exampleStore', 'count', {
            'key':'count',
            'count':found + 1
        }).then(function() {
            return jive.tiles.pushData(instance, getFormattedData(found));
        });
    }, function(err) {
        jive.logger.debug('Error encountered, push failed', err);
    });
}
Esempio n. 22
0
exports.route = function(req, res) {
    var conf = jive.service.options;
    var cloudalyticsConf = jive.service.options['cloudalytics'];


    var profiles = [];
    for (var x in cloudalyticsConf['profiles']){
        profiles.push({
            id : cloudalyticsConf['profiles'][x]['id'],
            name : cloudalyticsConf['profiles'][x]['name']
            });
    } // end for x

    res.render('start.html',
        {
            host : jive.service.serviceURL(),
            profile :  profiles
        }
    );
};
Esempio n. 23
0
        'handler' : function(theInstance){
            var webhookCallback = jive.service.serviceURL() + '/webhooks';
            var jiveCommunity = theInstance['jiveCommunity'];

            var ticketID = theInstance['config']['ticketID'];

            function doWebhook(accessToken) {
                jive.webhooks.register(
                        jiveCommunity, undefined, theInstance['config']['parent'],
                        webhookCallback, accessToken
                    ).then(function (webhook) {
                        webhook['tileInstanceID'] = theInstance['id'];

                        var webhookEntity = webhook['entity'];
                        var webhookToSave = {
                            'object': webhookEntity['object'],
                            'events': webhookEntity['event'],
                            'callback': webhookEntity['callback'],
                            'url': webhookEntity['resources']['self']['ref'],
                            'id': webhookEntity['id'],
                            'tileInstanceID': theInstance['id']
                        };

                        jive.webhooks.save(webhookToSave);
                    });
            }
            jive.community.find( { 'jiveCommunity' : jiveCommunity }, true).then( function(community) {

                if ( community && community['oauth'] && community['oauth']['access_token'] ) {
                    doWebhook( community['oauth']['access_token']);
                } else {
                    jive.service.persistence().find('tokens', {'ticket': ticketID }).then(function (found) {
                        var accessToken = found ? found[0]['accessToken']['access_token'] : undefined;
                        doWebhook( accessToken );
                    });
                }


            });

        }
Esempio n. 24
0
function processTileInstance(instance) {
    jive.logger.debug('running pusher for ', instance.name, 'instance', instance.id);

    function getFormattedData(count) {
        return {
            data: {
                "title": "Simple Gallery",
                "contents": [
                    {
                        "image": jive.context.config.clientUrl + ":" +  jive.context.config.port + "/{{{TILE_NAME}}}/IMG_" + (count % maxImages) + ".jpg",
                        "title": "sample image " + (count % maxImages)
                    }, {
                        "image": jive.context.config.clientUrl + ":" +  jive.context.config.port + "/{{{TILE_NAME}}}/IMG_" + ((count + 1) % maxImages) + ".jpg",
                        "title": "sample image " + ((count + 1) % maxImages)
                    }
                ],
                "config": {
                    "listStyle": "contentList"
                }
            }
        };
    }

    var store = jive.service.persistence();
    return store.find('exampleStore', {
        'key':'count'
    }).then(function(found) {
        found = found.length > 0 ? found[0].count : 0;

        store.save('exampleStore', 'count', {
            'key':'count',
            'count':(found+1) % maxImages
        }).then(function() {
            return jive.tiles.pushData(instance, getFormattedData(found));
        });
    }, function(err) {
        //some error
        jive.logger.debug('Error encountered, push failed', err);
    });
}
Esempio n. 25
0
function pushUpdate(tile) {
    jive.logger.info('pushing update: '+ tile.name +', '+ tile.id );
    var filter   = tile.config.filter;
    var sort = tile.config.sort;
    var viewer = tile.config.viewer;
    var authStore = jive.service.persistence();
    authStore.find('auth', {
        'viewer':viewer
    }).then(function(found) {
        if (found.length > 0) {
            var user = found[0].user;
            var pass = found[0].pass;
            fetchData(filter, user, pass, sort, function(data, filterName) {
                prepareData(tile, data, function(prepared) {
                    jive.tiles.pushData(tile, { data: prepared });
                }, filterName);
            });
        } else {
            jive.logger.warn("could not find auth creds");
        }
    });
}
Esempio n. 26
0
var util = require('util');
var jive = require('jive-sdk');
var url = require('url');
var mustache = require('mustache');

var sdkInstance = require('jive-sdk/jive-sdk-service/routes/oauth');

var myOauth = Object.create(sdkInstance);

module.exports = myOauth;

var tokenStore = jive.service.persistence();

/////////////////////////////////////////////////////////////
// overrides jive-sdk/routes/oauth.js to do something useful,
// like storing access token for the viewer

myOauth.fetchOAuth2Conf = function() {
    return jive.service.options['oauth2-basecamp'];
};

myOauth.oauth2SuccessCallback = function( state, originServerAccessTokenResponse, callback ) {
    console.log('State', state);
    console.log('originServerAccessTokenResponse', originServerAccessTokenResponse);

    // response from Basecamp is  'access_token=XXXXXXXXX&refresh_token=YYYYYYYY&expires_in=ZZZZZZ'
    // these are all in the 'entity' object, there is no body part
    var accessToken=originServerAccessTokenResponse.entity.access_token;

    // note: we could also be saving refresh tokes and expires_in data ..
    tokenStore.save('tokens', state['viewerID'], {
Esempio n. 27
0
.then( function() { return jive.service.start() } ).then( startServer, failServer );
Esempio n. 28
0
.then( function() { return jive.service.autowire() } )
Esempio n. 29
0
        var server = http.createServer(app).listen( app.get('port') || 8090, app.get('hostname') || undefined, function () {
            console.log("Express server listening on " + server.address().address +':'+server.address().port);
        });
    }
};

///////////////////////////////////////////////////////////////////////////////////////////////////
// Setting up your service

//
// Service startup sequence (Easy as 1-2-3!):
//

// 1. initialize service setup -- optionally pass in a JSON configuration object or path to a configuration object;
// if one is not provided, it assumes that [app root]/jiveclientconfiguration.json file exists.
jive.service.init(app)

// 2. autowire all available definitions in /tiles; see explanation below.
.then( function() { return jive.service.autowire() } )

// 3. start the service, which performs sanity checks such as clientId, clientSecret, and clientUrl defined.
// if successful service start, call the start the http server function defined by you; otherwise call the
// fail one
.then( function() { return jive.service.start() } ).then( startServer, failServer );

///////////////////////////////////////////////////////////////////////////////////////////////////
// Below is an explanation of each step in the above sequence successful.

/*
====================
Step 1. Service Init
Esempio n. 30
0
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

/**
 * This code pushes data to a tile.  It creates a url that is a deep link into the app.
 */

var jive = require("jive-sdk" ),
    db = jive.service.persistence();


function processTileInstance(instance) {
    jive.logger.debug('running pusher for ', instance.name, 'instance', instance.id);

    var dataToPush = {
        data: {
            "title": "Open Todos",
            "contents": [

            ],
            "config": {
                "listStyle": "contentList"
            }
        }