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.

##Sign_in

Example

    $.post("http:kusuk.in/api/v1/users/sign_in",{user:{email:"admin@admin.com", password:"admin1234"}},
    function(data)
    {
      console.log(data);
    })

Return example

    {user: Object, status: "ok", authentication_token: "m5Jb13z871Hqxd_BZk2_"}

progress/save

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:{"Score":2500},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);
    })

Return example

{"progress":"{\"Score\":\"2500\"}","status":"success"}

progress/get

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/progress/get",{"course_id":1, user_email: game.authentication_params['user_email'], user_token: game.authentication_params['user_token']},
      function(data)
      {
        console.log(data);
      })

Return example

{"progress":"{\"Score\":\"2500\"}"}

achievements/unlock

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:1,user_email:"admin@admin.com", user_token:"m5Jb13z871Hqxd_BZk2_"},
  function(data)
  {
    console.log(data)
  })

###Return

{"status":"success",
  "achievement":
  {
    "id":1, "course_id":1, "created_at":"2016-03-28T21:49:48.553Z", "updated_at":"2016-03-29T19:18:09.871Z", "name":"You got mail", "description":"Testa", "icon_id":"d1d810e6a412e476570fb7b9c69a348d09b013a54276bc143ddb1f6ee467"
  }
}

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/api/v1/achievements",{email:"admin@admin.com", id:1,user_email:"admin@admin.com", user_token:"m5Jb13z871Hqxd_BZk2_"},
      function(data)
      {
        console.log(data)
      })

###Return example {"achievements": [ { "id":1,"name":"First achievement!", "description":"You completed 5 levels", "icon":"/attachments/08c0016689239315ed81cc09dfb16f81e02ce043/store/d1d810e6a412e476570fb7b9c69a348d09b013a54276bc143ddb1f6ee467/icon.png" }, { "id":2,"name":"Second achievement!", "description":"You completed 10 levels", "icon":"/attachments/08c0016689239315ed81cc09dfb16f81e02ce043/store/d1d810e6a412e476570fb7b9c69a348d09b013a54276bc143ddb1f6ee467/icon2.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/courses/get",{course_id:1,user_email:"admin@admin.com", user_token:"m5Jb13z871Hqxd_BZk2_"},
  function(data)
  {
    console.log(data)
  })

###Return Example

{"course":{"id":1,"name":"Rails for dummies","description":"Testing","category_id":null,"created_at":"2016-03-28T19:03:01.724Z","updated_at":"2016-03-28T19:03:01.724Z","image_uid":null,"user_id":1,"github_clone_link":null},"achievements":[{"course_id":1,"id":1,"created_at":"2016-03-28T21:49:48.553Z","updated_at":"2016-03-29T19:18:09.871Z","name":"You got mail","description":"Testa","icon_id":"d1d810e6a412e476570fb7b9c69a348d09b013a54276bc143ddb1f6ee467"},{"course_id":1,"id":2,"created_at":"2016-04-12T19:47:03.854Z","updated_at":"2016-04-12T19:47:03.854Z","name":"A2","description":"fdsa","icon_id":"a3cab4f7016789d8520bff166baf7317ddc5f5280c4922a8b58c9f1711de"}],"sections":[{"course_id":1,"id":1,"number":1,"videourl":"https://www.youtube.com/v/8I539U5lXWY","content":null,"created_at":"2016-03-28T19:03:01.798Z","updated_at":"2016-03-28T19:03:01.798Z","title":"Install ruby on rails","homework_description":null,"price":null},{"course_id":1,"id":2,"number":2,"videourl":"https://www.youtube.com/v/f9G-W8RLuJ4","content":null,"created_at":"2016-03-28T19:03:01.805Z","updated_at":"2016-03-28T19:03:01.805Z","title":"Arithmetic Operators","homework_description":null,"price":null},{"course_id":1,"id":3,"number":3,"videourl":"https://www.youtube.com/v/JdCyLqmoxOg","content":null,"created_at":"2016-03-28T19:03:01.814Z","updated_at":"2016-03-28T19:03:01.814Z","title":"if - else - elsif","homework_description":null,"price":null}]}