Class: Kenexa::Client

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

Constant Summary collapse

DEFAULT_ENDPOINT =
'http://import.brassring.com/WebRouter/WebRouter.asmx/route'
TEMPLATE_PATH =
File.dirname(__FILE__) + "/templates"

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = DEFAULT_ENDPOINT) ⇒ Client

Returns a new instance of Client.



16
17
18
# File 'lib/kenexa/client.rb', line 16

def initialize(endpoint = DEFAULT_ENDPOINT)
  @uri = URI.parse(endpoint)
end

Instance Method Details

#each_jobObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kenexa/client.rb', line 36

def each_job
  page = 1
  loop {
    jobs = jobs(:page => page)
    max_pages ||= jobs.max_pages

    jobs.each { |job|
      yield job
    }

    page += 1
    break if page > max_pages
  }
end

#jobs(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kenexa/client.rb', line 20

def jobs(options = {})
  page = options[:page] || 1
  template = ERB.new(File.read(TEMPLATE_PATH + "/request.erb"))
  inputXml = template.result(binding)
  response = Net::HTTP.post_form(@uri, "inputXml" => inputXml)
  doc = Nokogiri::XML response.body

  # i'm not sure what is up with the response that comes back, but
  # it appears to be an escaped string of XML. We need to get that
  # string an parse it with Nokogiri to be able to parse the
  # interesting pieces.
  envelope = Nokogiri::XML doc.children.first.text

  JobCollectionProxy.new(envelope)
end