require 'open-uri' require 'timeout' require 'json' def coderwall(name, size = [60, 60]) begin cache = "#{@cache_path}/coderwall.json" json = File.read(cache) File::delete(cache) if Time::now > File::mtime( cache ) + 60*60*24 rescue Errno::ENOENT begin Timeout.timeout(10) do json = open( "https://coderwall.com/#{name}.json" ) {|f| f.read } end open(cache, 'wb') {|f| f.write(json) } rescue Timeout::Error return "" end end html = '
' JSON.parse(json)['badges'].each do |badge| html << %Q|#{badge['name']}| end html << '
' end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End: # vim: ts=3