-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.rb
More file actions
60 lines (53 loc) · 1.75 KB
/
errors.rb
File metadata and controls
60 lines (53 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
57
58
59
60
## ERRRRRORRRRRR HANDLLLLLINNNGG!! (say in the voice of Jon Lovitz as The Thespian)
module Errors
def twitter_api(&block)
begin
timeout &block
rescue *twitter_errors
end
end
def timeout(seconds = 1, &block)
Timeout.timeout(seconds, &block)
end
def twitter_errors
[Timeout::Error, Twitter::CantConnect]
end
def twitter_down!
background fail_whale_orange
image "whale.png", :width => 1.0, :height => 200
para "Too many tweets!", :align => "center"
para "Sorry, Twitter is over capacity. Wait, though, and ",
"the timeline will reload as soon as it can.", :align => "center"
end
def fail_status
Twitter::Status.new do |s|
s.text = "Twitter is over capacity. Timeline will continue to attempt to reload."
s.user = fail_user
s.created_at = Time.new.to_s
end
end
def fail_user
Twitter::User.new do |u|
u.profile_image_url = "whale.png"
u.name = "failwhale"
u.screen_name = "failwhale"
u.location = "an octopuses garden, in the shade"
u.url = "http://blog.twitter.com"
u.profile_background_color = fail_whale_orange
end
end
def fail_whale
image "whale.png",
:width => 45, :height => 45, :margin => 5
end
# Assuming that the maintenance page is up..
def maintenance_message
para *Hpricot(timeout { open("http://twitter.com") }).at("#content").
to_s.scan(/>([^<]+)</).flatten. # XXX poor man's "get all descendant text nodes"
reject { |x| x =~ /^\s*$/ }. # except stuff that is just whitespace
map { |x| x.squeeze(" ").strip }.join(" ")
rescue Timeout::Error, OpenURI::HTTPError
para "Twitter is down down down, probably just over capacity right now. ",
"Try again soon!"
end
end