footballdata 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4342bd0fd7a19bc6c8772cbed047ea3760ad5233
4
+ data.tar.gz: b5f999cc7044e5694d1641ae9467e65bddb77696
5
+ SHA512:
6
+ metadata.gz: c36ccdc8234fe85a01923320dd7085049a36821288d5988412cf559b3a3ef43d60965bf6ad1e248e86b3c7d1496a1004dffd95e6a34fdc2a8539f812bf6eb1f9
7
+ data.tar.gz: 574a527ac87c75dcf154c912cdc0b8dcff417b20f8226f43d684e090d2e881694e4771b23f351d94c0621bef7a968f882efb560acf2ca6adae3c1f9175cc69e0
@@ -0,0 +1,21 @@
1
+ module Footballdata
2
+ class Configuration
3
+ attr_accessor :api_key
4
+
5
+ def initialize
6
+ @api_key = ENV["API_KEY"]
7
+ end
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def self.configuration=(config)
15
+ @configuration = config
16
+ end
17
+
18
+ def self.configure
19
+ yield configuration
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+ require "json"
2
+ require "open-uri"
3
+
4
+ require './lib/models/fixture'
5
+ require './lib/models/team'
6
+ require './lib/models/league'
7
+ require './lib/configuration'
8
+
9
+ BASE_URL = "http://api.football-data.org/v1"
10
+
11
+ def api_key
12
+ Footballdata.configuration.api_key
13
+ end
14
+
15
+ module Footballdata
16
+ def self.leagues(season: current_season)
17
+ open("#{BASE_URL}/soccerseasons?season=#{season}", "X-Auth-Token" => api_key) do |response|
18
+ JSON.parse(response.read).map do |league|
19
+ League.new(
20
+ id: league["id"],
21
+ name: league["caption"]
22
+ )
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.team(id)
28
+ open("#{BASE_URL}/teams/#{id}", "X-Auth-Token" => api_key) do |response|
29
+ team = JSON.parse(response.read)
30
+ id = team["_links"]["fixtures"]["href"].split("/")[-2]
31
+ Team.new(
32
+ id: id,
33
+ name: team["name"]
34
+ )
35
+ end
36
+ end
37
+
38
+ def self.current_season
39
+ Time.now.month >= 7 ? Time.now.year : Time.now.year - 1
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ module Footballdata
2
+ class Fixture
3
+ def initialize(id:, soccerseason_id:, date:, matchday:, home_team_name:, home_team_id:,
4
+ away_team_name:, away_team_id:, goals_home_team:, goals_away_team:)
5
+ @id = id
6
+ @soccerseason_id = soccerseason_id
7
+ @date = date
8
+ @matchday = matchday
9
+ @home_team_name = home_team_name
10
+ @home_team_id = home_team_id
11
+ @away_team_name = away_team_name
12
+ @away_team_id = away_team_id
13
+ @goals_home_team = goals_home_team
14
+ @goals_away_team = goals_away_team
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ module Footballdata
2
+ class League
3
+ attr_reader :id, :name
4
+
5
+ def initialize(id:, name:)
6
+ @id = id
7
+ @name = name
8
+ end
9
+
10
+ def teams
11
+ open("#{BASE_URL}/soccerseasons/#{id}/teams", "X-Auth-Token" => api_key) do |response|
12
+ JSON.parse(response.read)["teams"].map do |team|
13
+ id = team["_links"]["fixtures"]["href"].split("/")[-2]
14
+ Footballdata::Team.new(
15
+ id: id,
16
+ name: team["name"]
17
+ )
18
+ end
19
+ end
20
+ end
21
+
22
+ def fixtures
23
+ open("#{BASE_URL}/soccerseasons/#{id}/fixtures", "X-Auth-Token" => api_key) do |response|
24
+ JSON.parse(response.read)["fixtures"].map do |team|
25
+ Footballdata::Fixture.new(
26
+ id: team["id"],
27
+ soccerseason_id: team["soccerseasonId"],
28
+ date: team["date"],
29
+ matchday: team["matchday"],
30
+ home_team_name: team["homeTeamName"],
31
+ home_team_id: team["homeTeamId"],
32
+ away_team_name: team["awayTeamName"],
33
+ away_team_id: team["awayTeamId"],
34
+ goals_home_team: team["result"]["goalsHomeTeam"],
35
+ goals_away_team: team["result"]["goalsAwayTeam"]
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ module Footballdata
2
+ class Team
3
+ attr_reader :id, :name
4
+
5
+ def initialize(id:, name:)
6
+ @id = id
7
+ @name = name
8
+ end
9
+
10
+ def fixtures
11
+ open("#{BASE_URL}/teams/#{id}/fixtures", "X-Auth-Token" => api_key) do |response|
12
+ JSON.parse(response.read)["fixtures"].map do |team|
13
+ Footballdata::Fixture.new(
14
+ id: team["id"],
15
+ soccerseason_id: team["soccerseasonId"],
16
+ date: team["date"],
17
+ matchday: team["matchday"],
18
+ home_team_name: team["homeTeamName"],
19
+ home_team_id: team["homeTeamId"],
20
+ away_team_name: team["awayTeamName"],
21
+ away_team_id: team["awayTeamId"],
22
+ goals_home_team: team["result"]["goalsHomeTeam"],
23
+ goals_away_team: team["result"]["goalsAwayTeam"]
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: footballdata
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Jansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sanitize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ description: Wrapper for the football-data.org API
42
+ email:
43
+ - joshuajansen88@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/configuration.rb
49
+ - lib/footballdata.rb
50
+ - lib/models/fixture.rb
51
+ - lib/models/league.rb
52
+ - lib/models/team.rb
53
+ homepage: https://github.com/joshuajansen/footballdata
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.4.5.1
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: This gem leverages the football-data.org API to get football data like teams
77
+ and results.
78
+ test_files: []