Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hacketyhack may now start without an internet connection #142

Merged
merged 1 commit into from

2 participants

Tobias Pfeiffer Steve Klabnik
Tobias Pfeiffer
Collaborator

hacketyhack does not crash any more when starting without an Internet connection. The only place where I had to check for this was the check for the latest version.

In order to determine whether we have a connection or not an HTTP request to the hacketyhack API is made in order to see whether the response is a HTTP Success.

I went with this approach rather than just rescuing the error, because the same function could be used to deactivate other Internet related functionality (Register a new account, Upload button of the editor).

This should close issue #140 (is there a way to get this pull request directly into this issue?)

Tobias Pfeiffer PragTob hacketyhack does not crash anymore when starting without an internet …
…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
be4e7b4
Steve Klabnik steveklabnik merged commit 3f714ff into from
Steve Klabnik
Owner

Awesome, thanks!

(is there a way to get this pull request directly into this issue?)

Nope. You can say "Closes #140" in the commit message and it'll close the related issue though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 31, 2011
  1. Tobias Pfeiffer

    hacketyhack does not crash anymore when starting without an internet …

    PragTob authored
    …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
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 2 deletions.
  1. +3 −2 app/ui/tabs/home.rb
  2. +16 −0 lib/web/web.rb
5 app/ui/tabs/home.rb
View
@@ -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
16 lib/web/web.rb
View
@@ -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
Something went wrong with that request. Please try again.