Skip to content

Instantly share code, notes, and snippets.

@adamkirkwood
Created October 26, 2011 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamkirkwood/1317157 to your computer and use it in GitHub Desktop.
Save adamkirkwood/1317157 to your computer and use it in GitHub Desktop.
MOCHIGAMES.namespace(MOCHIGAMES, 'GameRating');
MOCHIGAMES.GameRating = (function(parent, $) {
var Settings = {
base: window.location.origin,
endpoint: 'api/v1/usergamerating'
};
var Game = {
user_rating: null,
community_rating: null,
slug: null,
name: null
};
var Rating = {};
Rating.get = function() {
$.ajax({
url: [Settings.base, '/', Settings.endpoint, '/', Game.slug, '/'].join(''),
type: 'GET',
data: {'format': 'json'},
success: function(data) {
console.log(data);
}
});
};
Rating.post = function() {
$.ajax({
url: [Settings.base, '/', Settings.endpoint, '/', Game.slug, '/'].join(''),
type: 'POST',
contentType: 'application/json',
data: '{"rating": "4", "name": "' + Game.name + '"}',
beforeSend: function() {
console.log(this.url);
console.log(this.data);
},
success: function(data) {
console.log(data);
}
});
};
var init = function() {
// retrieve user's session cookie value
// check if the user has rated this game
// retrieve community rating for game if not rated by user
Game.slug = _game_slug;
Game.name = _game_name;
};
return {
init: init,
settings: Settings,
rating: Rating,
game: Game
};
})(MOCHIGAMES || {}, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment