Skip to content

Commit

Permalink
extract out the helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
tuo committed Sep 3, 2011
1 parent 425726e commit 410b1f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
18 changes: 18 additions & 0 deletions lib/jenkins-remote-api/ci/helper/xml_helper.rb
@@ -0,0 +1,18 @@
require 'rubygems'
require 'mechanize'
module Ci
module XmlHelper

def retrieve_xml_from(url)
xml = nil
begin
Mechanize.new.get(url) do |page|
xml = page.body
end
rescue Mechanize::ResponseCodeError => e
raise "Error in grabbing xml of #{url} due to network problem."
end
xml
end
end
end
14 changes: 4 additions & 10 deletions lib/jenkins-remote-api/ci/jenkins.rb
@@ -1,8 +1,9 @@
require 'mechanize'
require 'libxml'
module Ci
require "#{File.dirname(__FILE__)}/helper/xml_helper.rb"
module Ci
class Jenkins
include LibXML
include XmlHelper

attr_accessor :ci_address

Expand All @@ -18,15 +19,8 @@ def ci_address
end

def list_all_job_names
xml = ""
xml_url = ci_address + "api/xml"
begin
Mechanize.new.get(xml_url) do |page|
xml = page.body
end
rescue Mechanize::ResponseCodeError => e
raise "Error in grabbing xml of #{xml_url} due to network problem."
end
xml = retrieve_xml_from(xml_url)
parser = LibXML::XML::Parser.string(xml)
begin
doc = parser.parse
Expand Down

0 comments on commit 410b1f9

Please sign in to comment.