Class: Flying::Bot::Up
- Inherits:
-
Object
- Object
- Flying::Bot::Up
- Defined in:
- lib/flying/bots/up.rb
Instance Attribute Summary collapse
-
#dependency ⇒ Object
> Name.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#name ⇒ Object
> Name.
-
#referer ⇒ Object
readonly
Returns the value of attribute referer.
Instance Method Summary collapse
-
#assess ⇒ Object
Starts assessment of the current service using variables set during initialization.
- #get_http_response_code(referer) ⇒ Object
-
#initialize(referer, options = {}) ⇒ Up
constructor
A new instance of Up.
- #message_not_found ⇒ Object
- #message_server_error ⇒ Object
-
#message_unknown_error ⇒ Object
Messages.
- #message_unreachable ⇒ Object
- #set_error_message(referer, response_code, error_details = '') ⇒ Object
Constructor Details
#initialize(referer, options = {}) ⇒ Up
Returns a new instance of Up.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/flying/bots/up.rb', line 22 def initialize(referer, = {}) @referer = referer @options = @message = "Ok." @error = false @name = [:as] if .include?(:as) @dependency = [] # Dependency can be one or an array of symbols, whereas @dependency # must be only a flat array if .include?(:depends_on) @dependency << [:depends_on] if [:depends_on].kind_of? Symbol @dependency = [:depends_on] if [:depends_on].kind_of? Array end end |
Instance Attribute Details
#dependency ⇒ Object
> Name
How a service is known. Useful reusing and setting dependencies.
e.g. `site "etc.com", :as => :google`
name is :google.
> Dependency
When a service depends on another, it has dependencies. This is an array with the Name of each service.
20 21 22 |
# File 'lib/flying/bots/up.rb', line 20 def dependency @dependency end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/flying/bots/up.rb', line 6 def error @error end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/flying/bots/up.rb', line 6 def @message end |
#name ⇒ Object
> Name
How a service is known. Useful reusing and setting dependencies.
e.g. `site "etc.com", :as => :google`
name is :google.
> Dependency
When a service depends on another, it has dependencies. This is an array with the Name of each service.
20 21 22 |
# File 'lib/flying/bots/up.rb', line 20 def name @name end |
#referer ⇒ Object (readonly)
Returns the value of attribute referer.
6 7 8 |
# File 'lib/flying/bots/up.rb', line 6 def referer @referer end |
Instance Method Details
#assess ⇒ Object
Starts assessment of the current service using variables set during initialization
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/flying/bots/up.rb', line 40 def assess @error = false begin response_code = get_http_response_code(@referer) rescue Flying.an_error_ocurred(true) (@referer, false, $!) return false end return true if ["200", "302"].include? response_code Flying.an_error_ocurred(true) (@referer, response_code.to_s) false end |
#get_http_response_code(referer) ⇒ Object
70 71 72 |
# File 'lib/flying/bots/up.rb', line 70 def get_http_response_code referer Net::HTTP.get_response(URI(referer)).code end |
#message_not_found ⇒ Object
83 84 85 |
# File 'lib/flying/bots/up.rb', line 83 def "The target was simply not found (404)." end |
#message_server_error ⇒ Object
87 88 89 |
# File 'lib/flying/bots/up.rb', line 87 def "We got a response saying there's a server error (501)" end |
#message_unknown_error ⇒ Object
Messages
75 76 77 |
# File 'lib/flying/bots/up.rb', line 75 def "An unknown error ocurred." end |
#message_unreachable ⇒ Object
79 80 81 |
# File 'lib/flying/bots/up.rb', line 79 def "It is unreachable (is the url correct?)." end |
#set_error_message(referer, response_code, error_details = '') ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/flying/bots/up.rb', line 55 def (referer, response_code, error_details = '') @error = true case response_code when false @message = when "404" @message = when "501" @message = else @message = + "(#{error_details})" end @message = "\e[31m" + referer + ": " + @message + "\e[0m" end |