Skip to content

Instantly share code, notes, and snippets.

@sircharleswatson
Created July 9, 2014 16:23
Show Gist options
  • Save sircharleswatson/c231b74fe4cd8626d907 to your computer and use it in GitHub Desktop.
Save sircharleswatson/c231b74fe4cd8626d907 to your computer and use it in GitHub Desktop.
Gist for the World Cup geeklet @ http://softwareforgood.com/hello-world-cup/
#!/usr/bin/env ruby
require 'json'
require 'httparty'
BASE_URL = "http://worldcup.sfg.io/"
def get_json(url)
response = HTTParty.get(url)
json = JSON.parse(response.body)
return json
end
def prepare_matches(matches)
matches.each do |match|
home_team = match["home_team"]
away_team = match["away_team"]
format_board(home_team, away_team)
end
end
def format_board(home, away)
print "#{away["code"]}" + " " * 19 + "#{home["code"]}"
print "\n" * 2
print "#{away["goals"]} - #{home["goals"]}"
print "\n" * 2
end
def today
url = "#{BASE_URL}matches/today"
matches = get_json(url)
if matches.count == 0
puts "No matches today"
else
prepare_matches(matches)
end
end
today
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment