Updated APIdoc + New API endpoint for user profile
Now you can access a user __public__ profile by querying the api endpoint /profile?id=USERID
Cette révision appartient à :
Parent
b5746d473f
révision
69123d53a9
8 fichiers modifiés avec 261 ajouts et 29 suppressions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "nyaapantsu",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "How to use the Nyaa Pantsu API",
|
||||
"title": "Nyaa Pantsu API documentation",
|
||||
"url": "https://nyaa.pantsu.cat/api",
|
||||
|
|
|
@ -3,7 +3,7 @@ define({ "api": [
|
|||
"type": "get",
|
||||
"url": "/search/",
|
||||
"title": "Search Torrents",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "FindTorrents",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -353,7 +353,7 @@ define({ "api": [
|
|||
"type": "get",
|
||||
"url": "/view/:id",
|
||||
"title": "Request Torrent information",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "GetTorrent",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -570,7 +570,7 @@ define({ "api": [
|
|||
"type": "get",
|
||||
"url": "/head/:id",
|
||||
"title": "Request Torrent Head",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "GetTorrentHead",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -622,7 +622,7 @@ define({ "api": [
|
|||
"type": "get",
|
||||
"url": "/",
|
||||
"title": "Request Torrents index",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "GetTorrents",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -699,7 +699,7 @@ define({ "api": [
|
|||
"type": "post",
|
||||
"url": "/update/",
|
||||
"title": "Update a Torrent",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "UpdateTorrent",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -853,7 +853,7 @@ define({ "api": [
|
|||
"type": "post",
|
||||
"url": "/upload",
|
||||
"title": "Upload a Torrent",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "UploadTorrent",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -1014,7 +1014,7 @@ define({ "api": [
|
|||
"type": "post",
|
||||
"url": "/login/",
|
||||
"title": "Login a user",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "Login",
|
||||
"group": "Users",
|
||||
"parameter": {
|
||||
|
@ -1107,5 +1107,96 @@ define({ "api": [
|
|||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "post",
|
||||
"url": "/profile/",
|
||||
"title": "Get a user profile",
|
||||
"version": "1.1.1",
|
||||
"name": "Profile",
|
||||
"group": "Users",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "Number",
|
||||
"optional": false,
|
||||
"field": "id",
|
||||
"description": "<p>User ID.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "Boolean",
|
||||
"optional": false,
|
||||
"field": "ok",
|
||||
"description": "<p>The request is done without failing</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "String[]",
|
||||
"optional": false,
|
||||
"field": "infos",
|
||||
"description": "<p>Messages information relative to the request</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "Object",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>The user object</p>"
|
||||
}
|
||||
]
|
||||
},
|
||||
"examples": [
|
||||
{
|
||||
"title": "Success-Response:",
|
||||
"content": " HTTP/1.1 200 OK\n\t\t{\n\t\t\tdata:\n \t\t[{\n\t\t\t\t\tuser_id:1,\n\t\t\t\t\tusername:\"username\",\n\t\t\t\t\tstatus:1,\n\t\t\t\t\tmd5:\"\",\n\t\t\t\t\tcreated_at:\"date\",\n\t\t\t\t\tliking_count:0,\n\t\t\t\t\tliked_count:0\n\t\t\t\t}],\n\t\t\tinfos: [\"Logged\", ... ],\n\t\t\tok:true\n\t\t}",
|
||||
"type": "json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"filename": "controllers/api/api.go",
|
||||
"groupTitle": "Users",
|
||||
"error": {
|
||||
"fields": {
|
||||
"Error 4xx": [
|
||||
{
|
||||
"group": "Error 4xx",
|
||||
"type": "Boolean",
|
||||
"optional": false,
|
||||
"field": "ok",
|
||||
"description": "<p>The request couldn't be done due to some errors.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Error 4xx",
|
||||
"type": "String[]",
|
||||
"optional": false,
|
||||
"field": "errors",
|
||||
"description": "<p>List of errors messages.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Error 4xx",
|
||||
"type": "Object[]",
|
||||
"optional": false,
|
||||
"field": "all_errors",
|
||||
"description": "<p>List of errors object messages for each wrong field</p>"
|
||||
}
|
||||
]
|
||||
},
|
||||
"examples": [
|
||||
{
|
||||
"title": "Error-Response:",
|
||||
"content": " HTTP/1.1 200 OK\n {\n \"ok\": false,\n \"errors\": [ ... ]\n \"all_errors\": {\n\t\t \t\"username\": [ ... ],\n }\n }",
|
||||
"type": "json"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
] });
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"type": "get",
|
||||
"url": "/search/",
|
||||
"title": "Search Torrents",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "FindTorrents",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -353,7 +353,7 @@
|
|||
"type": "get",
|
||||
"url": "/view/:id",
|
||||
"title": "Request Torrent information",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "GetTorrent",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -570,7 +570,7 @@
|
|||
"type": "get",
|
||||
"url": "/head/:id",
|
||||
"title": "Request Torrent Head",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "GetTorrentHead",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -622,7 +622,7 @@
|
|||
"type": "get",
|
||||
"url": "/",
|
||||
"title": "Request Torrents index",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "GetTorrents",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -699,7 +699,7 @@
|
|||
"type": "post",
|
||||
"url": "/update/",
|
||||
"title": "Update a Torrent",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "UpdateTorrent",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -853,7 +853,7 @@
|
|||
"type": "post",
|
||||
"url": "/upload",
|
||||
"title": "Upload a Torrent",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "UploadTorrent",
|
||||
"group": "Torrents",
|
||||
"parameter": {
|
||||
|
@ -1014,7 +1014,7 @@
|
|||
"type": "post",
|
||||
"url": "/login/",
|
||||
"title": "Login a user",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"name": "Login",
|
||||
"group": "Users",
|
||||
"parameter": {
|
||||
|
@ -1107,5 +1107,96 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "post",
|
||||
"url": "/profile/",
|
||||
"title": "Get a user profile",
|
||||
"version": "1.1.1",
|
||||
"name": "Profile",
|
||||
"group": "Users",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "Number",
|
||||
"optional": false,
|
||||
"field": "id",
|
||||
"description": "<p>User ID.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "Boolean",
|
||||
"optional": false,
|
||||
"field": "ok",
|
||||
"description": "<p>The request is done without failing</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "String[]",
|
||||
"optional": false,
|
||||
"field": "infos",
|
||||
"description": "<p>Messages information relative to the request</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "Object",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>The user object</p>"
|
||||
}
|
||||
]
|
||||
},
|
||||
"examples": [
|
||||
{
|
||||
"title": "Success-Response:",
|
||||
"content": " HTTP/1.1 200 OK\n\t\t{\n\t\t\tdata:\n \t\t[{\n\t\t\t\t\tuser_id:1,\n\t\t\t\t\tusername:\"username\",\n\t\t\t\t\tstatus:1,\n\t\t\t\t\tmd5:\"\",\n\t\t\t\t\tcreated_at:\"date\",\n\t\t\t\t\tliking_count:0,\n\t\t\t\t\tliked_count:0\n\t\t\t\t}],\n\t\t\tinfos: [\"Logged\", ... ],\n\t\t\tok:true\n\t\t}",
|
||||
"type": "json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"filename": "controllers/api/api.go",
|
||||
"groupTitle": "Users",
|
||||
"error": {
|
||||
"fields": {
|
||||
"Error 4xx": [
|
||||
{
|
||||
"group": "Error 4xx",
|
||||
"type": "Boolean",
|
||||
"optional": false,
|
||||
"field": "ok",
|
||||
"description": "<p>The request couldn't be done due to some errors.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Error 4xx",
|
||||
"type": "String[]",
|
||||
"optional": false,
|
||||
"field": "errors",
|
||||
"description": "<p>List of errors messages.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Error 4xx",
|
||||
"type": "Object[]",
|
||||
"optional": false,
|
||||
"field": "all_errors",
|
||||
"description": "<p>List of errors object messages for each wrong field</p>"
|
||||
}
|
||||
]
|
||||
},
|
||||
"examples": [
|
||||
{
|
||||
"title": "Error-Response:",
|
||||
"content": " HTTP/1.1 200 OK\n {\n \"ok\": false,\n \"errors\": [ ... ]\n \"all_errors\": {\n\t\t \t\"username\": [ ... ],\n }\n }",
|
||||
"type": "json"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
define({
|
||||
"name": "nyaapantsu",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "How to use the Nyaa Pantsu API",
|
||||
"title": "Nyaa Pantsu API documentation",
|
||||
"url": "https://nyaa.pantsu.cat/api",
|
||||
|
@ -26,7 +26,7 @@ define({
|
|||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2017-07-20T21:04:54.468Z",
|
||||
"time": "2017-07-22T15:20:08.679Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "nyaapantsu",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "How to use the Nyaa Pantsu API",
|
||||
"title": "Nyaa Pantsu API documentation",
|
||||
"url": "https://nyaa.pantsu.cat/api",
|
||||
|
@ -26,7 +26,7 @@
|
|||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2017-07-20T21:04:54.468Z",
|
||||
"time": "2017-07-22T15:20:08.679Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
|
||||
/**
|
||||
* @apiDefine NotFoundError
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiError {String[]} errors List of errors messages with a 404 error message in it.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
|
@ -38,7 +38,7 @@ import (
|
|||
*/
|
||||
/**
|
||||
* @apiDefine RequestError
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiError {Boolean} ok The request couldn't be done due to some errors.
|
||||
* @apiError {String[]} errors List of errors messages.
|
||||
* @apiError {Object[]} all_errors List of errors object messages for each wrong field
|
||||
|
@ -56,7 +56,7 @@ import (
|
|||
|
||||
/**
|
||||
* @api {get} / Request Torrents index
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiName GetTorrents
|
||||
* @apiGroup Torrents
|
||||
*
|
||||
|
@ -89,7 +89,7 @@ func APIHandler(c *gin.Context) {
|
|||
|
||||
/**
|
||||
* @api {get} /view/:id Request Torrent information
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiName GetTorrent
|
||||
* @apiGroup Torrents
|
||||
*
|
||||
|
@ -179,7 +179,7 @@ func APIViewHandler(c *gin.Context) {
|
|||
|
||||
/**
|
||||
* @api {get} /head/:id Request Torrent Head
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiName GetTorrentHead
|
||||
* @apiGroup Torrents
|
||||
*
|
||||
|
@ -211,7 +211,7 @@ func APIViewHeadHandler(c *gin.Context) {
|
|||
|
||||
/**
|
||||
* @api {post} /upload Upload a Torrent
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiName UploadTorrent
|
||||
* @apiGroup Torrents
|
||||
*
|
||||
|
@ -298,7 +298,7 @@ func APIUploadHandler(c *gin.Context) {
|
|||
|
||||
/**
|
||||
* @api {post} /update/ Update a Torrent
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiName UpdateTorrent
|
||||
* @apiGroup Torrents
|
||||
*
|
||||
|
@ -368,7 +368,7 @@ func APIUpdateHandler(c *gin.Context) {
|
|||
|
||||
/**
|
||||
* @api {get} /search/ Search Torrents
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiName FindTorrents
|
||||
* @apiGroup Torrents
|
||||
*
|
||||
|
@ -453,7 +453,7 @@ func APISearchHandler(c *gin.Context) {
|
|||
|
||||
/**
|
||||
* @api {post} /login/ Login a user
|
||||
* @apiVersion 1.1.0
|
||||
* @apiVersion 1.1.1
|
||||
* @apiName Login
|
||||
* @apiGroup Users
|
||||
*
|
||||
|
@ -510,6 +510,55 @@ func APILoginHandler(c *gin.Context) {
|
|||
apiResponseHandler(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /profile/ Get a user profile
|
||||
* @apiVersion 1.1.1
|
||||
* @apiName Profile
|
||||
* @apiGroup Users
|
||||
*
|
||||
* @apiParam {Number} id User ID.
|
||||
*
|
||||
* @apiSuccess {Boolean} ok The request is done without failing
|
||||
* @apiSuccess {String[]} infos Messages information relative to the request
|
||||
* @apiSuccess {Object} data The user object
|
||||
*
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* data:
|
||||
* [{
|
||||
* user_id:1,
|
||||
* username:"username",
|
||||
* status:1,
|
||||
* md5:"",
|
||||
* created_at:"date",
|
||||
* liking_count:0,
|
||||
* liked_count:0
|
||||
* }],
|
||||
* infos: ["Logged", ... ],
|
||||
* ok:true
|
||||
* }
|
||||
*
|
||||
* @apiUse RequestError
|
||||
*/
|
||||
// APIProfileHandler : Get a public profile with API
|
||||
func APIProfileHandler(c *gin.Context) {
|
||||
c.Header("Content-Type", "application/json")
|
||||
messages := msg.GetMessages(c)
|
||||
id, err := strconv.ParseUint(c.Query("id"), 10, 32)
|
||||
if err != nil {
|
||||
id = 0
|
||||
}
|
||||
user, _, errorUser := users.FindByID(uint(id))
|
||||
if errorUser == nil {
|
||||
user.APIToken = "" // We erase apitoken from public profile
|
||||
apiResponseHandler(c, user.ToJSON())
|
||||
return
|
||||
}
|
||||
messages.Error(errorUser)
|
||||
apiResponseHandler(c)
|
||||
}
|
||||
|
||||
// APIRefreshTokenHandler : Refresh Token with API
|
||||
func APIRefreshTokenHandler(c *gin.Context) {
|
||||
c.Header("Content-Type", "application/json")
|
||||
|
|
|
@ -11,6 +11,7 @@ func init() {
|
|||
api.HEAD("/view/:id", APIViewHeadHandler)
|
||||
api.POST("/upload", APIUploadHandler)
|
||||
api.POST("/login", APILoginHandler)
|
||||
api.GET("/profile", APIProfileHandler)
|
||||
api.GET("/token/check", APICheckTokenHandler)
|
||||
api.GET("/token/refresh", APIRefreshTokenHandler)
|
||||
api.Any("/search", APISearchHandler)
|
||||
|
|
|
@ -63,7 +63,7 @@ type UserJSON struct {
|
|||
ID uint `json:"user_id"`
|
||||
Username string `json:"username"`
|
||||
Status int `json:"status"`
|
||||
APIToken string `json:"token"`
|
||||
APIToken string `json:"token,omitempty"`
|
||||
MD5 string `json:"md5"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
LikingCount int `json:"liking_count"`
|
||||
|
|
Référencer dans un nouveau ticket