Files
libr-2/README.md
T
2015-08-13 00:05:01 +08:00

3.5 KiB

Libr

安装运行

  • 下载postgres http://postgresapp.com/ 并运行
  • 下载redis, brew install redis 并运行: redis-server
  • git clone 代码
  • bundle install
  • rake db:create, rake db:migrate
  • rails s
  • 运行 sidekiq, 在项目跟目录下: bundle exec sidekiq -C config/sidekiq.yml

API 调用

1 注册 POST: http://127.0.0.1:3000/api/v1/sign_up

  • 参数:
    • user[email]
    • user[password]
    • user[password_confirmation]
  • 返回结果
{
  "user": {
    "id": 10,
    "name": "test5",
    "email": "test5@qq.com",
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbiI6ImU3M2YzYTljMTIxMjVkNDViNjJlNjkxNjQ4MjgyNGVmIn0.Rv_DkYEDWOIhObnTjC_8N8L-BACm8cFCOSqEgSmPUDc"
  }
}

2 登录 POST: http://127.0.0.1:3000/api/v1/sign_in

  • 参数:
  • user[email]
  • user[password]
  • 返回结果:
 {
   "user": {
     "id": 3,
     "name": null,
     "email": "wahyd4@qq.com",
     "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbiI6IjU0MGU4OTU4ODg3ZmI1MGI5YTA5YzI4MjQ2NTZlYTRlIn0.XQBWCNRYVdDvZwuBtafCyOkNpP8FEzwRqk8AhaHlaFc"
   }
 }

3 提交分享资源 POST: http://localhost:3000/api/v1/posts

  • 参数
  • 需要登录 传Authorization header
  • url 网址
  • type article 或者 web_page
  • description 可选
  • 返回
  {
    "id": 32,
    "user_id": 3,
    "sharable_id": 3,
    "sharable_type": "WebPage",
    "created_at": "2015-08-04T00:33:25.735+08:00",
    "updated_at": "2015-08-04T00:33:25.735+08:00",
    "description": "这是一个特别cool的github 项目",
    "sharable": {
      "id": 3,
      "name": null,
      "url": "http://mp.weixin.qq.com/s?__biz=MzA4NjAzMjEyOA==&mid=207485444&idx=1&sn=c0d5e1b2399fffbcdc5a5065eea52af8",
      "created_at": "2015-08-04T00:33:25.627+08:00",
      "updated_at": "2015-08-04T00:33:25.627+08:00",
      "processed": false,
      "view_account": 0
    }
  }

4 未注册用户首页数据 GET http://localhost:3000/api/v1/posts

  • 参数
  • 返回
  [
    {
      "description": "这是我看到底第一篇他写的文章",
      "sharable_type": "Article",
      "sharable": {
        "view_account": 0,
        "url": "http://www.jianshu.com/p/bfbc77eecdb0",
        "title": null
      }
    },      
    {
      "description": "到底能不能成功啊,我去",
      "sharable_type": "Article",
      "sharable": {
        "view_account": 0,
        "url": "http://www.cnbeta.com/articles/416787.htm",
        "title": null
      }
    },
    {
      "description": "这是一个特别cool的github 项目",
      "sharable_type": "WebPage",
      "sharable": {
        "view_account": 0,
        "url": "https://github.com/sparklemotion/mechanize",
        "title": "sparklemotion/mechanize · GitHub"
      }

5 follow 用户:POST http://localhost:3000/api/v1/users/2/follow

6 unfollow 用户: POST: http://localhost:3000/api/v1/users/2/unfollow

7 like post POST: http://localhost:3000/api/v1/posts/3/like

8 unlike post POST: http://localhost:3000/api/v1/posts/3/unlike

9 create comment POST: http://localhost:3000/api/v1/posts/1/comments

10 comment list GET http://localhost:3000/api/v1/posts/1/comments

11 like comment: POST http://localhost:3000/api/v1/posts/1/comments/1/like

12 unlike comment: POST http://localhost:3000/api/v1/posts/1/comments/1/unlike

注意

  • 注意,API返回结果中的token是利用JWT 技术加密的token,密钥是每个用户的email
  • jwt