Class: Hudson::HudsonObject

Inherits:
Object
  • Object
show all
Defined in:
lib/hudson-remote-api.rb

Overview

Base class for all Hudson objects

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_xml(url) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hudson-remote-api.rb', line 25

def self.get_xml(url)
  puts url
  uri = URI.parse(url)
  host = uri.host
  port = uri.port
  path = uri.path
  request = Net::HTTP::Get.new(path)
  request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
  request['Content-Type'] = "text/xml"
  response = Net::HTTP.start(host, port){|http| http.request(request)}

  if response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
    encoding = response.get_fields("Content-Encoding")
    if encoding and encoding.include?("gzip")
      return Zlib::GzipReader.new(StringIO.new(response.body)).read
    else
      return response.body
    end
  else
    puts response
    raise APIError, "Error retrieving #{path}"
  end
end

.load_xml_apiObject



18
19
20
21
# File 'lib/hudson-remote-api.rb', line 18

def self.load_xml_api
  @@hudson_xml_api_path = File.join(Hudson[:url], "api/xml")
  @@xml_api_create_item_path = File.join(Hudson[:url], "createItem")
end

Instance Method Details

#get_xml(path) ⇒ Object



49
50
51
# File 'lib/hudson-remote-api.rb', line 49

def get_xml(path)
  self.class.get_xml(path)
end

#send_post_request(url, data = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/hudson-remote-api.rb', line 53

def send_post_request(url, data={})
  uri = URI.parse(url)
  host = uri.host
  port = uri.port
  path = uri.path
  request = Net::HTTP::Post.new(path)
  request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
  request.set_form_data(data)
  #puts request.to_yaml
  Net::HTTP.new(host, port).start{|http| http.request(request)}
end

#send_xml_post_request(url, xml) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/hudson-remote-api.rb', line 65

def send_xml_post_request(url, xml)
  uri = URI.parse(url)
  host = uri.host
  port = uri.port
  path = uri.path
  request = Net::HTTP::Post.new(path)
  request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
  request.body = xml
  #puts request.body
  #puts request.to_yaml
  Net::HTTP.new(host, port).start{|http| http.request(request)}
end