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] when no transformation is given raw Hash / Array data is returned



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

def initialize(options = {})
  @api_key   = options.fetch(:api_key)   { fail Errors::InvalidConfiguration, "Missing api_key argument"   }
  @subdomain = options.fetch(:subdomain) { fail Errors::InvalidConfiguration, "Missing subdomain argument" }
  @transform_to   = options[:transform_to]   || {}
  @transform_from = options[:transform_from] || {}
end

Instance Method Details

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

create new candidate for given job

Parameters:

  • candidate (Hash)

    the candidate data as described in resources.workable.com/add-candidates-using-api 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



73
74
75
76
# File 'lib/workable/client.rb', line 73

def create_job_candidate(candidate, shortcode, stage_slug = nil)
  shortcode = "#{shortcode}/#{stage_slug}" unless stage_slug.nil?
  transform_to(:candidate, post_request("jobs/#{shortcode}/candidates", candidate)["candidate"])
end

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

list candidates for given job

Parameters:

  • shortcode (String)

    job shortcode to select candidates from

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

    extra options like stage_slug or limit

Options Hash (options):

  • :stage (String)

    optional stage 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



55
56
57
58
# File 'lib/workable/client.rb', line 55

def job_candidates(shortcode, options = {})
  url = build_job_candidates_url(shortcode, options)
  transform_to(:candidate, get_request(url)['candidates'])
end

#job_details(shortcode) ⇒ Object

request detailed information about job

Parameters:

  • shortcode (String)

    job short code



46
47
48
# File 'lib/workable/client.rb', line 46

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

#job_questions(shortcode) ⇒ Object

list of questions for job

Parameters:

  • shortcode (String)

    job short code



62
63
64
# File 'lib/workable/client.rb', line 62

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

#jobs(type = 'published') ⇒ Object

request jobs of given type

Parameters:

  • type (String) (defaults to: 'published')

    type of jobs to fetch, published by default



40
41
42
# File 'lib/workable/client.rb', line 40

def jobs(type = 'published')
  transform_to(:job, get_request("jobs?phase=#{type}")['jobs'])
end

#recruitersObject

list of external recruiters for company



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

def recruiters
  transform_to(:stage, get_request("recruiters")['recruiters'])
end

#stagesObject

list of stages defined for company



79
80
81
# File 'lib/workable/client.rb', line 79

def stages
  transform_to(:stage, get_request("stages")['stages'])
end