api.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. /**
  3. * API structure definition.
  4. *
  5. * Provides the API structure to define the help page.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. * @category API
  11. */
  12. /**
  13. * @var mixed[] $API API help structure.
  14. */
  15. $API = [
  16. "version" => 1,
  17. "category" => [
  18. [ // BEGIN CATEGORY Units
  19. "name" => "Units",
  20. "command" => [
  21. [ // BEGIN COMMAND Units
  22. "name" => "units",
  23. "method" => [
  24. [
  25. "id" => "GET",
  26. "url" => "/units/",
  27. "description" => "Retrieves units.",
  28. "parameters" => [
  29. [
  30. "key" => "page",
  31. "via" => "request",
  32. "type" => "int",
  33. "description" => "Page to fetch. Deaults to 1.",
  34. "optional" => true
  35. ],
  36. [
  37. "key" => "per_page",
  38. "via" => "request",
  39. "type" => "int",
  40. "description" => "number of results per page. Defaults to 30, maximum is 100.",
  41. "optional" => true
  42. ],
  43. [
  44. "key" => "name",
  45. "via" => "request",
  46. "type" => "string",
  47. "description" => "Filter units with this in their name. Case insensitive.",
  48. "optional" => true
  49. ]
  50. ],
  51. "responses" => [
  52. [
  53. "status" => "200",
  54. "message" => "Success.",
  55. "description" => null,
  56. "example" => null,
  57. ],
  58. ]
  59. ],
  60. [
  61. "id" => "GET",
  62. "url" => "/units/{id}/",
  63. "description" => "Retrieves a unit info.",
  64. "parameters" => [
  65. [
  66. "key" => "{id}",
  67. "via" => "query",
  68. "type" => "string",
  69. "description" => "Unit ID.",
  70. "optional" => false
  71. ],
  72. ],
  73. "responses" => [
  74. [
  75. "status" => "200",
  76. "message" => "Success.",
  77. "description" => null,
  78. "example" => null,
  79. ],
  80. [
  81. "status" => "404",
  82. "message" => "Unit not found.",
  83. "description" => "The requested unit does not exist.",
  84. "example" => null
  85. ]
  86. ]
  87. ],
  88. ],
  89. ] // END COMMAND profile
  90. ]
  91. ], // END CATEGORY Units
  92. [ // BEGIN CATEGORY Profile
  93. "name" => "Profile",
  94. "command" => [
  95. [ // BEGIN COMMAND UploadProfile
  96. "name" => "profile",
  97. "method" => [
  98. [
  99. "id" => "GET",
  100. "url" => "/profile/{id}/",
  101. "description" => "Retrieves player profile.",
  102. "parameters" => [
  103. [
  104. "key" => "{id}",
  105. "via" => "query",
  106. "type" => "string",
  107. "description" => "Player ID or name.",
  108. "optional" => false
  109. ],
  110. [
  111. "key" => "key",
  112. "via" => "body",
  113. "type" => "string",
  114. "description" => "API key. Required for private profiles.",
  115. "optional" => true
  116. ]
  117. ],
  118. "responses" => [
  119. [
  120. "status" => "200",
  121. "message" => "Success.",
  122. "description" => null,
  123. "example" => json_encode('{"username":"IValentin","level":50,"public":"1"}', JSON_PRETTY_PRINT),
  124. ],
  125. [
  126. "status" => "403",
  127. "message" => "A list of profiles cant be retrieved. Please specify a profile ID or player name.",
  128. "description" => "No player ID or name has been supplied. A full list of profiles is not available.",
  129. "example" => null
  130. ],
  131. [
  132. "status" => "403",
  133. "message" => "The profile is not public.",
  134. "description" => "The requestd player profile is private, and the API key has not been sent or it's invalid.",
  135. "example" => null
  136. ],
  137. [
  138. "status" => "404",
  139. "message" => "Player not found.",
  140. "description" => "The requestd player is not registered in SWDB.",
  141. "example" => null
  142. ]
  143. ]
  144. ],
  145. [
  146. "id" => "POST",
  147. "url" => "/profile/{id}/",
  148. "description" => "Creates a new player profile.",
  149. "parameters" => [
  150. [
  151. "key" => "{id}",
  152. "via" => "query",
  153. "type" => "string",
  154. "description" => "Player ID.",
  155. "optional" => false
  156. ],
  157. [
  158. "key" => "email",
  159. "via" => "body",
  160. "type" => "string",
  161. "description" => "User email. Must be a valid address.",
  162. "optional" => false
  163. ],
  164. [
  165. "key" => "password",
  166. "via" => "body",
  167. "type" => "string",
  168. "description" => "New user password.",
  169. "optional" => false
  170. ],
  171. [
  172. "key" => "name",
  173. "via" => "body",
  174. "type" => "string",
  175. "description" => "New username. If not supplied, it will default to 'player_[id]'. Will be overriden on the next PUT request.",
  176. "optional" => true
  177. ],
  178. [
  179. "key" => "public",
  180. "via" => "body",
  181. "type" => "int",
  182. "description" => "1 to make the profile public, 0 to keep it private. Default to 0.",
  183. "optional" => true
  184. ],
  185. ],
  186. "responses" => [
  187. [
  188. "status" => "201",
  189. "message" => "Created.",
  190. "description" => null,
  191. "example" => json_encode('{"username":"IValentin","email":example@example.com,"api_key":"0123456789012345","public":"0"}', JSON_PRETTY_PRINT),
  192. ],
  193. [
  194. "status" => "400",
  195. "message" => "User ID not received.",
  196. "description" => "The ID of the player to create is not in the query.",
  197. "example" => null
  198. ],
  199. [
  200. "status" => "400",
  201. "message" => "User email not received.",
  202. "description" => "The email of the player to create has not ben passed in the request.",
  203. "example" => null
  204. ],
  205. [
  206. "status" => "400",
  207. "message" => "Invalid email.",
  208. "description" => "The 'mail' parameter must be a valid email address.",
  209. "example" => null
  210. ],
  211. [
  212. "status" => "400",
  213. "message" => "User password not received.",
  214. "description" => "The password of the player to create has not ben passed in the request.",
  215. "example" => null
  216. ],
  217. [
  218. "status" => "400",
  219. "message" => "Existing user.",
  220. "description" => "A player with the same ID is already registered in SWDB.",
  221. "example" => null
  222. ]
  223. ]
  224. ],
  225. [
  226. "id" => "PUT",
  227. "url" => "/profile/{id}/",
  228. "description" => "Updates a player profile with data received from the game.",
  229. "parameters" => [
  230. [
  231. "key" => "{id}",
  232. "via" => "query",
  233. "type" => "string",
  234. "description" => "Player ID.",
  235. "optional" => false
  236. ],
  237. [
  238. "key" => "key",
  239. "via" => "body",
  240. "type" => "string",
  241. "description" => "API key.",
  242. "optional" => false
  243. ],
  244. [
  245. "key" => "response",
  246. "via" => "body",
  247. "type" => "string",
  248. "description" => "JSON received from game server on HubUserLogin command.",
  249. "optional" => false
  250. ]
  251. ],
  252. "responses" => [
  253. [
  254. "status" => "204",
  255. "message" => "Profile imported.",
  256. "description" => null,
  257. "example" => null,
  258. ],
  259. [
  260. "status" => "400",
  261. "message" => "API key not received.",
  262. "description" => "No API key was suplied in the request.",
  263. "example" => null
  264. ],
  265. [
  266. "status" => "400",
  267. "message" => "No data received.",
  268. "description" => "Game JSON response not received from request",
  269. "example" => null
  270. ],
  271. [
  272. "status" => "400",
  273. "message" => "Data is no valid JSON.",
  274. "description" => "The parameter 'response' contains information, but it's not valid JSON data.",
  275. "example" => null
  276. ],
  277. [
  278. "status" => "401",
  279. "message" => "Invalid credentials",
  280. "description" => "The API key is not valid for the profile being updated.",
  281. "example" => null
  282. ]
  283. ]
  284. ],
  285. [
  286. "id" => "DELETE",
  287. "url" => "/profile/{id}/",
  288. "description" => "Deletes a player profile.",
  289. "parameters" => [
  290. [
  291. "key" => "{id}",
  292. "via" => "query",
  293. "type" => "string",
  294. "description" => "Player ID.",
  295. "optional" => false
  296. ],
  297. [
  298. "key" => "key",
  299. "via" => "body",
  300. "type" => "string",
  301. "description" => "API key.",
  302. "optional" => false
  303. ]
  304. ],
  305. "responses" => [
  306. [
  307. "status" => "204",
  308. "message" => "Profile deleted.",
  309. "description" => null,
  310. "example" => null,
  311. ],
  312. [
  313. "status" => "400",
  314. "message" => "User ID not received.",
  315. "description" => "The ID of the player to create is not in the query.",
  316. "example" => null
  317. ],
  318. [
  319. "status" => "400",
  320. "message" => "API key not received.",
  321. "description" => "No API key was suplied in the request.",
  322. "example" => null
  323. ],
  324. [
  325. "status" => "401",
  326. "message" => "Invalid credentials",
  327. "description" => "The API key is not valid for the profile being updated.",
  328. "example" => null
  329. ]
  330. ]
  331. ],
  332. ],
  333. ] // END COMMAND profile
  334. ]
  335. ], // END CATEGORY Profile
  336. [ // BEGIN CATEGORY Run
  337. "name" => "Run",
  338. "command" => [
  339. [ // BEGIN COMMAND run
  340. "name" => "run",
  341. "method" => [
  342. [
  343. "id" => "POST",
  344. "url" => "/run/",
  345. "description" => "Logs a game run using JSON files intercepted from the game.",
  346. "parameters" => [
  347. [
  348. "key" => "key",
  349. "via" => "body",
  350. "type" => "string",
  351. "description" => "API key.",
  352. "optional" => false
  353. ],
  354. [
  355. "key" => "result_response",
  356. "via" => "body",
  357. "type" => "string",
  358. "description" => "JSON received from game server on run result.",
  359. "optional" => false
  360. ],
  361. [
  362. "key" => "result_request",
  363. "via" => "body",
  364. "type" => "string",
  365. "description" => "JSON sent to game server on run result. Required for commands: BattleDungeonResult_V2, BattleDimensionHoleDungeonResult_v2",
  366. "optional" => true
  367. ],
  368. [
  369. "key" => "start_response",
  370. "via" => "body",
  371. "type" => "string",
  372. "description" => "JSON received from game server on run start. Required for commands: BattleRiftOfWorldsRaidResult, BattleScenarioResult",
  373. "optional" => true
  374. ],
  375. [
  376. "key" => "start_request",
  377. "via" => "body",
  378. "type" => "string",
  379. "description" => "JSON sent to game server on run start. Required for commands: ",
  380. "optional" => true
  381. ],
  382. ],
  383. "responses" => [
  384. [
  385. "status" => "201",
  386. "message" => "Created.",
  387. "description" => null,
  388. "example" => null,
  389. ],
  390. [
  391. "status" => "400",
  392. "message" => "API key not received.",
  393. "description" => "No API key was suplied in the request.",
  394. "example" => null
  395. ],
  396. [
  397. "status" => "400",
  398. "message" => "No result response data received.",
  399. "description" => "JSON received from game server on run result wast receiven on the request.",
  400. "example" => null
  401. ],
  402. [
  403. "status" => "400",
  404. "message" => "Result response data is no valid JSON.",
  405. "description" => "The parameter 'result_response' contains information, but it's not valid JSON data.",
  406. "example" => null
  407. ],
  408. [
  409. "status" => "401",
  410. "message" => "Invalid credentials",
  411. "description" => "The API key is not valid for the profile being updated.",
  412. "example" => null
  413. ],
  414. [
  415. "status" => "405",
  416. "message" => "Command not implemented.",
  417. "description" => "The command referenced in the JSON file is not implemented.",
  418. "example" => null
  419. ],
  420. [
  421. "status" => "409",
  422. "message" => "Run already in database.",
  423. "description" => "The run is already in the database for the user.",
  424. "example" => null
  425. ]
  426. ]
  427. ],
  428. ],
  429. ] // END COMMAND Run
  430. ]
  431. ], // END CATEGORY Run
  432. ],
  433. ];