diff --git a/Gemfile b/Gemfile index 0a976dc..3f9dcca 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ gem 'omniauth-slack' gem "omniauth-google-oauth2" gem 'figaro' gem 'ancestry' +gem 'pry-rails' group :development, :test do gem 'sqlite3' diff --git a/Gemfile.lock b/Gemfile.lock index bb9b89f..5963b86 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM activerecord (>= 3.0.0) arel (6.0.3) builder (3.2.2) + coderay (1.1.0) concurrent-ruby (1.0.0) erubis (2.7.0) faraday (0.9.2) @@ -57,6 +58,7 @@ GEM nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) + method_source (0.8.2) mime-types (2.99) mini_portile2 (2.0.0) minitest (5.8.3) @@ -86,6 +88,12 @@ GEM omniauth-slack (2.3.0) omniauth-oauth2 (~> 1.3.1) pg (0.18.4) + pry (0.10.3) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-rails (0.3.4) + pry (>= 0.9.10) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) @@ -117,6 +125,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.5.0) + slop (3.6.0) spring (1.6.2) sprockets (3.5.2) concurrent-ruby (~> 1.0) @@ -141,6 +150,7 @@ DEPENDENCIES omniauth-oauth2 (~> 1.3.1) omniauth-slack pg + pry-rails rails (= 4.2.5) rails-api spring diff --git a/docs/answers_endpoint.md b/docs/answers_endpoint.md new file mode 100644 index 0000000..b8560f5 --- /dev/null +++ b/docs/answers_endpoint.md @@ -0,0 +1,233 @@ +#Answers Resources + +Endpoints | Usage | Public Access +--------- | ----- | ------------- +GET /questions/:id/answers | Returns all the answers for a particular question | True +POST /questions/:id/answers/ | Creates a new answer for the specified question | False +GET /questions/:id/answers/recent?limit={:total} | Returns {total} answers ordered by the most recent [ MAXLIMIT = 50 ] | True +GET /questions/:id/answers/popular?limit={:total} | Returns {total} answers ordered by the most popular [ MAXLIMIT = 50 ] | True +POST /questions/:id/answers/:id/upvote | Upvotes an answer | False +POST /questions/:id/answers/:id/downvote | Downvotes an answer | False +PUT /answers/:id | Updates the answer with certain attributes | False +DELETE /answers/:id | Deletes an answer and its related comments | False + +### GET /questions/:id/answers + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335" + } +``` + +Response +```ruby +Status: 200 + { + question: { + id: 1, + answers: [ + { + id: 2, + text: 'What do you really want to do?', + date_created: 'Wed, 24TH Nov, 2017 10:00AM', + updated: false, + score: 8, + user: { + id: 2, + name: 'Oscar Laide' + } + }, + { + id: 4, + text: 'This is such a scam', + date_created: 'Wed, 25TH Nov, 2017 12:00PM', + updated: true, + score: 9, + user: { + id: 3, + name: 'Bayo Owoade' + } + } + ] + } + } +``` + +```ruby +Status: 404 +{ + message: "Question not found" +} +``` + + +### POST /questions/:id/answers/ + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335", + text: "Why in the world do I have to do this?" + } +``` + +Response +```ruby +Status: 201 +{ + message: "Successfully added" +} +``` + +### GET /questions/:id/answers/recent?limit=10 + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335" + } +``` + +Response +```ruby +Status: 200 + { + question: { + id: 1, + limit: 10, + answers: [ + { + id: 4, + text: 'This is such a scam', + date_created: 'Wed, 25TH Nov, 2017 12:00PM', + updated: true, + user: { + id: 3, + name: 'Bayo Owoade' + } + }, + { + id: 2, + text: 'What do you really want to do?', + date_created: 'Wed, 24TH Nov, 2017 10:00AM', + updated: false, + user: { + id: 2, + name: 'Oscar Laide' + } + } + ] + } + } +``` + +### GET /questions/:id/answers/popular?limit={:total} + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335" + } +``` + +Response +```ruby +# note score param added to the answer +Status: 200 + { + question: { + id: 1, + limit: 10, + answers: [ + { + id: 4, + text: 'This is such a scam', + date_created: 'Wed, 25TH Nov, 2017 12:00PM', + updated: true, + score: 9, + user: { + id: 3, + name: 'Bayo Owoade' + } + }, + { + id: 2, + text: 'What do you really want to do?', + date_created: 'Wed, 24TH Nov, 2017 10:00AM', + updated: false, + score: 8, + user: { + id: 2, + name: 'Oscar Laide' + } + } + ] + } + } +``` + +### POST /questions/:id/answers/:id/upvote + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335", + answer_id: 5 + } +``` + +Response +```ruby +Status: 201 +{ + message: "Successfully upvoted" +} +``` + +### POST /questions/:id/answers/:id/downvote + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335", + answer_id: 5 + } +``` + +Response +```ruby +Status: 201 +{ + message: "Successfully downvoted" +} +``` + +### PUT /answers/:id + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335", + text: "What in the world does this mean?" + } +``` + +Response +```ruby + Status: 204 +``` + +### DELETE /answers/:id + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335" + } +``` + +Response +```ruby + Status: 204 +``` diff --git a/docs/api.md b/docs/api.md index 4663a01..bda36cf 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1 +1,6 @@ # API Endpoints + +The most important parameter for all endpoints except the `Home#index` is the +`user_token`, which can be sent either as a header or as a request params + +The token allows the application to authenticate on what diff --git a/docs/comments_endpoints.md b/docs/comments_endpoints.md new file mode 100644 index 0000000..3e83807 --- /dev/null +++ b/docs/comments_endpoints.md @@ -0,0 +1,233 @@ +#Comments Resources + +Endpoints | Usage | Public Access +--------- | ----- | ------------- +GET /answers/:id/comments | Returns all the comments for a particular answer | True +POST /answers/:id/comments/ | Creates a new comment for the specified answer | False +GET /answers/:id/comments/recent?limit={:total} | Returns {total} comments ordered by the most recent [ MAXLIMIT = 15 ] | True +GET /answers/:id/comments/popular?limit={:total} | Returns {total} comments ordered by the most popular [ MAXLIMIT = 15 ] | True +POST /answers/:id/comments/:id/upvote | Upvotes a comment | False +POST /answers/:id/comments/:id/downvote | Downvotes a comment | False +PUT /comments/:id | Updates the comment with certain attributes | False +DELETE /comments/:id | Deletes an comment | False + +### GET /answers/:id/comments + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335" + } +``` + +Response +```ruby +Status: 200 + { + answer: { + id: 1, + comments: [ + { + id: 2, + text: 'What do you really want to do?', + date_created: 'Wed, 24TH Nov, 2017 10:00AM', + updated: false, + score: 8, + user: { + id: 2, + name: 'Oscar Laide' + } + }, + { + id: 4, + text: 'This is such a scam', + date_created: 'Wed, 25TH Nov, 2017 12:00PM', + updated: true, + score: 9, + user: { + id: 3, + name: 'Bayo Owoade' + } + } + ] + } + } +``` + +```ruby +Status: 404 +{ + message: "Answer not found" +} +``` + + +### POST /answers/:id/comments/ + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335", + text: "Why in the world do I have to do this?" + } +``` + +Response +```ruby +Status: 201 +{ + message: "Successfully added" +} +``` + +### GET /answers/:id/comments/recent?limit=10 + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335" + } +``` + +Response +```ruby +Status: 200 + { + answer: { + id: 1, + limit: 10, + comments: [ + { + id: 4, + text: 'This is such a scam', + date_created: 'Wed, 25TH Nov, 2017 12:00PM', + updated: true, + user: { + id: 3, + name: 'Bayo Owoade' + } + }, + { + id: 2, + text: 'What do you really want to do?', + date_created: 'Wed, 24TH Nov, 2017 10:00AM', + updated: false, + user: { + id: 2, + name: 'Oscar Laide' + } + } + ] + } + } +``` + +### GET /answers/:id/comments/popular?limit={:total} + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335" + } +``` + +Response +```ruby +# note score param added to the answer +Status: 200 + { + answer: { + id: 1, + limit: 10, + comments: [ + { + id: 4, + text: 'This is such a scam', + date_created: 'Wed, 25TH Nov, 2017 12:00PM', + updated: true, + score: 9, + user: { + id: 3, + name: 'Bayo Owoade' + } + }, + { + id: 2, + text: 'What do you really want to do?', + date_created: 'Wed, 24TH Nov, 2017 10:00AM', + updated: false, + score: 8, + user: { + id: 2, + name: 'Oscar Laide' + } + } + ] + } + } +``` + +### POST /answers/:id/comments/:id/upvote + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335", + comment_id: 5 + } +``` + +Response +```ruby +Status: 201 +{ + message: "Successfully upvoted" +} +``` + +### POST /answers/:id/comments/:id/downvote + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335", + comment_id: 5 + } +``` + +Response +```ruby +Status: 201 +{ + message: "Successfully downvoted" +} +``` + +### PUT /comments/:id + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335", + text: "What in the world does this mean?" + } +``` + +Response +```ruby + Status: 204 +``` + +### DELETE /comments/:id + +Request +```ruby + { + auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335" + } +``` + +Response +```ruby + Status: 204 +```