Skip to content
Ahmed Castro edited this page Apr 12, 2016 · 33 revisions

Javascript games API

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

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("http://kusuk.in/api/v1/progress/save",{"course_id":1,progress:{"current_question":current_question},user_email: game.authentication_params['user_email'], user_token: game.authentication_params['user_token']},
    function(data)
    {
      console.log(data)
      console.log("Stored the current question in Kusukin: "+current_question);
    })

get_progress

Overview

This method 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("http://kusuk.in/api/v1/achievements/", {id:authentication_params["user_id"], user_email:authentication_params["user_email"], user_token:authentication_params["user_token"] },
      function(data)
        {
          console.log(data);
        }
      })

unlock_achievement

A post method that unlocks 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("http://kusuk.in/api/v1/achievements/unlock",{achievement_id: 15},
    function(data)
    {
      console.log(data["errors"])
    })

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_achievements

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.

###Parameters

  • email User's email

###Returns

  • achievements[]

    • id Achievement's id

    • name Achievement's name

    • description Achievement's description

    • icon Achievement's icon image in the PNG format

###Call Example

    $.get("http://kusuk.in/javascript_api/get_achievements", 
         {"email":"user@email.com"},
         function(data)
		 {
		   console.log(data)
		 })

###Return example

    {"achievements":
      [{"id":1,
      "name":"Complete the first level!",
      "description":"Congratulations! Keep on going and you'll become a Rockstar in no time!",
      "icon":"/attachments/16f075587e02329783c6330aac608866ce532a83/store/0f2b660a86423b3187d05f0abf0802a259a05b3cc36f30859b8239091d62/icon.png"
      },
      {"id":2,
        "name":"Complete 5 levels!",
        "description":"Keep up the good work!",
      "icon":"/attachments/4718fc5de919f85634e52e75fd7d0fccafedfb46/store/c3d4b8e552f7c9deb0371b2925acfe67a7eb95f5bac3ff12e8ba063997b0/icon.png"
      },
      {"id":3,
        "name":"Complete all the levels!",
        "description":"You are the true master now.",
      "icon":"/attachments/5d0f69b779ad528896144fb141104c1369841c76/store/385cff9793dc2412f3b46fc445beee97b98981d76df0acad977651704f3f/icon.png"
      }
      ]
    }

get_course

Description

A get method that retrieves data related to a given course.

###Parameters

  • course_id: Course's numeric id provided by the Kusuk.in website web you create it.

###Returns

  • name Course's name

  • description Course's name

  • achievements[]

    • id Achievement's id

    • name Achievement's name

    • description Achievement's description

    • icon Achievement's icon image in the PNG format

  • sections[]

    • id Section's id

    • name Section's name

    • video_url Youtube's video link

    • content Section content in the Markdown format

###Call Example

    $.get("http://kusuk.in/api/v1/achievements/", {id:authentication_params["user_id"], user_email:authentication_params["user_email"], user_token:authentication_params["user_token"] },
      function(data)
        {
          console.log(data);
        }
      })

###Return Example

http://kusuk.in/javascript_api/get_course?course_id=8

Clone this wiki locally