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 +4 -4
- data/.gitignore +9 -9
- data/.travis.yml +4 -4
- data/CODE_OF_CONDUCT.md +13 -13
- data/Gemfile +4 -4
- data/README.md +110 -110
- data/Rakefile +1 -1
- data/bin/football +184 -174
- data/football__data.gemspec +26 -26
- data/lib/football__data.rb +48 -48
- data/lib/football__data/configuration.rb +24 -24
- data/lib/football__data/version.rb +3 -3
- metadata +5 -9
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/config/config.yml.example +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afcb1a285e5e1e201d1e4d35231b700f176819e4
|
4
|
+
data.tar.gz: 15f1ccf391b7f955e8c8da3045e050adbbd706c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
CONFIG_FILE_EXAMPLE
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
desc "
|
59
|
-
option :
|
60
|
-
def
|
61
|
-
if
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
def
|
164
|
-
|
165
|
-
|
166
|
-
id
|
167
|
-
name =
|
168
|
-
code
|
169
|
-
puts "#{code.ljust(15)}#{name.ljust(
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
|
-
|
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
|
data/football__data.gemspec
CHANGED
@@ -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{
|
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
|
data/lib/football__data.rb
CHANGED
@@ -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.
|
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.
|
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:
|
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.
|
108
|
+
rubygems_version: 2.5.1
|
112
109
|
signing_key:
|
113
110
|
specification_version: 4
|
114
|
-
summary:
|
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
data/config/config.yml.example
DELETED
@@ -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
|