Skip to content

Commit

Permalink
Add candidate applications endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
leosoto committed Jan 11, 2020
1 parent 02c6138 commit 1197608
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ApplicationController < ActionController::API
include ActionController::HttpAuthentication::Token::ControllerMethods
before_action :require_valid_auth_token_and_set_session

def require_valid_auth_token_and_set_session
authenticate_or_request_with_http_token do |token, options|
@session = Session.where(token: token).first
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/candidates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ class CandidatesController < ApplicationController
def search
render json: @session.search_candidates(params[:query])
end

def applications
render json: @session.candidate_applications(params[:id])
end
end
2 changes: 1 addition & 1 deletion app/controllers/jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ def closed
def show
render json: @session.job(request.fullpath)
end

end
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class SessionsController < ApplicationController
skip_before_action :require_valid_auth_token_and_set_session

def create
session = Session.where(email: session_params[:email]).first_or_initialize
session.update(session_params)
Expand Down
25 changes: 23 additions & 2 deletions app/models/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ def job(job_url)
def search_candidates(query, page = nil)
page = [page.to_i, 1].max
parse_candidates(
get("/candidates.json?search=#{CGI.escape(query)}&page=#{page}"))
get("/candidates.json?search=#{CGI.escape(query)}&page=#{page}")[:webpros]
)
end

def candidate_applications(candidate_id)
parse_candidate_applications(
get("/candidates/#{candidate_id}/applications.json")[:job_applications]
)
end

private
Expand Down Expand Up @@ -72,7 +79,7 @@ def parse_jobs(gob_jobs)
end

def parse_candidates(candidates)
candidates[:webpros].map do |candidate|
candidates.map do |candidate|
parse_candidate(candidate)
end
end
Expand All @@ -86,6 +93,20 @@ def parse_candidate(candidate)
)
end

def parse_candidate_applications(candidate_applications)
candidate_applications.map do |candidate_application|
parse_candidate_application(candidate_application)
end
end

def parse_candidate_application(candidate_application)
candidate_application.slice(
:id, :url, :job_title, :phase_title,
:sent_at, :sent_at_full,
:messages_count, :notes_count,
:discard_reason
)
end

def email_and_password_work
get('/dashboard.json')
Expand Down
8 changes: 6 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
collection do
post 'search'
end

member do
get '/applications', to: 'candidates#applications'
end
end
resources :jobs, only: [] do
collection do
collection do
get 'active'
get 'closed'
get 'closed'
end

member do
Expand Down
19 changes: 19 additions & 0 deletions spec/requests/candidates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
).first_or_create!
end
let(:token) { session.token }
let(:some_candidate) { session.search_candidates('ruby').first }


path '/candidates/search' do
post('Search candidates') do
Expand All @@ -23,4 +25,21 @@
end
end
end

path '/candidates/{id}/applications' do
get('Candidate applications') do
parameter name: :id, in: :path, type: :string
produces 'application/json'
security [ token: [] ]

response(200, 'list of candidate applications') do
schema type: :array, items: {
'$ref' => '#/definitions/candidate_application_object'
}
let(:Authorization) { "Bearer #{token}" }
let(:id) { some_candidate[:id] }
run_test!
end
end
end
end
15 changes: 15 additions & 0 deletions spec/swagger_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@
twitter_link: { type: :string, 'x-nullable' => true },
},
required: [:id, :name, :email]
},

candidate_application_object: {
type: :object,
properties: {
id: { type: :string },
url: { type: :string },
job_title: { type: :string },
phase_title: { type: :string },
sent_at: { type: :string },
sent_at_full: { type: :string },
messages_count: { type: :integer },
notes_count: { type: :integer },
discard_reason: { type: :string, 'x-nullable' => true },
}
}
}

Expand Down
41 changes: 41 additions & 0 deletions swagger/v1/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ paths:
type: array
items:
"$ref": "#/definitions/candidate_object"
"/candidates/{id}/applications":
get:
summary: Candidate applications
parameters:
- name: id
in: path
type: string
required: true
produces:
- application/json
security:
- token: []
responses:
'200':
description: list of candidate applications
schema:
type: array
items:
"$ref": "#/definitions/candidate_application_object"
"/jobs/active":
get:
summary: List active jobs
Expand Down Expand Up @@ -262,3 +281,25 @@ definitions:
- id
- name
- email
candidate_application_object:
type: object
properties:
id:
type: string
url:
type: string
job_title:
type: string
phase_title:
type: string
sent_at:
type: string
sent_at_full:
type: string
messages_count:
type: integer
notes_count:
type: integer
discard_reason:
type: string
x-nullable: true

0 comments on commit 1197608

Please sign in to comment.