Skip to content

Instantly share code, notes, and snippets.

@emckean
Created January 3, 2014 19:22
Show Gist options
  • Save emckean/8244627 to your computer and use it in GitHub Desktop.
Save emckean/8244627 to your computer and use it in GitHub Desktop.
word view code
function addWordView() {
var checkSession = session.checkSessionCookie(req, res);
var encodedWord = encodeURI(req.params.word);
encodedWord = encodedWord.replace(/ /g, "%20");
userAgent = encodeURI(req.headers['user-agent']);
placeholderServerID = "1.2.3.4";
var url = config.apiServer+'word.json/'+encodedWord+'/wordView?userGuid=0&userAgent='+userAgent+'&serverIp='+placeholderServerID+'&api_key=' + config.apiKey;
var postObj = {};
postObj.userGuid = "0";
postObj.word = encodedWord;
postObj.userAgent = req.headers['user-agent'];
if(checkSession.loggedIn) {
tools.getUserId(checkSession.username, function(argument, userID) {
urlUserId = userID;
var url = config.apiServer+'word.json/'+encodedWord+'/wordView?userId='+urlUserId+'&userGuid=0&userAgent='+userAgent+'&serverIp='+placeholderServerID+'&api_key=' + config.apiKey;
request.post({
headers: {'content-type' : 'application/json'},
url: url,
body: JSON.stringify(postObj)
}, function(error, response, body){
if (!error && response.statusCode == 200) {
viewSuccess = response.body;
} else {
console.log(error);
}
})
})
} else {
request.post({
headers: {'content-type' : 'application/json'},
url: url,
body: JSON.stringify(postObj)
}, function(error, response, body){
if (!error && response.statusCode == 200) {
viewSuccess = response.body;
} else {
console.log(error);
}
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment