Class: Janky::JobCreator::HTTP
- Inherits:
-
Object
- Object
- Janky::JobCreator::HTTP
- Defined in:
- lib/janky/job_creator.rb
Class Method Summary collapse
Class Method Details
.exists?(server_url, name) ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/janky/job_creator.rb', line 70 def self.exists?(server_url, name) uri = server_url user = uri.user pass = uri.password path = uri.path http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == "https" http.use_ssl = true end get = Net::HTTP::Get.new("#{path}/job/#{name}/") get.basic_auth(user, pass) if user && pass response = http.request(get) case response.code when "200" true when "404" false else Exception.push_http_response(response) raise "Failed to determine job existance" end end |
.run(server_url, name, config) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/janky/job_creator.rb', line 95 def self.run(server_url, name, config) uri = server_url user = uri.user pass = uri.password path = uri.path http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == "https" http.use_ssl = true end post = Net::HTTP::Post.new("#{path}/createItem?name=#{name}") post.basic_auth(user, pass) if user && pass post["Content-Type"] = "application/xml" post.body = config response = http.request(post) unless response.code == "200" Exception.push_http_response(response) raise Error, "Failed to create job" end end |