Class: NotifyIntegrity
- Inherits:
-
Object
- Object
- NotifyIntegrity
- Defined in:
- lib/notify-integrity.rb
Instance Method Summary collapse
-
#auth(user, pass) ⇒ Object
# Adds authentication information of Integrity instance.
-
#check_for_success(uri) ⇒ Object
# Queries integrity until the build has succeeded.
-
#post_request(host, path, payload = {}) ⇒ Object
# Do a POST request to integrity.
-
#request_page(uri) ⇒ Object
# Requests a page from integrity.
Instance Method Details
#auth(user, pass) ⇒ Object
# Adds authentication information of Integrity instance.
11 12 13 14 |
# File 'lib/notify-integrity.rb', line 11 def auth user, pass @integrity_user = user @integrity_pass = pass end |
#check_for_success(uri) ⇒ Object
# Queries integrity until the build has succeeded.
WARNING: in current form, this continues looping until the integrity responds success or goes down by some server failure. I’ve had some situations where Integrity has created infinite build loop, which would cause this to loop infinitely too. Patches welcome.
Returns true is success, false if not
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/notify-integrity.rb', line 65 def check_for_success uri element = nil while true page = request_page uri element = page.parser.at_xpath "//div[@class='building']" break if element.to_s == "" sleep 1 end element = page.parser.at_xpath "//div[@class='success']" # failure if element.to_s == "" success = false else success = true end success end |
#post_request(host, path, payload = {}) ⇒ Object
# Do a POST request to integrity.
TODO: this should use Mechanize too. uses Net::HTTP
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/notify-integrity.rb', line 22 def post_request host, path, payload = {} uri = URI("#{host}#{path}") req = Net::HTTP::Post.new uri.path req.basic_auth @integrity_user, @integrity_pass unless @integrity_user.nil? req.set_form_data payload result = nil Net::HTTP.start(uri.hostname, uri.port) do |http| result = http.request(req) end if result.instance_of? Net::HTTPNotFound raise Net::HTTPNotFound, "Requested page does not exist (404). host: #{host}, path: #{path}" result = nil end result end |
#request_page(uri) ⇒ Object
# Requests a page from integrity.
uses Mechanize
46 47 48 49 50 51 52 53 |
# File 'lib/notify-integrity.rb', line 46 def request_page uri raise "invalid uri" if uri.nil? raise "integrity user or pass missing" if @integrity_user.nil? or @integrity_pass.nil? agent = Mechanize.new agent.add_auth uri, @integrity_user, @integrity_pass agent.get uri end |