Skip to content

Commit

Permalink
hacketyhack does not crash anymore when starting without an internet …
Browse files Browse the repository at this point in the history
…connection. in order to determine whether we hace a connection or not an HTTP request to the hacketyhack API is made in order to see whether the response is a HTTP Success
  • Loading branch information
PragTob committed Dec 31, 2011
1 parent 09b8752 commit be4e7b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/ui/tabs/home.rb
Expand Up @@ -15,8 +15,9 @@ def initialize *args, &blk
super *args, &blk
# never changes so is most efficient to load here
@samples = HH.samples
Upgrade::check_latest_version do |version| if version['version'] != HH::VERSION
home_bulletin(version['version'])
if Web.internet_connection?
Upgrade::check_latest_version do |version|
home_bulletin(version['version']) if version['version'] != HH::VERSION
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions lib/web/web.rb
Expand Up @@ -9,6 +9,22 @@ module Web
[JSON_MIME_TYPES, XML_MIME_TYPES].each do |ary|
ary.map! { |str| /^#{Regexp::quote(str)}/ }
end

# checking for an internet connection to deactivate functionality, requiring
# an internet connection when there is no connection or the API is down
def self.check_internet_connection
begin
HH::API.get "" do |response| return response.kind_of? Net::HTTPOK end
rescue
return false
end
end

# caching the result so we don't have to do a new request for each check
def self.internet_connection?
@connection ||= check_internet_connection
end

end

module Hpricot
Expand Down

0 comments on commit be4e7b4

Please sign in to comment.