Class: AwesomeBot::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_bot/result.rb

Overview

Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(links, white_list_from_cli) ⇒ Result

Returns a new instance of Result.



15
16
17
18
19
20
21
22
# File 'lib/awesome_bot/result.rb', line 15

def initialize(links, white_list_from_cli)
  @links = links
  @w = white_list_from_cli

  return if @w.nil?
  @links_white_listed,
  @links = links.partition { |u| AwesomeBot.white_list @w, u }
end

Instance Attribute Details

#dupesObject

Returns the value of attribute dupes.



7
8
9
# File 'lib/awesome_bot/result.rb', line 7

def dupes
  @dupes
end

Returns the value of attribute links.



13
14
15
# File 'lib/awesome_bot/result.rb', line 13

def links
  @links
end

Returns the value of attribute links_white_listed.



12
13
14
# File 'lib/awesome_bot/result.rb', line 12

def links_white_listed
  @links_white_listed
end

#skip_dupeObject

Returns the value of attribute skip_dupe.



8
9
10
# File 'lib/awesome_bot/result.rb', line 8

def skip_dupe
  @skip_dupe
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/awesome_bot/result.rb', line 9

def status
  @status
end

#white_listedObject

Returns the value of attribute white_listed.



10
11
12
# File 'lib/awesome_bot/result.rb', line 10

def white_listed
  @white_listed
end

Instance Method Details

#statuses_issues(options = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/awesome_bot/result.rb', line 24

def statuses_issues(options=nil)
  options = {
    'timeout'=>false,
    'ssl'=>false,
    'redirect'=>false
  } if options.nil?

  s = status.select { |x| x['status'] != 200 }

  if options['timeout']
    s = s.reject do |x|
      ( (x['error'].message == 'Net::ReadTimeout') || (x['error'].message == 'execution expired') || (x['error'].message.include? 'timed out') ) unless x['error'].nil?
    end
  end

  if options['redirect']
    s = s.reject { |x| AwesomeBot.status_is_redirected? x['status'] }
  end

  if options['ssl']
    s =  s.reject do |x|
      ( (x['error'].message.include? 'server certificate') || (x['error'].message.include? 'SSL_connect') ) unless x['error'].nil?
    end
  end

  unless options['errors'].nil?
    options['errors'].each do |c|
      s = s.reject { |x| x['status']==c.to_i }
    end
  end

  s
end

#success(options) ⇒ Object



58
59
60
# File 'lib/awesome_bot/result.rb', line 58

def success(options)
  success_dupe && success_links(options)
end

#success_dupeObject



62
63
64
65
# File 'lib/awesome_bot/result.rb', line 62

def success_dupe
  return true if skip_dupe
  links.uniq.count == links.count
end


67
68
69
# File 'lib/awesome_bot/result.rb', line 67

def success_links(options)
  statuses_issues(options).count==0
end

#white_listingObject



71
72
73
# File 'lib/awesome_bot/result.rb', line 71

def white_listing
  !@w.nil?
end

#write(filename) ⇒ Object



75
76
77
78
79
80
# File 'lib/awesome_bot/result.rb', line 75

def write(filename)
  require 'json'

  r = write_artifacts
  File.open(filename, 'w') { |f| f.write JSON.pretty_generate(r) }
end

#write_artifactsObject



82
83
84
85
86
87
88
89
90
# File 'lib/awesome_bot/result.rb', line 82

def write_artifacts
  require 'date'
  {
    'date'=>Time.now,
    'links'=>@links,
    'issues'=>statuses_issues,
    'all'=>status
  }
end