football__data 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94036f5602a15ffb7b5ae10b32bc5f6b390add34
4
- data.tar.gz: 8a51e8c4bb2e6d91437f4ab86bf2855adb641bad
3
+ metadata.gz: afcb1a285e5e1e201d1e4d35231b700f176819e4
4
+ data.tar.gz: 15f1ccf391b7f955e8c8da3045e050adbbd706c1
5
5
  SHA512:
6
- metadata.gz: bcdc718f9dc805a70676b9d4a7dec903c7f970b92ae978462e3ef3717c69e2ff49cc2f426e3ee4b40f3f61b87510cf9a433829f18d141607892ff8fe784974b4
7
- data.tar.gz: 08ded28d32bccfc8e6027e91dd17f015125dbde9965dfba16f12e14aa32775b81bf2c12585aab0b56d72c7dd0480f8e1e8735a0cdfbb585b0f0cf27164c10fbc
6
+ metadata.gz: 850f052d12717ea2f5026b1a64038ad785041fdf896b4ad416ba8c46e8910cb670538cf5e385fc9f24f51a37764f59b5ef3469d1894bf3136df3778c9c88436a
7
+ data.tar.gz: 65936faa07598ee49306dd23e8cb52e75461c85bdbd810d5afed44ad88c1a9b18a8dc567850b900269f3c19a1ac380686bfee4226f2c36fa8aba90fc15617e80
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.3
4
- before_install: gem install bundler -v 1.10.6
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,13 +1,13 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in football__data.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in football__data.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,110 +1,110 @@
1
- # FootballData
2
-
3
- A ruby wrapper of [football-data.org](http://api.football-data.org/index),
4
- it also has an executable to get football info from terminal.
5
-
6
- ## Installation
7
-
8
- Add this line to your application's Gemfile:
9
-
10
- ```ruby
11
- gem 'football__data'
12
- ```
13
-
14
- And then execute:
15
-
16
- $ bundle
17
-
18
- Or install it yourself as:
19
-
20
- $ gem install football__data
21
-
22
- ## Usage
23
-
24
- ### Executable
25
-
26
- You can use `football` from the terminal to get some football info.
27
-
28
- ```
29
- $ football help # get the help info
30
-
31
- # examples
32
- $ football config # config api key, fav team, fav league, etc
33
- $ football table --league=398
34
- Premier League 2015/16 matchday 15
35
- ---------------------------------------------------------------------------
36
- R Team P W D L GF GA GD Pts
37
- ---------------------------------------------------------------------------
38
- 1 Leicester City FC 15 9 5 1 32 21 11 32
39
- 2 Arsenal FC 15 9 3 3 27 13 14 30
40
- 3 Manchester City FC 15 9 2 4 30 16 14 29
41
- ......
42
-
43
- # you could also add -i to interactive mode, you can see the league id there
44
- # such as:
45
- $ football fixture -i
46
- BL1 1. Bundesliga 394
47
- BL2 2. Bundesliga 395
48
- FL1 Ligue 1 396
49
- ......
50
- Enter the league id of the team: 394
51
- FCB FC Bayern München 5
52
- HSV Hamburger SV 7
53
- ......
54
- Enter the team id: 5
55
- 2015-12-10 03:45 GNK Dinamo Zagreb : FC Bayern München (TBD)
56
- 2015-12-12 22:30 FC Bayern München : FC Ingolstadt 04 (TBD)
57
-
58
- # setting fav_league and fav_team would make it much simple
59
- # use football help SUBCOMMAND to see details
60
- ```
61
-
62
- ### API
63
-
64
- First you need to configure the api
65
-
66
- ```ruby
67
- FootballData.configure do |config|
68
- # get api key at 'http://api.football-data.org/register'
69
- config.api_key = YOUR_API_KEY
70
-
71
- # default api version is 'alpha' if not setted
72
- config.api_version = 'alpha'
73
-
74
- # the default control method is 'full' if not setted
75
- # see request section on 'http://api.football-data.org/documentation'
76
- config.response_control = 'minified'
77
- end
78
- ```
79
-
80
- Use `FootballData.fetch(resource, subresource, params)` to fetch the data.
81
- It returns a json parsed object. Such as:
82
-
83
- ```ruby
84
- # GET 'http://api.football-data.org/v1/soccerseasons'
85
- FootballData.fetch(:soccerseasons)
86
-
87
- # GET 'http://api.football-data.org/v1/soccerseasons/398/leagueTable'
88
- FootballData.fetch(:soccerseasons, :leagueTable, id: 398)
89
-
90
- # GET 'http://api.football-data.org/v1/soccerseasons/398/fixtures?matchday=8'
91
- FootballData.fetch(:soccerseasons, :fixtures, id: 398, matchday: 8)
92
-
93
- res = FootballData.fetch(:teams, :players, id: 57)
94
- pp res['players'].find{|player| player['name'] =~ /Mesut/i}
95
- # {"id"=>1967,
96
- # "name"=>"Mesut Özil",
97
- # "position"=>"Attacking Midfield",
98
- # "jerseyNumber"=>11,
99
- # "dateOfBirth"=>"1988-10-15",
100
- # "nationality"=>"Germany",
101
- # "contractUntil"=>"2018-06-30",
102
- # "marketValue"=>"40,000,000 €"}
103
- ```
104
-
105
- See api structure on page 'http://api.football-data.org/documentation'
106
-
107
-
108
- ## Contributing
109
-
110
- Feel free to file an issue of make a pr.
1
+ # FootballData
2
+
3
+ A ruby wrapper of [football-data.org](http://api.football-data.org/index),
4
+ it also has an executable to get football info from terminal.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'football__data'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install football__data
21
+
22
+ ## Usage
23
+
24
+ ### Executable
25
+
26
+ You can use `football` from the terminal to get some football info.
27
+
28
+ ```
29
+ $ football help # get the help info
30
+
31
+ # examples
32
+ $ football config # config api key, fav team, fav league, etc
33
+ $ football table --league=398
34
+ Premier League 2015/16 matchday 15
35
+ ---------------------------------------------------------------------------
36
+ R Team P W D L GF GA GD Pts
37
+ ---------------------------------------------------------------------------
38
+ 1 Leicester City FC 15 9 5 1 32 21 11 32
39
+ 2 Arsenal FC 15 9 3 3 27 13 14 30
40
+ 3 Manchester City FC 15 9 2 4 30 16 14 29
41
+ ......
42
+
43
+ # you could also add -i to interactive mode, you can see the league id there
44
+ # such as:
45
+ $ football fixture -i
46
+ BL1 1. Bundesliga 394
47
+ BL2 2. Bundesliga 395
48
+ FL1 Ligue 1 396
49
+ ......
50
+ Enter the league id of the team: 394
51
+ FCB FC Bayern München 5
52
+ HSV Hamburger SV 7
53
+ ......
54
+ Enter the team id: 5
55
+ 2015-12-10 03:45 GNK Dinamo Zagreb : FC Bayern München (TBD)
56
+ 2015-12-12 22:30 FC Bayern München : FC Ingolstadt 04 (TBD)
57
+
58
+ # setting fav_league and fav_team would make it much simple
59
+ # use football help SUBCOMMAND to see details
60
+ ```
61
+
62
+ ### API
63
+
64
+ First you need to configure the api
65
+
66
+ ```ruby
67
+ FootballData.configure do |config|
68
+ # get api key at 'http://api.football-data.org/register'
69
+ config.api_key = YOUR_API_KEY
70
+
71
+ # default api version is 'alpha' if not setted
72
+ config.api_version = 'alpha'
73
+
74
+ # the default control method is 'full' if not setted
75
+ # see request section on 'http://api.football-data.org/documentation'
76
+ config.response_control = 'minified'
77
+ end
78
+ ```
79
+
80
+ Use `FootballData.fetch(resource, subresource, params)` to fetch the data.
81
+ It returns a json parsed object. Such as:
82
+
83
+ ```ruby
84
+ # GET 'http://api.football-data.org/v1/soccerseasons'
85
+ FootballData.fetch(:soccerseasons)
86
+
87
+ # GET 'http://api.football-data.org/v1/soccerseasons/398/leagueTable'
88
+ FootballData.fetch(:soccerseasons, :leagueTable, id: 398)
89
+
90
+ # GET 'http://api.football-data.org/v1/soccerseasons/398/fixtures?matchday=8'
91
+ FootballData.fetch(:soccerseasons, :fixtures, id: 398, matchday: 8)
92
+
93
+ res = FootballData.fetch(:teams, :players, id: 57)
94
+ pp res['players'].find{|player| player['name'] =~ /Mesut/i}
95
+ # {"id"=>1967,
96
+ # "name"=>"Mesut Özil",
97
+ # "position"=>"Attacking Midfield",
98
+ # "jerseyNumber"=>11,
99
+ # "dateOfBirth"=>"1988-10-15",
100
+ # "nationality"=>"Germany",
101
+ # "contractUntil"=>"2018-06-30",
102
+ # "marketValue"=>"40,000,000 €"}
103
+ ```
104
+
105
+ See api structure on page 'http://api.football-data.org/documentation'
106
+
107
+
108
+ ## Contributing
109
+
110
+ Feel free to file an issue of make a pr.
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
data/bin/football CHANGED
@@ -1,174 +1,184 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "thor"
4
- require "time"
5
- require "yaml"
6
- require "fileutils"
7
-
8
- require "football__data"
9
-
10
-
11
- # constants
12
- CLI = $PROGRAM_NAME
13
- HOME = ENV["HOME"]
14
- EDITOR = ENV["EDITOR"] || "vim"
15
- CONFIG_FILE = "#{HOME}/.config/football-data/config.yml"
16
- CONFIG_FILE_EXAMPLE = "config/config.yml.example"
17
-
18
-
19
- # check config file
20
- unless File.exist? CONFIG_FILE
21
- puts <<-END.gsub(/^\s*\|/, '')
22
- |It seems you haven't configured it yet.
23
- |#{CLI} will generate generate an example config file.
24
- |Run `#{CLI} config` to config the file.
25
- END
26
-
27
- FileUtils.mkdir_p File.dirname(CONFIG_FILE)
28
- FileUtils.cp CONFIG_FILE_EXAMPLE, CONFIG_FILE
29
-
30
- exit
31
- end
32
-
33
-
34
- # get config info
35
- CONFIG = YAML.load_file CONFIG_FILE
36
-
37
- FootballData.configure do |config|
38
- config.api_key = CONFIG['api_key']
39
- config.api_version = CONFIG['api_version']
40
- end
41
-
42
- FAV_LEAGUE_ID = CONFIG['fav_league_id']
43
- FAV_TEAM_ID = CONFIG['fav_team_id']
44
-
45
-
46
- # cli
47
- class Football < Thor
48
- desc "config [EXAMPLE]", "Custom configuration file or edit it from an example"
49
- option :example, :type => :boolean, :default => false
50
- def config
51
- if options[:example]
52
- FileUtils.rm CONFIG_FILE
53
- FileUtils.cp CONFIG_FILE_EXAMPLE, CONFIG_FILE
54
- end
55
- exec "#{EDITOR} #{CONFIG_FILE}"
56
- end
57
-
58
- desc "list TYPE", "List LEAGUE or TEAM id"
59
- option :league, :type => :numeric
60
- def list(type)
61
- if type == "league"
62
- __list_league
63
- elsif type == "team"
64
- if league_id = options[:league]
65
- __list_team league_id
66
- else
67
- puts "can not get teams id without specifying the league id"
68
- end
69
- else
70
- puts "type should be league or team"
71
- end
72
- end
73
-
74
-
75
- desc "table [LEAGUE]", "Get LEAGUE table"
76
- option :league, :type => :numeric
77
- option :interactive, :type => :boolean, :default => false, :aliases => :i
78
- def table
79
- league_id = if options[:interactive]
80
- __list_league
81
- print "\nEnter league id: "
82
- STDIN.gets.to_i
83
- else
84
- options[:league_id] || FAV_LEAGUE_ID
85
- end
86
- league_table = FootballData.fetch :soccerseasons, :leagueTable, :id => league_id
87
- caption = league_table['leagueCaption']
88
- matchday = league_table['matchday']
89
- standing = league_table['standing']
90
- div_line = "-" * 75
91
- w = 5
92
-
93
- puts "#{caption}\tmatchday #{matchday}"
94
- puts div_line
95
- puts "R".ljust(w) + "Team".ljust(30) + %w[P W D L GF GA GD Pts].map{|i|i.ljust(w)}.join
96
- puts div_line
97
- standing.each do |team|
98
- row = team['position'].to_s.ljust(w)
99
- row += team['teamName'].ljust(30)
100
- row += team['playedGames'].to_s.ljust(w)
101
- row += team['wins'].to_s.ljust(w)
102
- row += team['draws'].to_s.ljust(w)
103
- row += team['losses'].to_s.ljust(w)
104
- row += team['goals'].to_s.ljust(w)
105
- row += team['goalsAgainst'].to_s.ljust(w)
106
- row += team['goalDifference'].to_s.ljust(w)
107
- row += team['points'].to_s.ljust(w)
108
- puts row
109
- end
110
- end
111
-
112
- desc "fixture [TEAM]", "Get latest fixture of TEAM"
113
- option :team, :type => :numeric
114
- option :time, :type => :string
115
- option :interactive, :type => :boolean, :default => false, :aliases => :i
116
- def fixture
117
- team_id = if options[:interactive]
118
- __list_league
119
- print "\nEnter the league id of the team: "
120
- league_id = STDIN.gets.to_i
121
- __list_team league_id
122
- print "\nEnter the team id: "
123
- STDIN.gets.to_i
124
- else
125
- options[:team] || FAV_TEAM_ID
126
- end
127
- time = options[:time] || "n7"
128
- info = FootballData.fetch :teams, :fixtures, :id => team_id, :timeFrame => time
129
- fixtures = info['fixtures']
130
- if fixtures.empty?
131
- puts "There is no match coming >_<"
132
- else
133
- fixtures.each do |fixture|
134
- date = Time.parse(fixture['date']).localtime
135
- home = fixture['homeTeamName']
136
- away = fixture['awayTeamName']
137
- goal_home = fixture['result']['goalsHomeTeam']
138
- goal_away = fixture['result']['goalsAwayTeam']
139
- gh = goal_home == -1 ? '' : " #{goal_home}"
140
- ga = goal_away == -1 ? '' : " #{goal_away}"
141
- l = "#{home.ljust(20)}#{gh}"
142
- r = "#{ga}#{away}"
143
- match = "#{date.strftime("%Y-%m-%d %H:%M").ljust(20)}\t"
144
- match += "#{l} : #{r.ljust(20)}"
145
- match += "(TBD)" if gh.empty?
146
- puts match
147
- end
148
- end
149
- end
150
-
151
- private
152
-
153
- def __list_league
154
- leagues = FootballData.fetch :soccerseasons
155
- leagues.each do |league|
156
- id = league['_links']['self']['href'].split('/').last
157
- *name, _ = league['caption'].split
158
- code = league['league']
159
- puts "#{code.ljust(15)}#{name.join(' ').ljust(25)}#{id}"
160
- end
161
- end
162
-
163
- def __list_team(league_id)
164
- teams = FootballData.fetch(:soccerseasons, :teams, :id => league_id)['teams']
165
- teams.each do |team|
166
- id = team['_links']['self']['href'].split('/').last
167
- name = team['name']
168
- code = team['code']
169
- puts "#{code.ljust(15)}#{name.ljust(30)}#{id}"
170
- end
171
- end
172
- end
173
-
174
- Football.start
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "time"
5
+ require "yaml"
6
+
7
+ require "football__data"
8
+
9
+
10
+ # constants
11
+ CLI = File.basename $PROGRAM_NAME
12
+ HOME = ENV["HOME"]
13
+ EDITOR = ENV["EDITOR"] || "vim"
14
+ CONFIG_FILE = "#{HOME}/.config/football-data/config.yml"
15
+
16
+ CONFIG_FILE_EXAMPLE =<<-END.gsub(/^\s*\|/, '')
17
+ |# football__data config file example, yaml format
18
+
19
+ |# api info
20
+ |api_key: YOUR_API_KEY # must
21
+ |# api_version: alpha|v1 # optional, default to alpha
22
+
23
+ |# favorite setting
24
+ |# run `football list league` to get league id
25
+ |# run `football list team --league=ID` to get team id in league ID
26
+ |
27
+ |# fav_league_id: YOUR_FAVORITE_LEAGUE_ID # favorite league id
28
+ |# fav_team_id: YOUR_FAVORITE_TEAM_ID # favorite team id
29
+ END
30
+
31
+ # check config file
32
+ unless File.exist? CONFIG_FILE
33
+ puts <<-END.gsub(/^\s*\|/, '')
34
+ |It seems you haven't configured it yet.
35
+ |`#{CLI}` will generate generate an example config file.
36
+ |Run `#{CLI} config` to config the file.
37
+ END
38
+
39
+ File.open(CONFIG_FILE, "w") { |f| f.puts CONFIG_FILE_EXAMPLE }
40
+
41
+ exit
42
+ end
43
+
44
+ # get config info
45
+ CONFIG = YAML.load_file CONFIG_FILE
46
+
47
+ FootballData.configure do |config|
48
+ config.api_key = CONFIG['api_key']
49
+ config.api_version = CONFIG['api_version']
50
+ end
51
+
52
+ FAV_LEAGUE_ID = CONFIG['fav_league_id']
53
+ FAV_TEAM_ID = CONFIG['fav_team_id']
54
+
55
+
56
+ # cli
57
+ class Football < Thor
58
+ desc "config [EXAMPLE]", "Custom configuration file or edit it from an example"
59
+ option :example, :type => :boolean, :default => false
60
+ def config
61
+ if options[:example]
62
+ FileUtils.rm CONFIG_FILE
63
+ FileUtils.cp CONFIG_FILE_EXAMPLE, CONFIG_FILE
64
+ end
65
+ exec "#{EDITOR} #{CONFIG_FILE}"
66
+ end
67
+
68
+ desc "list TYPE", "List LEAGUE or TEAM id"
69
+ option :league, :type => :numeric
70
+ def list(type)
71
+ if type == "league"
72
+ __list_league
73
+ elsif type == "team"
74
+ if league_id = options[:league]
75
+ __list_team league_id
76
+ else
77
+ puts "can not get teams id without specifying the league id"
78
+ end
79
+ else
80
+ puts "type should be league or team"
81
+ end
82
+ end
83
+
84
+
85
+ desc "table [LEAGUE]", "Get LEAGUE table"
86
+ option :league, :type => :numeric
87
+ option :interactive, :type => :boolean, :default => false, :aliases => :i
88
+ def table
89
+ league_id = if options[:interactive]
90
+ __list_league
91
+ print "\nEnter league id: "
92
+ STDIN.gets.to_i
93
+ else
94
+ options[:league_id] || FAV_LEAGUE_ID
95
+ end
96
+ league_table = FootballData.fetch :soccerseasons, :leagueTable, :id => league_id
97
+ caption = league_table['leagueCaption']
98
+ matchday = league_table['matchday']
99
+ standing = league_table['standing']
100
+ div_line = "-" * 75
101
+ w = 5
102
+
103
+ puts "#{caption}\tmatchday #{matchday}"
104
+ puts div_line
105
+ puts "R".ljust(w) + "Team".ljust(30) + %w[P W D L GF GA GD Pts].map{|i|i.ljust(w)}.join
106
+ puts div_line
107
+ standing.each do |team|
108
+ row = team['position'].to_s.ljust(w)
109
+ row += team['teamName'].ljust(30)
110
+ row += team['playedGames'].to_s.ljust(w)
111
+ row += team['wins'].to_s.ljust(w)
112
+ row += team['draws'].to_s.ljust(w)
113
+ row += team['losses'].to_s.ljust(w)
114
+ row += team['goals'].to_s.ljust(w)
115
+ row += team['goalsAgainst'].to_s.ljust(w)
116
+ row += team['goalDifference'].to_s.ljust(w)
117
+ row += team['points'].to_s.ljust(w)
118
+ puts row
119
+ end
120
+ end
121
+
122
+ desc "fixture [TEAM]", "Get latest fixture of TEAM"
123
+ option :team, :type => :numeric
124
+ option :time, :type => :string
125
+ option :interactive, :type => :boolean, :default => false, :aliases => :i
126
+ def fixture
127
+ team_id = if options[:interactive]
128
+ __list_league
129
+ print "\nEnter the league id of the team: "
130
+ league_id = STDIN.gets.to_i
131
+ __list_team league_id
132
+ print "\nEnter the team id: "
133
+ STDIN.gets.to_i
134
+ else
135
+ options[:team] || FAV_TEAM_ID
136
+ end
137
+ time = options[:time] || "n7"
138
+ info = FootballData.fetch :teams, :fixtures, :id => team_id, :timeFrame => time
139
+ fixtures = info['fixtures']
140
+ if fixtures.empty?
141
+ puts "There is no match coming >_<"
142
+ else
143
+ fixtures.each do |fixture|
144
+ date = Time.parse(fixture['date']).localtime
145
+ home = fixture['homeTeamName']
146
+ away = fixture['awayTeamName']
147
+ goal_home = fixture['result']['goalsHomeTeam']
148
+ goal_away = fixture['result']['goalsAwayTeam']
149
+ gh = goal_home == -1 ? '' : " #{goal_home}"
150
+ ga = goal_away == -1 ? '' : " #{goal_away}"
151
+ l = "#{home.ljust(20)}#{gh}"
152
+ r = "#{ga}#{away}"
153
+ match = "#{date.strftime("%Y-%m-%d %H:%M").ljust(20)}\t"
154
+ match += "#{l} : #{r.ljust(20)}"
155
+ match += "(TBD)" if gh.empty?
156
+ puts match
157
+ end
158
+ end
159
+ end
160
+
161
+ private
162
+
163
+ def __list_league
164
+ leagues = FootballData.fetch :soccerseasons
165
+ leagues.each do |league|
166
+ id = league['_links']['self']['href'].split('/').last
167
+ *name, _ = league['caption'].split
168
+ code = league['league']
169
+ puts "#{code.ljust(15)}#{name.join(' ').ljust(25)}#{id}"
170
+ end
171
+ end
172
+
173
+ def __list_team(league_id)
174
+ teams = FootballData.fetch(:soccerseasons, :teams, :id => league_id)['teams']
175
+ teams.each do |team|
176
+ id = team['_links']['self']['href'].split('/').last
177
+ name = team['name']
178
+ code = team['code']
179
+ puts "#{code.ljust(15)}#{name.ljust(30)}#{id}"
180
+ end
181
+ end
182
+ end
183
+
184
+ Football.start
@@ -1,26 +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 'football__data/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "football__data"
8
- spec.version = FootballData::VERSION
9
- spec.authors = ["delta"]
10
- spec.email = ["delta4d@gmail.com"]
11
- spec.license = 'MIT'
12
-
13
- spec.summary = %q{ruby api wrapper of football-data.org}
14
- spec.description = %q{ruby api wrapper of football-data.org}
15
- spec.homepage = "https://github.com/delta4d/football-data"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.executables = ["football"]
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
-
24
- spec.add_dependency "faraday", "~> 0.9"
25
- spec.add_dependency "thor", "~> 0.19"
26
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'football__data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "football__data"
8
+ spec.version = FootballData::VERSION
9
+ spec.authors = ["delta"]
10
+ spec.email = ["delta4d@gmail.com"]
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = %q{api wrapper of football-data.org}
14
+ spec.description = %q{ruby api wrapper of football-data.org and a executable}
15
+ spec.homepage = "https://github.com/delta4d/football-data"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = ["football"]
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "faraday", "~> 0.9"
25
+ spec.add_dependency "thor", "~> 0.19"
26
+ end
@@ -1,48 +1,48 @@
1
- require "football__data/version"
2
- require "football__data/configuration"
3
-
4
- require "json"
5
- require "faraday"
6
-
7
- module FootballData
8
- extend Configuration
9
-
10
- class << self
11
- # main method of FootballData, fetch info of football matches and players
12
- # see 'http://api.football-data.org/documentation' for details
13
- #
14
- # @param resource [Symbol, String] one of :soccerseasons, :teams, :fixtures
15
- # @param subresource [Symbol, String]
16
- # :soccerseasons => one of :fixtures, :teams, :leagueTable
17
- # :teams => one of :fixtures, :players
18
- # @param params [Hash] the filter parameters, :id is also pass by params
19
- def fetch(resource, subresource = nil, params = {})
20
- id, filter = parse_params(params)
21
- path = "/#{@api_version}/#{resource}"
22
- path += "/#{id}/#{subresource}" if id
23
- path += "?#{filter}" if filter
24
- response = get(path)
25
- JSON.parse(response.body)
26
- end
27
-
28
- private
29
-
30
- def parse_params(params)
31
- id = params[:id]
32
- no_id_params = params.dup
33
- no_id_params.delete(:id)
34
- filter = no_id_params.map{ |key, val| "#{key}=#{val}" }.join("&")
35
- [id, filter]
36
- end
37
-
38
- def connection
39
- @connection ||= Faraday.new(url: API_ENDPOINT,
40
- headers: {"X-Auth-Token" => @api_key,
41
- "X-Response-Control" => @response_control})
42
- end
43
-
44
- def get(path)
45
- connection.get(path)
46
- end
47
- end
48
- end
1
+ require "football__data/version"
2
+ require "football__data/configuration"
3
+
4
+ require "json"
5
+ require "faraday"
6
+
7
+ module FootballData
8
+ extend Configuration
9
+
10
+ class << self
11
+ # main method of FootballData, fetch info of football matches and players
12
+ # see 'http://api.football-data.org/documentation' for details
13
+ #
14
+ # @param resource [Symbol, String] one of :soccerseasons, :teams, :fixtures
15
+ # @param subresource [Symbol, String]
16
+ # :soccerseasons => one of :fixtures, :teams, :leagueTable
17
+ # :teams => one of :fixtures, :players
18
+ # @param params [Hash] the filter parameters, :id is also pass by params
19
+ def fetch(resource, subresource = nil, params = {})
20
+ id, filter = parse_params(params)
21
+ path = "/#{@api_version}/#{resource}"
22
+ path += "/#{id}/#{subresource}" if id
23
+ path += "?#{filter}" if filter
24
+ response = get(path)
25
+ JSON.parse(response.body)
26
+ end
27
+
28
+ private
29
+
30
+ def parse_params(params)
31
+ id = params[:id]
32
+ no_id_params = params.dup
33
+ no_id_params.delete(:id)
34
+ filter = no_id_params.map{ |key, val| "#{key}=#{val}" }.join("&")
35
+ [id, filter]
36
+ end
37
+
38
+ def connection
39
+ @connection ||= Faraday.new(url: API_ENDPOINT,
40
+ headers: {"X-Auth-Token" => @api_key,
41
+ "X-Response-Control" => @response_control})
42
+ end
43
+
44
+ def get(path)
45
+ connection.get(path)
46
+ end
47
+ end
48
+ end
@@ -1,24 +1,24 @@
1
- module FootballData
2
- module Configuration
3
- DEFAULT_API_KEY = nil
4
- DEFAULT_API_VERSON = "alpha"
5
- DEFAULT_RESPONSE_CONTROL = "full"
6
-
7
- API_ENDPOINT = "http://api.football-data.org"
8
-
9
- attr_writer :api_version, :api_key, :response_control
10
-
11
- def configure
12
- raise "don't you wanna configure it?" unless block_given?
13
- yield self
14
- @api_version ||= DEFAULT_API_VERSON
15
- @response_control ||= DEFAULT_RESPONSE_CONTROL
16
- end
17
-
18
- def reset!
19
- @api_key = DEFAULT_API_KEY
20
- @api_version = DEFAULT_API_VERSON
21
- @response_control = DEFAULT_RESPONSE_CONTROL
22
- end
23
- end
24
- end
1
+ module FootballData
2
+ module Configuration
3
+ DEFAULT_API_KEY = nil
4
+ DEFAULT_API_VERSON = "alpha"
5
+ DEFAULT_RESPONSE_CONTROL = "full"
6
+
7
+ API_ENDPOINT = "http://api.football-data.org"
8
+
9
+ attr_writer :api_version, :api_key, :response_control
10
+
11
+ def configure
12
+ raise "don't you wanna configure it?" unless block_given?
13
+ yield self
14
+ @api_version ||= DEFAULT_API_VERSON
15
+ @response_control ||= DEFAULT_RESPONSE_CONTROL
16
+ end
17
+
18
+ def reset!
19
+ @api_key = DEFAULT_API_KEY
20
+ @api_version = DEFAULT_API_VERSON
21
+ @response_control = DEFAULT_RESPONSE_CONTROL
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
- module FootballData
2
- VERSION = "0.2.2"
3
- end
1
+ module FootballData
2
+ VERSION = "0.2.3"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: football__data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - delta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-08 00:00:00.000000000 Z
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.19'
69
- description: ruby api wrapper of football-data.org
69
+ description: ruby api wrapper of football-data.org and a executable
70
70
  email:
71
71
  - delta4d@gmail.com
72
72
  executables:
@@ -80,10 +80,7 @@ files:
80
80
  - Gemfile
81
81
  - README.md
82
82
  - Rakefile
83
- - bin/console
84
83
  - bin/football
85
- - bin/setup
86
- - config/config.yml.example
87
84
  - football__data.gemspec
88
85
  - lib/football__data.rb
89
86
  - lib/football__data/configuration.rb
@@ -108,9 +105,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
105
  version: '0'
109
106
  requirements: []
110
107
  rubyforge_project:
111
- rubygems_version: 2.4.5.1
108
+ rubygems_version: 2.5.1
112
109
  signing_key:
113
110
  specification_version: 4
114
- summary: ruby api wrapper of football-data.org
111
+ summary: api wrapper of football-data.org
115
112
  test_files: []
116
- has_rdoc:
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "football__data"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
@@ -1,11 +0,0 @@
1
- # football__data config file example, yaml format
2
-
3
- # api info
4
- api_key: YOUR_API_KEY # must
5
- api_version: alpha|v1 # optional, default to alpha
6
-
7
- # favorite setting
8
- # run `football list league` to get league id
9
- # run `football list team --league=ID` to get team id in league ID
10
- fav_league_id: YOUR_FAVORITE_LEAGUE_ID # favorite league id
11
- fav_team_id: YOUR_FAVORITE_TEAM_ID # favorite team id