Class: Workable::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/workable/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

set access to workable and data transformation methods

Examples:

transformation for candidates using ‘MyApp::Candidate.find_and_update_or_create`

client = Workable::Client.new(
  api_key: 'api_key',
  subdomain: 'your_subdomain',
  transform_to: {
    candidate: &MyApp::Candidate.method(:find_and_update_or_create)
  }
)

Linkedin gem style with Mash

require "hashie"
 client = Workable::Client.new(
   api_key: 'api_key',
   subdomain: 'your_subdomain',
   transform_to: {
     candidate: &Hashie::Mash.method(:new)
   }
 )

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :api_key (String)

    api key for workable

  • :subdomain (String)

    company subdomain in workable

  • :transform_to (Hash<Symbol: Proc>)

    mapping of transformations for data available transformations: [:job, :candidate, :question, :stage, :recruiter, :member] when no transformation is given raw Hash / Array data is returned



30
31
32
33
34
35
# File 'lib/workable/client.rb', line 30

def initialize(options = {})
  @api_key   = options.fetch(:api_key)   { configuration_error 'Missing api_key argument'   }
  @subdomain = options.fetch(:subdomain) { configuration_error 'Missing subdomain argument' }
  @transform_to   = Transformation.new(options[:transform_to])
  @transform_from = Transformation.new(options[:transform_from])
end

Instance Method Details

#aboutObject

return information about your account



38
39
40
# File 'lib/workable/client.rb', line 38

def about
  get_request('')
end

#copy(candidate_id, member_id, shortcode, stage = nil) ⇒ Object

copy a candidate to another job

Parameters:

  • candidate_id (String)

    the candidate’s id

  • member_id (String)

    id of the member performing the copy

  • shortcode (String)

    shortcode of the job that the candidate will be copied to

  • stage (String) (defaults to: nil)

    stage the candidate should be copied to



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/workable/client.rb', line 176

def copy(candidate_id, member_id, shortcode, stage = nil)
  body = {
    member_id: member_id,
    target_job_shortcode: shortcode,
    target_stage: stage
  }

  response = post_request("candidates/#{candidate_id}/copy") do |request|
    request.body = body.to_json
  end

  @transform_to.apply(:candidate, response['candidate'])
end

#create_comment(candidate_id, member_id, comment_text, policy = [], attachment = nil) ⇒ Object

create a comment on the candidate’s timeline

Parameters:

  • candidate_id (String)

    the candidate’s id

  • member_id (String)

    id of the member leaving the comment

  • comment_text (String)

    the comment’s text

  • policy (String) (defaults to: [])

    option to set the view rights of the comment

  • attachment (Hash) (defaults to: nil)

    optional attachment for the comment

  • attachment (defaults to: nil)

    :name [String] filename of the attachment

  • attachment (defaults to: nil)

    :data [String] payload of the attachment, encoded in base64



144
145
146
147
148
149
150
# File 'lib/workable/client.rb', line 144

def create_comment(candidate_id, member_id, comment_text, policy = [], attachment = nil)
  comment = { body: comment_text, policy: policy, attachment: attachment }

  post_request("candidates/#{candidate_id}/comments") do |request|
    request.body = { member_id: member_id, comment: comment }.to_json
  end
end

#create_job_candidate(candidate, shortcode, stage_slug = nil) ⇒ Hash

create new candidate for given job

Parameters:

  • candidate (Hash)

    the candidate data as described in workable.readme.io/docs/job-candidates-create including the ‘“candidate”=>{}` part

  • shortcode (String)

    job short code

  • stage_slug (String) (defaults to: nil)

    optional stage slug

Returns:

  • (Hash)

    the candidate information without ‘“candidate”=>{}` part



126
127
128
129
130
131
132
133
134
# File 'lib/workable/client.rb', line 126

def create_job_candidate(candidate, shortcode, stage_slug = nil)
  shortcode = "#{shortcode}/#{stage_slug}" if stage_slug

  response = post_request("jobs/#{shortcode}/candidates") do |request|
    request.body = @transform_from.apply(:candidate, candidate).to_json
  end

  @transform_to.apply(:candidate, response['candidate'])
end

#create_rating(candidate_id, member_id, comment, score) ⇒ Object

creates a rating for a candidate

Parameters:

  • candidate_id (String)

    the candidate’s id

  • member_id (String)

    id of the member adding the rating

  • comment (String)

    a comment about the scoring of the candidate

  • score (String)

    one of ‘negative’, ‘positive’, or ‘definitely’



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/workable/client.rb', line 224

def create_rating(candidate_id, member_id, comment, score)
  body = {
    member_id: member_id,
    comment: comment,
    score: score
  }

  post_request("candidates/#{candidate_id}/ratings") do |request|
    request.body = body.to_json
  end
end

#disqualify(candidate_id, member_id, reason = nil) ⇒ Object

disqualify a candidate

Parameters:

  • candidate_id (String)

    the candidate’s id

  • member_id (String)

    id of the member performing the disqualification

  • reason (String) (defaults to: nil)

    why the candidate should be disqualified



156
157
158
159
160
# File 'lib/workable/client.rb', line 156

def disqualify(candidate_id, member_id, reason = nil)
  post_request("candidates/#{candidate_id}/disqualify") do |request|
    request.body = { member_id: member_id, disqualification_reason: reason }.to_json
  end
end

#job_application_form(shortcode) ⇒ Object

application form questions for job

Parameters:

  • shortcode (String)

    job short code



83
84
85
# File 'lib/workable/client.rb', line 83

def job_application_form(shortcode)
  @transform_to.apply(:question, get_request("jobs/#{shortcode}/application_form"))
end

#job_candidate(shortcode, id) ⇒ Object

return the full object of a specific candidate

Parameters:

  • shortcode (String)

    job shortcode to select candidate from

  • id (String)

    candidates’s id



115
116
117
# File 'lib/workable/client.rb', line 115

def job_candidate(shortcode, id)
  @transform_to.apply(:candidate, get_request("jobs/#{shortcode}/candidates/#{id}")['candidate'])
end

#job_candidates(shortcode, params = {}) ⇒ Object

list candidates for given job

Parameters:

  • shortcode (String)

    job shortcode to select candidates from

  • params (Hash) (defaults to: {})

    extra options like ‘state` or `limit`

Options Hash (params):

  • :state (String)

    optional state slug, if not given candidates are listed for all stages

  • :limit (Number|String)

    optional limit of candidates to download, if not given all candidates are listed

  • :since_id (String)

    Returns results with an ID more than or equal to the specified ID.

  • :max_id (String)

    Returns results with an ID less than or equal to the specified ID.

  • :created_after (Timestamp|Integer)

    Returns results created after the specified timestamp.

  • :updated_after (Timestamp|Integer)

    Returns results updated after the specified timestamp.



108
109
110
# File 'lib/workable/client.rb', line 108

def job_candidates(shortcode, params = {})
  build_collection("jobs/#{shortcode}/candidates", :candidate, 'candidates', params)
end

#job_details(shortcode) ⇒ Object

request detailed information about job

Parameters:

  • shortcode (String)

    job short code



71
72
73
# File 'lib/workable/client.rb', line 71

def job_details(shortcode)
  @transform_to.apply(:job, get_request("jobs/#{shortcode}"))
end

#job_members(shortcode) ⇒ Object

return a collection of job’s members

Parameters:

  • shortcode (String)

    job short code



89
90
91
# File 'lib/workable/client.rb', line 89

def job_members(shortcode)
  @transform_to.apply(:member, get_request("jobs/#{shortcode}/members")['members'])
end

#job_questions(shortcode) ⇒ Object

list of questions for job

Parameters:

  • shortcode (String)

    job short code



77
78
79
# File 'lib/workable/client.rb', line 77

def job_questions(shortcode)
  @transform_to.apply(:question, get_request("jobs/#{shortcode}/questions")['questions'])
end

#job_recruiters(shortcode) ⇒ Object

return a collection of the job’s external recruiters

Parameters:

  • shortcode (String)

    job short code



95
96
97
# File 'lib/workable/client.rb', line 95

def job_recruiters(shortcode)
  @transform_to.apply(:recruiter, get_request("jobs/#{shortcode}/recruiters")['recruiters'])
end

#jobs(params = {}) ⇒ Object

request posted jobs

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • optional (Hash)

    filter parameters

  • :state (String)

    Returns jobs with the current state. Possible values (draft, published, archived & closed)

  • :limit (Integer)

    Specifies the number of jobs to try and retrieve per page

  • :since_id (String)

    Returns results with an ID more than or equal to the specified ID.

  • :max_id (String)

    Returns results with an ID less than or equal to the specified ID.

  • :created_after (Timestamp|Integer)

    Returns results created after the specified timestamp.

  • :updated_after (Timestamp|Integer)

    Returns results updated after the specified timestamp.



65
66
67
# File 'lib/workable/client.rb', line 65

def jobs(params = {})
  build_collection('jobs', :job, 'jobs', params)
end

#membersObject

returns a collection of your account members



43
44
45
# File 'lib/workable/client.rb', line 43

def members
  @transform_to.apply(:member, get_request('members')['members'])
end

#move(candidate_id, member_id, stage) ⇒ Object

moves a candidate to another stage

Parameters:

  • candidate_id (String)

    the candidate’s id

  • member_id (String)

    id of the member performing the move

  • stage (String)

    stage the candidate should be moved to



213
214
215
216
217
# File 'lib/workable/client.rb', line 213

def move(candidate_id, member_id, stage)
  post_request("candidates/#{candidate_id}/move") do |request|
    request.body = { member_id: member_id, target_stage: stage }.to_json
  end
end

#recruitersObject

returns a collection of your account external recruiters



48
49
50
# File 'lib/workable/client.rb', line 48

def recruiters
  @transform_to.apply(:recruiter, get_request('recruiters')['recruiters'])
end

#relocate(candidate_id, member_id, shortcode, stage = nil) ⇒ Object

moves a candidate to another job

Parameters:

  • candidate_id (Number|String)

    the candidate’s id

  • member_id (Number|String)

    id of the member performing the relocation

  • shortcode (String)

    shortcode of the job that the candidate will be moved to

  • stage (String) (defaults to: nil)

    stage the candidate should be moved to



195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/workable/client.rb', line 195

def relocate(candidate_id, member_id, shortcode, stage = nil)
  body = {
    member_id: member_id,
    target_job_shortcode: shortcode,
    target_stage: stage
  }

  response = post_request("candidates/#{candidate_id}/relocate") do |request|
    request.body = body.to_json
  end

  @transform_to.apply(:candidate, response['candidate'])
end

#revert(candidate_id, member_id) ⇒ Object

revert a candidate’s disqualification

Parameters:

  • candidate_id (String)

    the candidate’s id

  • member_id (String)

    id of the member reverting the disqualification



165
166
167
168
169
# File 'lib/workable/client.rb', line 165

def revert(candidate_id, member_id)
  post_request("candidates/#{candidate_id}/revert") do |request|
    request.body = { member_id: member_id }.to_json
  end
end

#stagesObject

returns a collection of your recruitment pipeline stages



53
54
55
# File 'lib/workable/client.rb', line 53

def stages
  @transform_to.apply(:stage, get_request('stages')['stages'])
end