I'm trying to call it from Mac OS X Yosemite 10.10.2 and am getting the following error:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:223:in `open_loop': redirection forbidden: http://blockchain.info/blocks/Slush?format=json -> https://blockchain.info/blocks/Slush?format=json (RuntimeError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:149:in `open_uri'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:689:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:34:in `open'
from blockfound.rb:83:in `
If I try to directly access the same URL (https://blockchain.info/blocks/Slush?format=json) from a browser, it works.
So I googled the problem and found this page:
http://stackoverflow.com/questions/10013293/open-uri-is-not-redirecing-http-to-https
I installed the open_uri_redirections gem, then made the minor mods to your script to allow redirections, and it works.
Here's the text of the patch, if you're interested:
--- blockfound.rb 2015-03-18 07:59:25.000000000 -0700
***************
*** 1,6 ****
--- 1,7 ----
require 'rubygems'
require 'json'
require 'open-uri'
+ require 'open_uri_redirections'
require 'yaml'
require 'net/https'
require 'optparse'
***************
*** 54,60 ****
oldschool = res["oldschool"]
if oldschool == true
#slush specific
! result = JSON.load(open("http://mining.bitcoin.cz/stats/json/"))
#pool speed
gh = result["ghashes_ps"]
--- 55,61 ----
oldschool = res["oldschool"]
if oldschool == true
#slush specific
! result = JSON.load(open("http://mining.bitcoin.cz/stats/json/", :allow_redirections => :safe))
#pool speed
gh = result["ghashes_ps"]
***************
*** 80,86 ****
#clean up %20 if present
pool_name = res["pool"]
pool_name.gsub!('%20', ' ')
! bc_pjson = JSON.load(open(bcurl))
bc_latest_height = bc_pjson["blocks"][0]["height"]
bc_latest_time = Time.at(bc_pjson["blocks"][0]["time"]).utc
bc_second_time = Time.at(bc_pjson["blocks"][1]["time"]).utc
--- 81,87 ----
#clean up %20 if present
pool_name = res["pool"]
pool_name.gsub!('%20', ' ')
! bc_pjson = JSON.load(open(bcurl, :allow_redirections => :safe))
bc_latest_height = bc_pjson["blocks"][0]["height"]
bc_latest_time = Time.at(bc_pjson["blocks"][0]["time"]).utc
bc_second_time = Time.at(bc_pjson["blocks"][1]["time"]).utc
Maybe an alternative simpler patch (which I didn't try) would be to change the URLs to https to avoid redirection.