-
Notifications
You must be signed in to change notification settings - Fork 0
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."
}return all channel
- type: UNSUBSCRIBE = 0, CREATER = 1, SUBSCRIBE = 2
// 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() {
/* ... */
});{
"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"
}
]
}new channel
- name
// 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() {
/* ... */
});{
"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"
}
}return all users in the channel
// 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() {
/* ... */
});{
"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"
}
}join channel / exit channel
- action (0 for join and 1 for exit)
// 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() {
/* ... */
});{
"ret": 20,
"msg": "join channel fail."
}{
"ret": 20,
"msg": "exit channel fail."
}{
"ret": 0,
"msg": "ok."
}