Skip to content
Ahmed Castro edited this page Mar 9, 2016 · 22 revisions

Javascript games API

This Section is for the methods needed by the javascript game integration: save_progress, get_progress and unlock_achievement. This methods will be used firstly by Guco, but in the future will be integrated with more games.

save_progress

Overview

This method stores user data for each game such as progress, preferences, scores etc... It works in synergy with get_progress which can retrieve later (in other session for example) the data that save_progress stored.

Description

A post method that stores a JSON data for each course section for each user.

Parameters

  • Json user data to be stored

Returns

  • Error array if any

Example

  $.post("/javascript_api/save_progress",{progress{"player1_wins":game.player1_wins,"player2_wins":game.player2_wins},
    function(data)
    {
      console.log(data["error"])
    })

get_progress

Overview

This method retrieves the data previously stored by save_progress. It will usually be invoked when the game starts so all the progress is reestablished, the user preferences set, the previous scores displayed etc...

Description

A get method that retrieves the data previously stored by the save_progress method. The data is returned in a JSON map format.

###Parameters

None

###Returns

  • Json progress previously stored

  • Error array if any

Example

    $.get("/javascript_api/get_progress",
      function(data)
      {
        game.player1_wins=data["player1_wins"]
        game.player2_wins=data["player2_wins"]
      })

unblock_achievement

A post method that unblocks an achievement for the current user. The achievements will be previously defined in the Kusukin platform by the course creators.

###Parameters

  • Achievement id

###Returns

  • Error array if any

###Example

  $.post("/javascript_api/unblock_achievement",{achievement_id: 15},
    function(data)
    {
      console.log(data["error"])
    })

General purpose API

This API will be used by other apps such as websites or mobile apps to communicate with Kusukin. Coral will be first organization to use this API but other organizations may also use it in the future.

get_achievemnts

Overview

This method will be firstly used by a mobile app that is currently being developed by Coral. The app purpose is to take courses and see the achievements in a smartphone or tablet.

Description

A get method that retrieves the and array of all the achievements unlocked by an user in a given course.

###Parameters

  • User id

  • Course id

###Returns

  • Achievment list

  • Error array if any

###Example

    $.get("/javascript_api/get_achievements", {user_id: user_id},
      function(data)
      {
        game.player1_wins=data["player1_wins"]
        game.player2_wins=data["player2_wins"]
      })
Clone this wiki locally