Skip to content
This repository

Hacketyhack may now start without an internet connection #142

Merged
merged 1 commit into from over 2 years ago

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 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 January 01, 2012
Steve Klabnik steveklabnik closed this January 01, 2012
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

Showing 1 unique commit by 1 author.

Dec 31, 2011
Tobias Pfeiffer 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
This page is out of date. Refresh to see the latest.
5  app/ui/tabs/home.rb
@@ -15,8 +15,9 @@ def initialize *args, &blk
15 15
     super *args, &blk
16 16
     # never changes so is most efficient to load here
17 17
     @samples = HH.samples
18  
-    Upgrade::check_latest_version do |version| if version['version'] != HH::VERSION
19  
-        home_bulletin(version['version'])
  18
+    if Web.internet_connection?
  19
+      Upgrade::check_latest_version do |version| 
  20
+        home_bulletin(version['version']) if version['version'] != HH::VERSION
20 21
       end
21 22
     end
22 23
   end
16  lib/web/web.rb
@@ -9,6 +9,22 @@ module Web
9 9
   [JSON_MIME_TYPES, XML_MIME_TYPES].each do |ary|
10 10
     ary.map! { |str| /^#{Regexp::quote(str)}/ }
11 11
   end
  12
+  
  13
+  # checking for an internet connection to deactivate functionality, requiring
  14
+  # an internet connection when there is no connection or the API is down
  15
+  def self.check_internet_connection
  16
+    begin
  17
+      HH::API.get "" do |response| return response.kind_of? Net::HTTPOK end
  18
+    rescue
  19
+      return false
  20
+    end
  21
+  end
  22
+  
  23
+  # caching the result so we don't have to do a new request for each check
  24
+  def self.internet_connection?
  25
+    @connection ||= check_internet_connection
  26
+  end
  27
+  
12 28
 end
13 29
 
14 30
 module Hpricot
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.