Merge: Mock Github API tests
[nit.git] / contrib / nitrpg / src / game.nit
index 9b550c3..5413f43 100644 (file)
@@ -42,10 +42,10 @@ interface GameEntity
        fun key: String is abstract
 
        # Saves `self` in db.
-       fun save do game.db.collection(collection_name).save(to_json)
+       fun save do game.db.collection(collection_name).save(to_json_object)
 
        # Json representation of `self`.
-       fun to_json: JsonObject do
+       fun to_json_object: JsonObject do
                var json = new JsonObject
                json["_id"] = key
                return json
@@ -75,7 +75,7 @@ class Game
        redef var key = name is lazy
 
        # Mongo server url where this game data are stored.
-       var mongo_url = "mongodb://localhost:27017" is writable
+       var mongo_url = "mongodb://mongo:27017" is writable
 
        # Mongo db client.
        var client = new MongoClient(mongo_url) is lazy
@@ -89,7 +89,8 @@ class Game
        redef var collection_name = "games"
 
        # Init the Game and try to load saved data.
-       init do
+       init from_mongo(api: GithubAPI, repo: Repo) do
+               init(api, repo)
                var req = new JsonObject
                req["name"] = repo.full_name
                var res = db.collection("games").find(req)
@@ -101,7 +102,7 @@ class Game
        # Used to load entities from saved data.
        fun from_json(json: JsonObject) do end
 
-       redef fun to_json do
+       redef fun to_json_object do
                var json = super
                json["name"] = name
                return json
@@ -165,7 +166,7 @@ class Game
        end
 
        # Erase all saved data for this game.
-       fun clear do db.collection(collection_name).remove(to_json)
+       fun clear do db.collection(collection_name).remove(to_json_object)
 
        # Verbosity level used fo stdout.
        #
@@ -231,11 +232,11 @@ class Player
        #
        # Used to load players from saved data.
        init from_json(game: Game, json: JsonObject) do
-               init(game, json["name"].to_s)
+               init(game, json["name"].as(String))
                nitcoins = json["nitcoins"].as(Int)
        end
 
-       redef fun to_json do
+       redef fun to_json_object do
                var json = super
                json["game"] = game.key
                json["name"] = name