From f0885fb85a7e453c7d5d53e3df4a51c29129c2bc Mon Sep 17 00:00:00 2001 From: Harry Levine Date: Fri, 21 Jul 2017 15:13:41 -0600 Subject: [PATCH 1/4] Route for new slack invite endpoint Trying to keep the RESTful by using a slacks controller and the :create method. Adjusting the path name to have the API endpoint have Slack as singular. --- config/routes.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index c09a2e2a..47e390cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,8 +8,8 @@ get '/status', to: 'status#all' get '/status/protected', to: 'status#protected' - post '/users/profile/verify', to: 'users#verify' get '/users/by_location', to: 'users#by_location' + post '/users/profile/verify', to: 'users#verify' resources :code_schools, only: :index resources :events, only: :index @@ -19,6 +19,7 @@ resources :votes, only: [:create, :destroy] end resources :services, only: :index + resources :slacks, only: :create, path: 'slack' resources :squads, only: [:index, :create, :show] do member do post 'join' From 929f7bdafe9791a09e4f0e6027efcab1e763e780 Mon Sep 17 00:00:00 2001 From: Harry Levine Date: Fri, 21 Jul 2017 15:17:59 -0600 Subject: [PATCH 2/4] Slacks controller with new endpoint to trigger slack invite job MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Requires no parameters, as it passes the current user’s email address. --- app/controllers/api/v1/slacks_controller.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/controllers/api/v1/slacks_controller.rb diff --git a/app/controllers/api/v1/slacks_controller.rb b/app/controllers/api/v1/slacks_controller.rb new file mode 100644 index 00000000..fe546a78 --- /dev/null +++ b/app/controllers/api/v1/slacks_controller.rb @@ -0,0 +1,17 @@ +module Api + module V1 + class SlacksController < ApplicationController + before_action :authenticate_user! + + def create + raise "User id #{current_user.id} does not have a saved email address." unless current_user.email.present? + + SlackJobs::InviterJob.perform_now current_user.email + + render json: { status: :ok } + rescue StandardError => e + render json: { errors: e.message }, status: :unprocessable_entity + end + end + end +end From 545cae1a1d12d3b04cb2ca64b5633b7b5d42f795 Mon Sep 17 00:00:00 2001 From: Harry Levine Date: Fri, 21 Jul 2017 15:18:23 -0600 Subject: [PATCH 3/4] Apiary docs for new endpoint --- apiary.apib | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/apiary.apib b/apiary.apib index d6258cb5..b6482087 100644 --- a/apiary.apib +++ b/apiary.apib @@ -210,6 +210,30 @@ API endpoints that Operation Code's Rails backend makes available to its React f errors: "Some error message" } +## Slack | Invite [/api/v1/slack] + +### Invite a User to Slack [POST] + ++ Request (application/json) + + + Headers + + Authorization: Bearer Access-Token + ++ Response 200 (application/json) + + + Body + + { + status: 200 + } + ++ Response 422 (application/json) + + { + errors: "Some error message" + } + ## Tag | Collection [/api/v1/tags] ### List All Tags [GET] From 6ed00b09c48f5ce41c890557d4ae8e10f97021ef Mon Sep 17 00:00:00 2001 From: Harry Levine Date: Fri, 21 Jul 2017 15:32:35 -0600 Subject: [PATCH 4/4] Renames API to be more in keeping with the action To be RESTful, we are creating a slack user. --- apiary.apib | 2 +- .../api/v1/{slacks_controller.rb => slack_users_controller.rb} | 2 +- config/routes.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename app/controllers/api/v1/{slacks_controller.rb => slack_users_controller.rb} (88%) diff --git a/apiary.apib b/apiary.apib index b6482087..65aa5894 100644 --- a/apiary.apib +++ b/apiary.apib @@ -210,7 +210,7 @@ API endpoints that Operation Code's Rails backend makes available to its React f errors: "Some error message" } -## Slack | Invite [/api/v1/slack] +## Slack User | Invite [/api/v1/slack_users] ### Invite a User to Slack [POST] diff --git a/app/controllers/api/v1/slacks_controller.rb b/app/controllers/api/v1/slack_users_controller.rb similarity index 88% rename from app/controllers/api/v1/slacks_controller.rb rename to app/controllers/api/v1/slack_users_controller.rb index fe546a78..d1484d05 100644 --- a/app/controllers/api/v1/slacks_controller.rb +++ b/app/controllers/api/v1/slack_users_controller.rb @@ -1,6 +1,6 @@ module Api module V1 - class SlacksController < ApplicationController + class SlackUsersController < ApplicationController before_action :authenticate_user! def create diff --git a/config/routes.rb b/config/routes.rb index 47e390cc..1ed0302f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,7 @@ resources :votes, only: [:create, :destroy] end resources :services, only: :index - resources :slacks, only: :create, path: 'slack' + resources :slack_users, only: :create resources :squads, only: [:index, :create, :show] do member do post 'join'