worldcup-2014 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2015c530ef79f9778a37e2dfef5e79f8338f098
4
+ data.tar.gz: 4362355f72ce7e346692c5834d0faf581b6da9ae
5
+ SHA512:
6
+ metadata.gz: e684e668ba7ff0099a9b4e3a93860734de3ff3080ce962a04273308129b88f5d3e7351591057ae3cf059056bb4335592c0294df17019ac95a99b7d264ba817f7
7
+ data.tar.gz: e21e67c23ba7b7aa708bbccbec15748153d0c2c2df59ad4a7c0d3b831410b940f4fb758c364212f7bd007873937280e10d9c499aebb736e4a6e8a5e58eeff90a
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in worldcup.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Henry Poydar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # World Cup 2014
2
+
3
+ Provides command line access to World Cup 2014 information and results.
4
+ Uses Soccer for Good API http://worldcup.sfg.io/. Inspired by https://github.com/fatiherikli/worldcup (Python) and John Oliver. Gives you slightly more information than googling "world cup".
5
+
6
+ ## Installation
7
+
8
+ $ gem install worldcup-2014
9
+
10
+ ## Usage
11
+
12
+ $ worldcup [options]
13
+ -c, --today Display today's matches and current results (default)
14
+ -y, --yesterday Display yesterday's results
15
+ -t, --tomorrow Display information for tomorrow's matches
16
+ -h, --help Display this screen
17
+
18
+ ## Results
19
+
20
+ ![](screenshot.png)
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it ( https://github.com/hpoydar/worldcup/fork )
25
+ 2. Create your feature branch with a spec (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'optparse'
7
+ require 'world_cup'
8
+
9
+ options = {}
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: worldcup [options]"
12
+
13
+ options[:day_delta] = 0
14
+
15
+ opts.on( '-c', '--today', "Display today's matches and current results (default)" ) do
16
+ options[:day_delta] = 0
17
+ end
18
+
19
+ opts.on( '-y', '--yesterday', "Display yesterday's results" ) do
20
+ options[:day_delta] = -1
21
+ end
22
+
23
+ opts.on( '-t', '--tomorrow', "Display information for tomorrow's matches" ) do
24
+ options[:day_delta] = 1
25
+ end
26
+
27
+ opts.on( '-a', '--all', "Display information for all matches" ) do
28
+ options[:day_delta] = nil
29
+ end
30
+
31
+ opts.on( '-h', '--help', 'Display this screen' ) do
32
+ puts opts
33
+ exit
34
+ end
35
+
36
+ end.parse!
37
+
38
+ world_cup_results = WorldCup::Results.new(options)
39
+ world_cup_results.render
@@ -0,0 +1,2 @@
1
+ require "world_cup/results"
2
+ require "world_cup/version"
@@ -0,0 +1,110 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+ require 'terminal-table'
4
+ require 'colorize'
5
+
6
+ module WorldCup
7
+
8
+ class Results
9
+
10
+ SFG_ENDPOINT = 'http://worldcup.sfg.io/matches'
11
+
12
+ attr_reader :raw_response, :response, :table
13
+
14
+ def initialize(opts={})
15
+ @opts = opts
16
+ @raw_response = nil
17
+ @response = nil
18
+ @rows = nil
19
+ @table = nil
20
+ end
21
+
22
+ def render
23
+ unless retrieve
24
+ puts "Sorry, #{SFG_ENDPOINT} could not be reached. Please check your internet connection and try again."
25
+ return
26
+ end
27
+ unless convert
28
+ puts "Sorry, the response at #{SFG_ENDPOINT} could not be interpreted. Please try again."
29
+ return
30
+ end
31
+ select_matches
32
+ compose_table
33
+ puts @table
34
+ end
35
+
36
+ protected
37
+
38
+ def retrieve
39
+ @raw_response = open(SFG_ENDPOINT).read
40
+ true
41
+ rescue StandardError
42
+ false
43
+ end
44
+
45
+ def convert
46
+ @response = JSON.parse(@raw_response)
47
+ @rows = @response
48
+ true
49
+ rescue JSON::JSONError
50
+ false
51
+ end
52
+
53
+ def parse_match_status(status)
54
+ case status
55
+ when 'future'; 'Upcoming'
56
+ when 'completed'; 'Final'
57
+ when 'in progress'; 'Live'
58
+ else; status
59
+ end
60
+ end
61
+
62
+ def format_row(row)
63
+ case row[6].downcase
64
+ when 'live'
65
+ row.map { |rr| rr.to_s.colorize(:white).bold }
66
+ when 'final'
67
+ if row[3] > row[4]
68
+ row.map.with_index { |rr, i|
69
+ i == 2 || i == 3 ? rr.to_s.colorize(:green) : rr }
70
+ elsif row[4] > row[3]
71
+ row.map.with_index { |rr, i|
72
+ i == 4 || i == 5 ? rr.to_s.colorize(:green) : rr }
73
+ else
74
+ row
75
+ end
76
+ else
77
+ row.map { |rr| rr.to_s }
78
+ end
79
+ end
80
+
81
+ def select_matches
82
+
83
+ return if @opts[:day_delta].nil?
84
+ @rows.keep_if { |r| Date.parse(r['datetime']) == Date.today + @opts[:day_delta].to_i }
85
+ end
86
+
87
+ def compose_table
88
+ rows = @rows.sort_by {|r| r['datetime'].to_s }.map do |r|
89
+ [
90
+ r['match_number'],
91
+ DateTime.parse(r['datetime']).strftime('%a %b %-d %H:%M'),
92
+ (r['away_team'].is_a?(Array) ? 'TBD' : r['away_team']['country']),
93
+ (r['away_team'].is_a?(Array) ? '' : r['away_team']['goals']),
94
+ (r['home_team'].is_a?(Array) ? '' : r['home_team']['goals']),
95
+ (r['home_team'].is_a?(Array) ? 'TBD' : r['home_team']['country']),
96
+ parse_match_status(r['status']),
97
+ r['location']
98
+ ]
99
+ end
100
+ rows = rows.map { |r| format_row(r) }
101
+ @table = Terminal::Table.new(
102
+ headings: ['Match', 'Date', 'Away', '', '', 'Home', 'Status', 'Location'],
103
+ rows: rows)
104
+ @table.align_column(2, :right)
105
+ end
106
+
107
+ end
108
+
109
+
110
+ end
@@ -0,0 +1,3 @@
1
+ module WorldCup
2
+ VERSION = "0.1.0"
3
+ end
Binary file
@@ -0,0 +1 @@
1
+ [{"match_number":1,"location":"Arena Corinthians","datetime":"2014-06-12T16:00:00.000-05:00","status":"completed","home_team":{"country":"Brazil","code":"BRA","goals":3},"away_team":{"country":"Croatia","code":"CRO","goals":1},"winner":"Brazil"},{"match_number":2,"location":"Estadio das Dunas","datetime":"2014-06-13T12:00:00.000-05:00","status":"completed","home_team":{"country":"Mexico","code":"MEX","goals":1},"away_team":{"country":"Cameroon","code":"CMR","goals":0},"winner":"Mexico"},{"match_number":3,"location":"Arena Fonte Nova","datetime":"2014-06-13T15:00:00.000-05:00","status":"completed","home_team":{"country":"Spain","code":"ESP","goals":1},"away_team":{"country":"Netherlands","code":"NED","goals":5},"winner":"Netherlands"},{"match_number":4,"location":"Arena Pantanal","datetime":"2014-06-13T17:00:00.000-05:00","status":"completed","home_team":{"country":"Chile","code":"CHI","goals":3},"away_team":{"country":"Australia","code":"AUS","goals":1},"winner":"Chile"},{"match_number":5,"location":"Estadio Mineirao","datetime":"2014-06-14T12:00:00.000-05:00","status":"completed","home_team":{"country":"Colombia","code":"COL","goals":3},"away_team":{"country":"Greece","code":"GRE","goals":0},"winner":"Colombia"},{"match_number":6,"location":"Arena Pernambuco","datetime":"2014-06-14T21:00:00.000-05:00","status":"completed","home_team":{"country":"Ivory Coast","code":"CIV","goals":2},"away_team":{"country":"Japan","code":"JPN","goals":1},"winner":"Ivory Coast"},{"match_number":7,"location":"Estadio Castelao","datetime":"2014-06-14T15:00:00.000-05:00","status":"completed","home_team":{"country":"Uruguay","code":"URU","goals":1},"away_team":{"country":"Costa Rica","code":"CRC","goals":3},"winner":"Costa Rica"},{"match_number":8,"location":"Arena Amazonia","datetime":"2014-06-14T17:00:00.000-05:00","status":"completed","home_team":{"country":"England","code":"ENG","goals":1},"away_team":{"country":"Italy","code":"ITA","goals":2},"winner":"Italy"},{"match_number":9,"location":"Estadio Nacional","datetime":"2014-06-15T12:00:00.000-05:00","status":"completed","home_team":{"country":"Switzerland","code":"SUI","goals":2},"away_team":{"country":"Ecuador","code":"ECU","goals":1},"winner":"Switzerland"},{"match_number":10,"location":"Estadio Beira-Rio","datetime":"2014-06-15T15:00:00.000-05:00","status":"completed","home_team":{"country":"France","code":"FRA","goals":3},"away_team":{"country":"Honduras","code":"HON","goals":0},"winner":"France"},{"match_number":11,"location":"Maracanã - Estádio Jornalista Mário Filho","datetime":"2014-06-15T18:00:00.000-05:00","status":"completed","home_team":{"country":"Argentina","code":"ARG","goals":2},"away_team":{"country":"Bosnia and Herzegovina","code":"BIH","goals":1},"winner":"Argentina"},{"match_number":12,"location":"Arena da Baixada","datetime":"2014-06-16T15:00:00.000-05:00","status":"completed","home_team":{"country":"Iran","code":"IRN","goals":0},"away_team":{"country":"Nigeria","code":"NGA","goals":0},"winner":"Draw"},{"match_number":13,"location":"Arena Fonte Nova","datetime":"2014-06-16T12:00:00.000-05:00","status":"completed","home_team":{"country":"Germany","code":"GER","goals":4},"away_team":{"country":"Portugal","code":"POR","goals":0},"winner":"Germany"},{"match_number":14,"location":"Estadio das Dunas","datetime":"2014-06-16T18:00:00.000-05:00","status":"completed","home_team":{"country":"Ghana","code":"GHA","goals":1},"away_team":{"country":"USA","code":"USA","goals":2},"winner":"USA"},{"match_number":15,"location":"Estadio Mineirao","datetime":"2014-06-17T12:00:00.000-05:00","status":"completed","home_team":{"country":"Belgium","code":"BEL","goals":2},"away_team":{"country":"Algeria","code":"ALG","goals":1},"winner":"Belgium"},{"match_number":16,"location":"Arena Pantanal","datetime":"2014-06-17T17:00:00.000-05:00","status":"completed","home_team":{"country":"Russia","code":"RUS","goals":1},"away_team":{"country":"Korea Republic","code":"KOR","goals":1},"winner":"Draw"},{"match_number":17,"location":"Estadio Castelao","datetime":"2014-06-17T15:00:00.000-05:00","status":"completed","home_team":{"country":"Brazil","code":"BRA","goals":0},"away_team":{"country":"Mexico","code":"MEX","goals":0},"winner":"Draw"},{"match_number":18,"location":"Arena Amazonia","datetime":"2014-06-18T17:00:00.000-05:00","status":"future","home_team":{"country":"Cameroon","code":"CMR","goals":0},"away_team":{"country":"Croatia","code":"CRO","goals":0},"winner":null},{"match_number":19,"location":"Maracanã - Estádio Jornalista Mário Filho","datetime":"2014-06-18T15:00:00.000-05:00","status":"future","home_team":{"country":"Spain","code":"ESP","goals":0},"away_team":{"country":"Chile","code":"CHI","goals":0},"winner":null},{"match_number":20,"location":"Estadio Beira-Rio","datetime":"2014-06-18T12:00:00.000-05:00","status":"in progress","home_team":{"country":"Australia","code":"AUS","goals":1},"away_team":{"country":"Netherlands","code":"NED","goals":1},"winner":null},{"match_number":21,"location":"Estadio Nacional","datetime":"2014-06-19T12:00:00.000-05:00","status":"future","home_team":{"country":"Colombia","code":"COL","goals":0},"away_team":{"country":"Ivory Coast","code":"CIV","goals":0},"winner":null},{"match_number":22,"location":"Estadio das Dunas","datetime":"2014-06-19T18:00:00.000-05:00","status":"future","home_team":{"country":"Japan","code":"JPN","goals":0},"away_team":{"country":"Greece","code":"GRE","goals":0},"winner":null},{"match_number":23,"location":"Arena Corinthians","datetime":"2014-06-19T15:00:00.000-05:00","status":"future","home_team":{"country":"Uruguay","code":"URU","goals":0},"away_team":{"country":"England","code":"ENG","goals":0},"winner":null},{"match_number":24,"location":"Arena Pernambuco","datetime":"2014-06-20T12:00:00.000-05:00","status":"future","home_team":{"country":"Italy","code":"ITA","goals":0},"away_team":{"country":"Costa Rica","code":"CRC","goals":0},"winner":null},{"match_number":25,"location":"Arena Fonte Nova","datetime":"2014-06-20T15:00:00.000-05:00","status":"future","home_team":{"country":"Switzerland","code":"SUI","goals":0},"away_team":{"country":"France","code":"FRA","goals":0},"winner":null},{"match_number":26,"location":"Arena da Baixada","datetime":"2014-06-20T18:00:00.000-05:00","status":"future","home_team":{"country":"Honduras","code":"HON","goals":0},"away_team":{"country":"Ecuador","code":"ECU","goals":0},"winner":null},{"match_number":27,"location":"Estadio Mineirao","datetime":"2014-06-21T12:00:00.000-05:00","status":"future","home_team":{"country":"Argentina","code":"ARG","goals":0},"away_team":{"country":"Iran","code":"IRN","goals":0},"winner":null},{"match_number":28,"location":"Arena Pantanal","datetime":"2014-06-21T17:00:00.000-05:00","status":"future","home_team":{"country":"Nigeria","code":"NGA","goals":0},"away_team":{"country":"Bosnia and Herzegovina","code":"BIH","goals":0},"winner":null},{"match_number":29,"location":"Estadio Castelao","datetime":"2014-06-21T15:00:00.000-05:00","status":"future","home_team":{"country":"Germany","code":"GER","goals":0},"away_team":{"country":"Ghana","code":"GHA","goals":0},"winner":null},{"match_number":30,"location":"Arena Amazonia","datetime":"2014-06-22T17:00:00.000-05:00","status":"future","home_team":{"country":"USA","code":"USA","goals":0},"away_team":{"country":"Portugal","code":"POR","goals":0},"winner":null},{"match_number":31,"location":"Maracanã - Estádio Jornalista Mário Filho","datetime":"2014-06-22T12:00:00.000-05:00","status":"future","home_team":{"country":"Belgium","code":"BEL","goals":0},"away_team":{"country":"Russia","code":"RUS","goals":0},"winner":null},{"match_number":32,"location":"Estadio Beira-Rio","datetime":"2014-06-22T15:00:00.000-05:00","status":"future","home_team":{"country":"Korea Republic","code":"KOR","goals":0},"away_team":{"country":"Algeria","code":"ALG","goals":0},"winner":null},{"match_number":33,"location":"Estadio Nacional","datetime":"2014-06-23T16:00:00.000-05:00","status":"future","home_team":{"country":"Cameroon","code":"CMR","goals":0},"away_team":{"country":"Brazil","code":"BRA","goals":0},"winner":null},{"match_number":34,"location":"Arena Pernambuco","datetime":"2014-06-23T16:00:00.000-05:00","status":"future","home_team":{"country":"Croatia","code":"CRO","goals":0},"away_team":{"country":"Mexico","code":"MEX","goals":0},"winner":null},{"match_number":35,"location":"Arena da Baixada","datetime":"2014-06-23T12:00:00.000-05:00","status":"future","home_team":{"country":"Australia","code":"AUS","goals":0},"away_team":{"country":"Spain","code":"ESP","goals":0},"winner":null},{"match_number":36,"location":"Arena Corinthians","datetime":"2014-06-23T12:00:00.000-05:00","status":"future","home_team":{"country":"Netherlands","code":"NED","goals":0},"away_team":{"country":"Chile","code":"CHI","goals":0},"winner":null},{"match_number":37,"location":"Arena Pantanal","datetime":"2014-06-24T15:00:00.000-05:00","status":"future","home_team":{"country":"Japan","code":"JPN","goals":0},"away_team":{"country":"Colombia","code":"COL","goals":0},"winner":null},{"match_number":38,"location":"Estadio Castelao","datetime":"2014-06-24T16:00:00.000-05:00","status":"future","home_team":{"country":"Greece","code":"GRE","goals":0},"away_team":{"country":"Ivory Coast","code":"CIV","goals":0},"winner":null},{"match_number":39,"location":"Estadio das Dunas","datetime":"2014-06-24T12:00:00.000-05:00","status":"future","home_team":{"country":"Italy","code":"ITA","goals":0},"away_team":{"country":"Uruguay","code":"URU","goals":0},"winner":null},{"match_number":40,"location":"Estadio Mineirao","datetime":"2014-06-24T12:00:00.000-05:00","status":"future","home_team":{"country":"Costa Rica","code":"CRC","goals":0},"away_team":{"country":"England","code":"ENG","goals":0},"winner":null},{"match_number":41,"location":"Arena Amazonia","datetime":"2014-06-25T15:00:00.000-05:00","status":"future","home_team":{"country":"Honduras","code":"HON","goals":0},"away_team":{"country":"Switzerland","code":"SUI","goals":0},"winner":null},{"match_number":42,"location":"Maracanã - Estádio Jornalista Mário Filho","datetime":"2014-06-25T16:00:00.000-05:00","status":"future","home_team":{"country":"Ecuador","code":"ECU","goals":0},"away_team":{"country":"France","code":"FRA","goals":0},"winner":null},{"match_number":43,"location":"Estadio Beira-Rio","datetime":"2014-06-25T12:00:00.000-05:00","status":"future","home_team":{"country":"Nigeria","code":"NGA","goals":0},"away_team":{"country":"Argentina","code":"ARG","goals":0},"winner":null},{"match_number":44,"location":"Arena Fonte Nova","datetime":"2014-06-25T12:00:00.000-05:00","status":"future","home_team":{"country":"Bosnia and Herzegovina","code":"BIH","goals":0},"away_team":{"country":"Iran","code":"IRN","goals":0},"winner":null},{"match_number":45,"location":"Arena Pernambuco","datetime":"2014-06-26T12:00:00.000-05:00","status":"future","home_team":{"country":"USA","code":"USA","goals":0},"away_team":{"country":"Germany","code":"GER","goals":0},"winner":null},{"match_number":46,"location":"Estadio Nacional","datetime":"2014-06-26T12:00:00.000-05:00","status":"future","home_team":{"country":"Portugal","code":"POR","goals":0},"away_team":{"country":"Ghana","code":"GHA","goals":0},"winner":null},{"match_number":47,"location":"Arena Corinthians","datetime":"2014-06-26T16:00:00.000-05:00","status":"future","home_team":{"country":"Korea Republic","code":"KOR","goals":0},"away_team":{"country":"Belgium","code":"BEL","goals":0},"winner":null},{"match_number":48,"location":"Arena da Baixada","datetime":"2014-06-26T16:00:00.000-05:00","status":"future","home_team":{"country":"Algeria","code":"ALG","goals":0},"away_team":{"country":"Russia","code":"RUS","goals":0},"winner":null},{"match_number":49,"location":"Estadio Mineirao","datetime":"2014-06-28T12:00:00.000-05:00","status":"future","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":50,"location":"Maracanã - Estádio Jornalista Mário Filho","datetime":"2014-06-28T16:00:00.000-05:00","status":"future","home_team_tbd":"[1C]","away_team_tbd":"[2D]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":51,"location":"Estadio Castelao","datetime":"2014-06-29T12:00:00.000-05:00","status":"future","home_team_tbd":"[1B]","away_team_tbd":"[2A]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":52,"location":"Arena Pernambuco","datetime":"2014-06-29T16:00:00.000-05:00","status":"future","home_team_tbd":"[1D]","away_team_tbd":"[2C]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":53,"location":"Estadio Nacional","datetime":"2014-06-30T12:00:00.000-05:00","status":"future","home_team_tbd":"[1E]","away_team_tbd":"[2F]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":54,"location":"Estadio Beira-Rio","datetime":"2014-06-30T16:00:00.000-05:00","status":"future","home_team_tbd":"[1G]","away_team_tbd":"[2H]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":55,"location":"Arena Corinthians","datetime":"2014-07-01T12:00:00.000-05:00","status":"future","home_team_tbd":"[1F]","away_team_tbd":"[2E]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":56,"location":"Arena Fonte Nova","datetime":"2014-07-01T16:00:00.000-05:00","status":"future","home_team_tbd":"[1H]","away_team_tbd":"[2G]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":57,"location":"Estadio Castelao","datetime":"2014-07-04T16:00:00.000-05:00","status":"future","home_team_tbd":"[W49]","away_team_tbd":"[W50]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":58,"location":"Maracanã - Estádio Jornalista Mário Filho","datetime":"2014-07-04T12:00:00.000-05:00","status":"future","home_team_tbd":"[W53]","away_team_tbd":"[W54]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":59,"location":"Arena Fonte Nova","datetime":"2014-07-05T16:00:00.000-05:00","status":"future","home_team_tbd":"[W51]","away_team_tbd":"[W52]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":60,"location":"Estadio Nacional","datetime":"2014-07-05T12:00:00.000-05:00","status":"future","home_team_tbd":"[W55]","away_team_tbd":"[W56]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":61,"location":"Estadio Mineirao","datetime":"2014-07-08T16:00:00.000-05:00","status":"future","home_team_tbd":"[W57]","away_team_tbd":"[W58]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":62,"location":"Arena Corinthians","datetime":"2014-07-09T16:00:00.000-05:00","status":"future","home_team_tbd":"[W59]","away_team_tbd":"[W60]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":63,"location":"Estadio Nacional","datetime":"2014-07-12T16:00:00.000-05:00","status":"future","home_team_tbd":"[L61]","away_team_tbd":"[L62]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null},{"match_number":64,"location":"Maracanã - Estádio Jornalista Mário Filho","datetime":"2014-07-13T15:00:00.000-05:00","status":"future","home_team_tbd":"[W61]","away_team_tbd":"[W62]","home_team":["home_team_tbd"],"away_team":["away_team_tbd"],"winner":null}]
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'world_cup'
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorldCup::Results do
4
+
5
+ let(:wcr) { WorldCup::Results.new({}) }
6
+ let(:api_response) {
7
+ File.open(File.expand_path(File.dirname(__FILE__)) + '/../fixtures/sfg-api-20140618.json', "rb").read }
8
+
9
+ describe "#render" do
10
+
11
+ context "today's matches in progress (default)" do
12
+ it "shows only today's matches"
13
+ end
14
+
15
+ context "yesterday's results selected" do
16
+ it "shows only yesterday's results"
17
+ end
18
+
19
+ context "tomorrow's matches selected" do
20
+ it "shows only tomorrow's results"
21
+ end
22
+
23
+ context "all matches selected" do
24
+ it "shows all matches with results for the ones played"
25
+ end
26
+
27
+ context "problems" do
28
+
29
+ it "displays an error message if the API can't be reached" do
30
+ wcr.should_receive(:puts).with(/^Sorry/)
31
+ wcr.should_receive(:open).and_raise(StandardError)
32
+ wcr.render
33
+ end
34
+
35
+ it "displays an error message if the API can't be reached" do
36
+ wcr.should_receive(:puts).with(/^Sorry/)
37
+ JSON.should_receive(:parse).and_raise(JSON::JSONError)
38
+ wcr.stub_chain(:open, :read) { api_response }
39
+ wcr.render
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe "#convert" do
47
+
48
+ it "converts the raw JSON response to an array of hashes" do
49
+ wcr.stub_chain(:open, :read) { api_response }
50
+ wcr.send(:retrieve)
51
+ wcr.send(:convert)
52
+ wcr.response.is_a?(Array).should eq true
53
+ end
54
+ end
55
+
56
+ describe "#retrieve" do
57
+
58
+ it "retrieves a JSON response from the SFG API" do
59
+ wcr.stub_chain(:open, :read) { api_response }
60
+ wcr.send(:retrieve)
61
+ wcr.raw_response.should =~ /^\[\{\"match_number\":1,\"location\":\"Arena Corinthians\"/
62
+ end
63
+
64
+ it "returns true" do
65
+ wcr.stub_chain(:open, :read) { api_response }
66
+ wcr.send(:retrieve).should eq true
67
+ end
68
+
69
+ context "with connectivity problems" do
70
+
71
+ it "returns false" do
72
+ wcr.should_receive(:open).and_raise(StandardError)
73
+ wcr.stub(:puts)
74
+ wcr.send(:retrieve).should eq false
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'world_cup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "worldcup-2014"
8
+ spec.version = WorldCup::VERSION
9
+ spec.authors = ["Henry Poydar"]
10
+ spec.email = ["hpoydar@gmail.com"]
11
+ spec.summary = %q{Provides command line access to World Cup 2014 information and results.}
12
+ spec.homepage = "https://github.com/hpoydar/worldcup-2014"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "terminal-table", "~> 1.4.5"
21
+ spec.add_runtime_dependency 'colorize', '~> 0.7.3'
22
+ spec.add_development_dependency "rspec", "~> 2.14.1"
23
+ spec.add_development_dependency 'timecop', '~> 0.7.1'
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: worldcup-2014
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Henry Poydar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: terminal-table
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - hpoydar@gmail.com
100
+ executables:
101
+ - worldcup
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/worldcup
111
+ - lib/world_cup.rb
112
+ - lib/world_cup/results.rb
113
+ - lib/world_cup/version.rb
114
+ - screenshot.png
115
+ - spec/fixtures/sfg-api-20140618.json
116
+ - spec/spec_helper.rb
117
+ - spec/world_cup/results_spec.rb
118
+ - worldcup-2014.gemspec
119
+ homepage: https://github.com/hpoydar/worldcup-2014
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.0
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Provides command line access to World Cup 2014 information and results.
143
+ test_files:
144
+ - spec/fixtures/sfg-api-20140618.json
145
+ - spec/spec_helper.rb
146
+ - spec/world_cup/results_spec.rb