Class: Flying::Bot::Up

Inherits:
Object
  • Object
show all
Defined in:
lib/flying/bots/up.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUp

Returns a new instance of Up.



8
9
10
# File 'lib/flying/bots/up.rb', line 8

def initialize
  @message = "Ok."
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/flying/bots/up.rb', line 6

def message
  @message
end

Instance Method Details

#assess(referer, *options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/flying/bots/up.rb', line 12

def assess(referer, *options)
  begin
    response_code = get_http_response_code(referer)
  rescue
    Flying.an_error_ocurred(true)
    set_error_message(referer, false, $!)
    return false
  end
  return true if ["200", "302"].include? response_code
  Flying.an_error_ocurred(true)
  set_error_message(referer, response_code.to_s)
  false
end

#get_http_response_code(referer) ⇒ Object



40
41
42
# File 'lib/flying/bots/up.rb', line 40

def get_http_response_code referer
  Net::HTTP.get_response(URI(referer)).code
end

#message_not_foundObject



53
54
55
# File 'lib/flying/bots/up.rb', line 53

def message_not_found
  "The target was simply not found (404)."
end

#message_server_errorObject



57
58
59
# File 'lib/flying/bots/up.rb', line 57

def message_server_error
  "We got a response saying there's a server error (501)"
end

#message_unknown_errorObject

Messages



45
46
47
# File 'lib/flying/bots/up.rb', line 45

def message_unknown_error
  "An unknown error ocurred."
end

#message_unreachableObject



49
50
51
# File 'lib/flying/bots/up.rb', line 49

def message_unreachable
  "It is unreachable (is the url correct?)."
end

#set_error_message(referer, response_code, error_details = '') ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/flying/bots/up.rb', line 26

def set_error_message(referer, response_code, error_details = '')
  case response_code
  when false
    @message = message_unreachable
  when "404"
    @message = message_not_found
  when "501"
    @message = message_server_error
  else
    @message = message_unknown_error + "(#{error_details})"
  end
  @message = referer + ": " + @message
end