Created
October 26, 2011 17:58
-
-
Save adamkirkwood/1317157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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