Advertisement
Guest User

Untitled

a guest
Apr 1st, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.69 KB | None | 0 0
  1. ## /user
  2.  
  3. ### /user:signup
  4.  
  5. Sign up a new user.
  6.  
  7. ```javascript
  8. const request = {
  9. body: {
  10. username: 'username',
  11. password: 'password'
  12. }
  13. }
  14. socket.emit('/user:signup', request, (error, response) => {
  15. console.log(error); // null if no error
  16. console.log(response.message); // the success message
  17. console.log(response.data.token); // the access token
  18. })
  19. ```
  20.  
  21. ### /user:signin
  22.  
  23. SIgn in an user.
  24.  
  25. ```javascript
  26. const request = {
  27. body: {
  28. username: 'username',
  29. password: 'password'
  30. }
  31. };
  32. socket.emit('/user:signin', request, (error, response) => {
  33. console.log(error); // null if no error
  34. console.log(response.message); // the success message
  35. console.log(response.data.token); // the access token
  36. })
  37. ```
  38.  
  39. ### /user:signout
  40.  
  41. Sign out the current user.
  42.  
  43. ```javascript
  44. socket.emit('/user:signout', null, (error, response) => {
  45. console.log(error); // null if no error
  46. })
  47. ```
  48.  
  49.  
  50. ### /user:set_avatar
  51.  
  52. Update a new avatar for the current user.
  53.  
  54. ```javascript
  55. const request = {
  56. files: {
  57. avatar: {
  58. data: 'base64 encoded image data here'
  59. }
  60. }
  61. };
  62. socket.emit('/user:set_avatar', request, (error, response) => {
  63. console.log(error); // null if no error
  64. console.log(response.message); // the success message
  65. console.log(response.data.url); // the avatar url
  66. })
  67. ```
  68.  
  69. ### /user:get_avatars
  70.  
  71. Get avatars of multiple users.
  72.  
  73. ```javascript
  74. const request = {
  75. query: {
  76. usernames: ['username1', 'username2']
  77. }
  78. };
  79. socket.emit('/user:set_avatar', request, (error, response) => {
  80. console.log(error); // null if no error
  81. console.log(response.data[0].username); // the username
  82. console.log(response.data[0].url); // the avatar url
  83. })
  84. ```
  85.  
  86. ### /user:get_avatar
  87.  
  88. Get avatar of the current user.
  89.  
  90. ```javascript
  91. socket.emit('/user:get_avatar', null, (error, response) => {
  92. console.log(error); // null if no error
  93. console.log(response.data.url); // the avatar url
  94. })
  95. ```
  96.  
  97. ### /user:set_profile
  98.  
  99. Update profile of the current user.
  100.  
  101. ```javascript
  102. const request = {
  103. body: {
  104. 'phone': 'phone',
  105. 'email': 'email',
  106. 'address': 'address',
  107. 'nid': 'nid',
  108. 'bod': 'bod'
  109. }
  110. };
  111. socket.emit('/user:set_profile', request, (error, response) => {
  112. console.log(error); // null if no error
  113. console.log(response.data.username);
  114. console.log(response.data.gold);
  115. console.log(response.data.vip);
  116. console.log(response.data.phone);
  117. console.log(response.data.email);
  118. console.log(response.data.address);
  119. console.log(response.data.nid);
  120. console.log(response.data.bod);
  121. })
  122. ```
  123.  
  124. ### /user:get_profile
  125.  
  126. Get profile of the current user.
  127.  
  128. ```javascript
  129. socket.emit('/user:get_profile', null, (error, response) => {
  130. console.log(error); // null if no error
  131. console.log(response.data.username);
  132. console.log(response.data.gold);
  133. console.log(response.data.vip);
  134. console.log(response.data.phone);
  135. console.log(response.data.email);
  136. console.log(response.data.address);
  137. console.log(response.data.nid);
  138. console.log(response.data.bod);
  139. })
  140. ```
  141.  
  142. ### /user:set_password
  143.  
  144. ```javascript
  145. const request = {
  146. body: {
  147. 'oldPassword': 'oldPassword',
  148. 'newPassword': 'newPassword'
  149. }
  150. };
  151. socket.emit('/user:set_password', request, (error, response) => {
  152. console.log(error); // null if no error
  153. console.log(response.message); // a success message
  154. })
  155. ```
  156.  
  157. ### /user:signin_by_token
  158.  
  159. Signin an user by his access token.
  160.  
  161. ```javascript
  162. const request = {
  163. body: {
  164. token: '1234123234234'
  165. }
  166. };
  167. socket.emit('/user:signin_by_token', request, (err, res) => {
  168. console.log(err); // null if no error
  169. console.log(res.data.token); // a new access token
  170. })
  171. ```
  172.  
  173.  
  174. ## /news_catalog
  175.  
  176. ### /news_catalog:list
  177.  
  178. List all available news catalogs.
  179.  
  180. ```javascript
  181. socket.emit('/news_catalog:list', null, (err, res) => {
  182. console.log(err); // null if no error
  183. console.log(res.data[0].name) // catalog id
  184. });
  185. ```
  186.  
  187. ## /news
  188.  
  189. ### /news:list
  190.  
  191. List news.
  192.  
  193. You can do time-based paging by changing 'before' and defining a 'limit' per page.
  194.  
  195. The 'limit' can be big as you want, but server will limit the result on its side and doesn't allow you have a big query (the server's limit is 50 currently).
  196.  
  197. Find all news:
  198. ```javascript
  199. const request = {
  200. query: {
  201. before: Date.now(),
  202. limit: 20
  203. }
  204. };
  205. socket.emit('/news:list', request, (err, res) => {
  206. console.log(err); // null if no error
  207. console.log(res.data[0]._id); // news id
  208. console.log(res.data[0].title); // title
  209. console.log(res.data[0].thumbnail); // thumbnail url
  210. console.log(res.data[0].author); // author name
  211. console.log(res.data[0].createdAt); // created time, epoch time, milliseconds
  212. console.log(res.data[0].keywords[0]); // keyword
  213. console.log(res.data[0].catalogs[0]); // catalog id
  214. console.log(res.data[0].likes); // number of likes
  215. });
  216. ```
  217.  
  218.  
  219. Find news by **catalog ids**:
  220. ```javascript
  221. const request = {
  222. query: {
  223. catalogs: ['catalog_1'],
  224. before: Date.now(),
  225. limit: 20
  226. }
  227. };
  228. socket.emit('/news:list', request, (err, res) => {
  229. console.log(err); // null if no error
  230. console.log(res.data[0]._id); // news id
  231. console.log(res.data[0].title); // title
  232. console.log(res.data[0].thumbnail); // thumbnail url
  233. console.log(res.data[0].author); // author name
  234. console.log(res.data[0].createdAt); // created time, epoch time, milliseconds
  235. console.log(res.data[0].keywords[0]); // keyword
  236. console.log(res.data[0].catalogs[0]); // catalog id
  237. console.log(res.data[0].likes); // number of likes
  238. });
  239. ```
  240.  
  241. Find news by keywords:
  242. ```javascript
  243. const request = {
  244. query: {
  245. keywords: ['kw_1', 'kw_2'],
  246. before: Date.now(),
  247. limit: 20
  248. }
  249. };
  250. socket.emit('/news:list', request, (err, res) => {
  251. console.log(err); // null if no error
  252. console.log(res.data[0]._id); // news id
  253. console.log(res.data[0].title); // title
  254. console.log(res.data[0].thumbnail); // thumbnail url
  255. console.log(res.data[0].author); // author name
  256. console.log(res.data[0].createdAt); // created time, epoch time, milliseconds
  257. console.log(res.data[0].keywords[0]); // keyword
  258. console.log(res.data[0].catalogs[0]); // catalog id
  259. console.log(res.data[0].likes); // number of likes
  260. });
  261. ```
  262.  
  263. ### /news:get_content
  264.  
  265. Get content of a news.
  266.  
  267. ```javascript
  268. const request = {
  269. query: {
  270. newsId: '1234566545'
  271. }
  272. };
  273. socket.emit('/news:get_content', request, (err, res) => {
  274. console.log(err); // null if no error
  275. console.log(res.data.format); // content format, can be 'md', 'txt', 'html'.
  276. console.log(res.data.content); // content
  277. });
  278. ```
  279.  
  280. ### /news:like
  281.  
  282. Like a news.
  283.  
  284. ```javascript
  285. const request = {
  286. body: {
  287. newsId: '1234566545'
  288. }
  289. };
  290. socket.emit('/news:like', request, (err, res) => {
  291. console.log(err); // null if no error
  292. console.log(res.data.likes); // the new number of likes
  293. });
  294. ```
  295.  
  296. ## /clip_catalog
  297.  
  298. ### /clip_catalog:list
  299.  
  300. List all clip catalogs.
  301.  
  302. ```javascript
  303. socket.emit('/clip_catalog:list', null, (err, res) => {
  304. console.log(err); // null if no error
  305. console.log(res.data[0]._id); // catalog id
  306. console.log(res.data[0].name); // catalog name
  307. });
  308. ```
  309.  
  310.  
  311. ## /clip
  312.  
  313. ### /clip:list
  314.  
  315. List clip.
  316.  
  317. You can do time-based paging by changing 'before' and defining a 'limit' per page.
  318.  
  319. The 'limit' can be big as you want, but server will limit the result on its side and doesn't allow you have a big query (the server's limit is 50 currently).
  320.  
  321. Find all clip:
  322. ```javascript
  323. const request = {
  324. query: {
  325. before: Date.now(),
  326. limit: 20
  327. }
  328. };
  329. socket.emit('/clip:list', request, (err, res) => {
  330. console.log(err); // null if no error
  331. console.log(res.data[0]._id); // clip id
  332. console.log(res.data[0].title); // title
  333. console.log(res.data[0].thumbnail); // thumbnail url
  334. console.log(res.data[0].createdAt); // created time, epoch time, milliseconds
  335. console.log(res.data[0].keywords[0]); // keyword
  336. console.log(res.data[0].catalogs[0]); // catalog id
  337. console.log(res.data[0].likes); // number of likes
  338. console.log(res.data[0].views); // number of views
  339. console.log(res.data[0].duration); // duration in seconds
  340. });
  341. ```
  342.  
  343.  
  344. Find clip by **catalog ids**:
  345. ```javascript
  346. const request = {
  347. query: {
  348. catalogs: ['1212312312312'],
  349. before: Date.now(),
  350. limit: 20
  351. }
  352. };
  353. socket.emit('/clip:list', request, (err, res) => {
  354. console.log(err); // null if no error
  355. console.log(res.data[0]._id); // clip id
  356. console.log(res.data[0].title); // title
  357. console.log(res.data[0].thumbnail); // thumbnail url
  358. console.log(res.data[0].createdAt); // created time, epoch time, milliseconds
  359. console.log(res.data[0].keywords[0]); // keyword
  360. console.log(res.data[0].catalogs[0]); // catalog id
  361. console.log(res.data[0].likes); // number of likes
  362. console.log(res.data[0].views); // number of views
  363. console.log(res.data[0].duration); // duration in seconds
  364. });
  365. ```
  366.  
  367. Find clip by keywords:
  368. ```javascript
  369. const request = {
  370. query: {
  371. keywords: ['kw_1', 'kw_2'],
  372. before: Date.now(),
  373. limit: 20
  374. }
  375. };
  376. socket.emit('/clip:list', request, (err, res) => {
  377. console.log(err); // null if no error
  378. console.log(res.data[0]._id); // clip id
  379. console.log(res.data[0].title); // title
  380. console.log(res.data[0].thumbnail); // thumbnail url
  381. console.log(res.data[0].createdAt); // created time, epoch time, milliseconds
  382. console.log(res.data[0].keywords[0]); // keyword
  383. console.log(res.data[0].catalogs[0]); // catalog id
  384. console.log(res.data[0].likes); // number of likes
  385. console.log(res.data[0].views); // number of views
  386. console.log(res.data[0].duration); // duration in seconds
  387. });
  388. ```
  389.  
  390. ### /clip:get_url
  391.  
  392. Get url of a clip.
  393.  
  394. ```javascript
  395. const request = {
  396. query: {
  397. clipId: '1234566545'
  398. }
  399. };
  400. socket.emit('/clip:get_url', request, (err, res) => {
  401. console.log(err); // null if no error
  402. console.log(res.data.url); // the clip url
  403. });
  404. ```
  405.  
  406. ### /clip:like
  407.  
  408. Like a clip.
  409.  
  410. ```javascript
  411. const request = {
  412. body: {
  413. clipId: '1234566545'
  414. }
  415. };
  416. socket.emit('/clip:like', request, (err, res) => {
  417. console.log(err); // null if no error
  418. console.log(res.data.likes); // the new number of likes
  419. });
  420. ```
  421.  
  422. ## /channel
  423.  
  424. ### /channel:list
  425.  
  426. List all channels.
  427.  
  428. ```javascript
  429. socket.emit('/channel:list', null, (err, res) => {
  430. console.log(err); // null if no error
  431. console.log(res.data[0]._id); // channel id
  432. console.log(res.data[0].name); // channel name
  433. console.log(res.data[0].description); // channel description
  434. console.log(res.data[0].icon); // channel icon url
  435. console.log(res.data[0].keywords); // channel keywords
  436. });
  437. ```
  438.  
  439. ### /channel:get_url
  440.  
  441. Get url of a channel.
  442.  
  443. ```javascript
  444. const request = {
  445. query: {
  446. channelId: '1231231231'
  447. }
  448. };
  449. socket.emit('/channel:get_url', request, (err, res) => {
  450. console.log(err); // null if no error
  451. console.log(res.data.url); // url of the channel
  452. });
  453. ```
  454.  
  455. ### /channel:get_schedule
  456.  
  457. Get schedule of a channel.
  458.  
  459. ```javascript
  460. const request = {
  461. query: {
  462. channelId: '123123131',
  463. after: Date.now()
  464. }
  465. };
  466. socket.emit('/channel:get_schedule', request, (err, res) => {
  467. console.log(err); // null if no error
  468. console.log(res.data[0]._id); // schedule id
  469. console.log(res.data[0].livedAt); // lived time, epoch time in milliseconds
  470. console.log(res.data[0].description); // program description
  471. });
  472. ```
  473.  
  474. You can do time-based paging by changing the 'after'.
  475.  
  476. ## /notification
  477.  
  478. ### /notification:list
  479.  
  480. List all unread notifications.
  481.  
  482. ```javascript
  483. const request = {
  484. query: {
  485. deviceId: '123123131'
  486. }
  487. };
  488. socket.emit('/notification:list', request, (err, res) => {
  489. console.log(err); // null if no error
  490. console.log(res.data[0]._id); // notification id
  491. console.log(res.data[0].title); // title
  492. console.log(res.data[0].description);
  493. console.log(res.data[0].link); // the app deep link
  494. console.log(res.data[0].extras); // the deep link extras
  495. console.log(res.data[0].createdAt); // the created time, epoch time, in milliseconds
  496. console.log(res.data[0].expiredAt); // the expired time, date tine
  497. });
  498. ```
  499.  
  500. ### /notification:read
  501.  
  502. Specify an user or a device read a notification.
  503.  
  504. ```javascript
  505. const request = {
  506. body: {
  507. notificationId: '123123123',
  508. deviceId: '123123131'
  509. }
  510. };
  511. // don't wait for this request
  512. socket.emit('/notification:list', request);
  513. ```
  514.  
  515. ## /vip
  516.  
  517. ### /vip:list
  518.  
  519. List all VIP plans.
  520.  
  521. ```javascript
  522. socket.emit('/vip:list', null, (err, res) => {
  523. console.log(err); // null if no error
  524. console.log(res.data[0].name); // vip name
  525. console.log(res.data[0].title);
  526. console.log(res.data[0].description);
  527. console.log(res.data[0].gateway); // registration gateway
  528. console.log(res.data[0].plans[0].name); // plan name, registration syntax also
  529. console.log(res.data[0].plans[0].fee); // registration fee
  530. console.log(res.data[0].plans[0].unit); // fee unit ex: đồng/ngày, đồng/tuần.
  531. });
  532. ```
  533.  
  534. An example result:
  535. ```json
  536. {
  537. "data": [
  538. {
  539. "_id": "56fc99ab2b355814346ff64a",
  540. "name": "vip",
  541. "description": "vip description",
  542. "title": "vip title",
  543. "gateway": 8080,
  544. "dailyGold": 10000,
  545. "__v": 0,
  546. "plans": [
  547. {
  548. "name": "vip",
  549. "fee": 10000,
  550. "unit": "dong\/ngay",
  551. "_id": "56fc99ab2b355814346ff64c"
  552. },
  553. {
  554. "name": "vip7",
  555. "fee": 15000,
  556. "unit": "dong\/tuan",
  557. "_id": "56fc99ab2b355814346ff64b"
  558. }
  559. ]
  560. },
  561. {
  562. "_id": "56fc99ab2b355814346ff64d",
  563. "name": "tip",
  564. "description": "tip description",
  565. "title": "tip title",
  566. "gateway": 8080,
  567. "dailyGold": 10000,
  568. "__v": 0,
  569. "plans": [
  570. {
  571. "name": "tip",
  572. "fee": 10000,
  573. "unit": "dong\/ngay",
  574. "_id": "56fc99ab2b355814346ff64f"
  575. },
  576. {
  577. "name": "tip7",
  578. "fee": 15000,
  579. "unit": "dong\/tuan",
  580. "_id": "56fc99ab2b355814346ff64e"
  581. }
  582. ]
  583. }
  584. ]
  585. }
  586. ```
  587.  
  588. ## /feedback
  589.  
  590. ### /feedback:send
  591.  
  592. Send a feedback.
  593.  
  594. ```javascript
  595. const request = {
  596. body: {
  597. content: 'keep it shity please'
  598. }
  599. };
  600. socket.emit('/feedback:send', request, (err, res) => {
  601. console.log(err); // null if no error
  602. console.log(res.message); // a thankful message
  603. });
  604. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement