Skip to content

API Channel

Terry Chan edited this page Dec 13, 2016 · 6 revisions

This API need token otherwise it will return token invalid error.

{
  "ret": 10,
  "msg": "token invalid."
}

/api/channel?token={token}

GET

return all channel

url parameter

  • type: UNSUBSCRIBE = 0, CREATER = 1, SUBSCRIBE = 2

jQuery example

// Get Channels (GET http://api.sysu.space/api/channel)

jQuery.ajax({
    url: "http://api.sysu.space/api/channel",
    type: "GET",
    data: {
        "token": "22b1a163b07c80c6991eb2c5ce76627",
        "type": "0",
    },
    headers: {
        "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
    },
})
.done(function(data, textStatus, jqXHR) {
    console.log("HTTP Request Succeeded: " + jqXHR.status);
    console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
    console.log("HTTP Request Failed");
})
.always(function() {
    /* ... */
});

return type

{
  "ret": 0,
  "msg": "ok.",
  "channels": [
    {
      "id": 166,
      "type": 0,
      "name": "naminamiting",
      "last_update": "2016-12-08 03:17:41.0"
    },
    {
      "id": 156,
      "type": 0,
      "name": "channels",
      "last_update": "2016-12-03 03:29:44.0"
    },
    {
      "id": 157,
      "type": 0,
      "name": "Cieo,test",
      "last_update": "2016-12-03 03:29:44.0"
    },
    {
      "id": 162,
      "type": 0,
      "name": "ChannelTest",
      "last_update": "2016-12-03 03:29:44.0"
    },
    {
      "id": 79,
      "type": 0,
      "name": "I Have Money!",
      "last_update": "2016-11-28 09:46:12.0"
    },
    {
      "id": 81,
      "type": 0,
      "name": "AI",
      "last_update": "2016-11-28 09:46:12.0"
    },
    {
      "id": 76,
      "type": 0,
      "name": "hello world",
      "last_update": "2016-11-27 10:30:38.0"
    }
  ]
}

POST

new channel

form url-encoded parameter

  • name

jQuery example

// New Channel (POST http://api.sysu.space/api/channel)

jQuery.ajax({
    url: "http://api.sysu.space/api/channel?" + jQuery.param({
        "token": "22b1a163b07c80c6991eb2c5ce76627",
    }),
    type: "POST",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
    },
    contentType: "application/x-www-form-urlencoded",
    data: {
        "name": "naminamiting",
    },
})
.done(function(data, textStatus, jqXHR) {
    console.log("HTTP Request Succeeded: " + jqXHR.status);
    console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
    console.log("HTTP Request Failed");
})
.always(function() {
    /* ... */
});

return type

{
  "ret": 1,
  "msg": "channel name duplicated error."
}
{
  "ret": 0,
  "msg": "ok.",
  "channel": {
    "id": 166,
    "type": 1,
    "name": "naminamiting",
    "last_update": "2016-12-08 03:17:41"
  }
}

/api/channel/{id}?token={token}

GET

return all users in the channel

jQuery example

// New Channel (GET https://api.sysu.space/api/channel/168)

jQuery.ajax({
    url: "https://api.sysu.space/api/channel/168",
    type: "GET",
    data: {
        "token": "fc2720696af9f4478564adab92146017",
    },
})
.done(function(data, textStatus, jqXHR) {
    console.log("HTTP Request Succeeded: " + jqXHR.status);
    console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
    console.log("HTTP Request Failed");
})
.always(function() {
    /* ... */
});

return type

{
  "ret": 0,
  "msg": "ok.",
  "users": [
    {
      "id": 63,
      "expiry_time": 0,
      "username": "terry"
    },
    {
      "id": 68,
      "expiry_time": 0,
      "username": "wodexiaohao"
    }
  ],
  "user": {
    "id": 63,
    "expiry_time": 278732,
    "username": "terry"
  }
}
{
  "ret": 11,
  "msg": "permission deny.",
  "user": {
    "id": 63,
    "expiry_time": 278746,
    "username": "terry"
  }
}

POST

join channel / exit channel

form url-encoded parameter

  • action (0 for join and 1 for exit)

jQuery example

// Join Channel (POST http://api.sysu.space/api/channel/81)

jQuery.ajax({
    url: "http://api.sysu.space/api/channel/81?" + jQuery.param({
        "token": "3290ea5260335da58f5f221cd6302ace",
    }),
    type: "POST",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
    },
    contentType: "application/x-www-form-urlencoded",
    data: {
        "action": "0",
    },
})
.done(function(data, textStatus, jqXHR) {
    console.log("HTTP Request Succeeded: " + jqXHR.status);
    console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
    console.log("HTTP Request Failed");
})
.always(function() {
    /* ... */
});

return type

{
  "ret": 20,
  "msg": "join channel fail."
}
{
  "ret": 20,
  "msg": "exit channel fail."
}
{
  "ret": 0,
  "msg": "ok."
}

Clone this wiki locally