Module: HTTP
- Included in:
- Inari::Commands
- Defined in:
- lib/inari/commands/http.rb
Instance Method Summary collapse
- #first_response ⇒ Object
-
#get_web_page(page, &block) ⇒ Object
Fetches a web page and notifies when a timeout occurs or the page returns an unexpected status.
- #page_content(response = nil) ⇒ Object
-
#page_size(response = nil) ⇒ Object
HTTP commands.
- #set_first_response(response) ⇒ Object
-
#watch_for_changes_on_page(page, &block) ⇒ Object
Raises an alert when a page changes.
Instance Method Details
#first_response ⇒ Object
43 |
# File 'lib/inari/commands/http.rb', line 43 def first_response ; @first_response[current_host] ; end |
#get_web_page(page, &block) ⇒ Object
Fetches a web page and notifies when a timeout occurs or the page returns an unexpected status.
Supply a block to use something instead of Net::HTTP.get_response
19 20 21 22 23 24 |
# File 'lib/inari/commands/http.rb', line 19 def get_web_page(page, &block) response, down = get_remote_response(page, &block) add_response(page, response, down) response.code == '200' end |
#page_content(response = nil) ⇒ Object
10 11 12 13 |
# File 'lib/inari/commands/http.rb', line 10 def page_content(response = nil) response = last_response if response.nil? response.body rescue nil end |
#page_size(response = nil) ⇒ Object
HTTP commands
5 6 7 8 |
# File 'lib/inari/commands/http.rb', line 5 def page_size(response = nil) response = last_response if response.nil? response.body.size rescue 0 end |
#set_first_response(response) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/inari/commands/http.rb', line 36 def set_first_response(response) @first_response ||= {} returning @first_response[current_host].nil? do |added| @first_response[current_host] = response unless !added end end |
#watch_for_changes_on_page(page, &block) ⇒ Object
Raises an alert when a page changes.
27 28 29 30 31 32 33 34 |
# File 'lib/inari/commands/http.rb', line 27 def watch_for_changes_on_page(page, &block) # Fetch a fresh copy of the page and retain the last one response, down = get_remote_response(page, &block) returning (!set_first_response(response) and changed?(response)) do |state| add_response(page, last_response, state) end end |