sportradar-api 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sportradar/api.rb +8 -0
- data/lib/sportradar/api/error.rb +5 -4
- data/lib/sportradar/api/request.rb +6 -1
- data/lib/sportradar/api/soccer.rb +28 -19
- data/lib/sportradar/api/soccer/boxscore.rb +25 -0
- data/lib/sportradar/api/soccer/match.rb +43 -0
- data/lib/sportradar/api/soccer/player.rb +47 -0
- data/lib/sportradar/api/soccer/schedule.rb +14 -0
- data/lib/sportradar/api/soccer/summary.rb +26 -0
- data/lib/sportradar/api/soccer/team.rb +45 -0
- data/lib/sportradar/api/soccer/venue.rb +21 -0
- data/lib/sportradar/api/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a30d13dd287328fb8ed82d4046e537829e9d6c71
|
4
|
+
data.tar.gz: 51e7e42e1d48ffb906680b542768de12431d696b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b678ccdf1ac3fed3e77ca3fa0363be7ed75b23ca6868b13ebb37f391e6dc2bdd1e350176866a197b9f25d18ad4fbffafc8bf9f0641906f4b928b81a6082a9ee7
|
7
|
+
data.tar.gz: 9cbf2b2cbe7019627ff8728f2ff192b19b97037b7b6c8492544a5e50ed87523358ce338f1fa42e1c7650d0fe84380fdbe3813ef3b19cdffebee2de732b71f3f9
|
data/Gemfile.lock
CHANGED
data/lib/sportradar/api.rb
CHANGED
@@ -9,6 +9,14 @@ require "sportradar/api/error"
|
|
9
9
|
require "sportradar/api/request"
|
10
10
|
|
11
11
|
require "sportradar/api/soccer"
|
12
|
+
require "sportradar/api/soccer/boxscore"
|
13
|
+
require "sportradar/api/soccer/match"
|
14
|
+
require "sportradar/api/soccer/player"
|
15
|
+
require "sportradar/api/soccer/schedule"
|
16
|
+
require "sportradar/api/soccer/summary"
|
17
|
+
require "sportradar/api/soccer/team"
|
18
|
+
require "sportradar/api/soccer/venue"
|
19
|
+
|
12
20
|
require "sportradar/api/nfl"
|
13
21
|
require "sportradar/api/images"
|
14
22
|
require "sportradar/api/live_images"
|
data/lib/sportradar/api/error.rb
CHANGED
@@ -12,13 +12,14 @@ module Sportradar
|
|
12
12
|
class Timeout < Timeout::Error ; end
|
13
13
|
class NoData < EOFError; end
|
14
14
|
|
15
|
-
attr_reader :message, :
|
15
|
+
attr_reader :message, :code, :response
|
16
16
|
|
17
|
-
def initialize(
|
18
|
-
@
|
19
|
-
@status = response_status
|
17
|
+
def initialize( code, message, response)
|
18
|
+
@code = response_code
|
20
19
|
@message = response_message
|
20
|
+
@response = response
|
21
21
|
end
|
22
|
+
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -17,11 +17,16 @@ module Sportradar
|
|
17
17
|
def get(path, options={})
|
18
18
|
base_setup(path, options)
|
19
19
|
puts url
|
20
|
-
|
20
|
+
response = self.class.get(url, headers: headers, query: options.merge(api_key), timeout: timeout)
|
21
21
|
rescue Net::ReadTimeout, Net::OpenTimeout
|
22
22
|
raise Sportradar::Api::Error::Timeout
|
23
23
|
rescue EOFError
|
24
24
|
raise Sportradar::Api::Error::NoData
|
25
|
+
if response.success?
|
26
|
+
response
|
27
|
+
else
|
28
|
+
Sportradar::Api::Error.new(response.code, response.message, response)
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
private
|
@@ -2,7 +2,7 @@ module Sportradar
|
|
2
2
|
module Api
|
3
3
|
class Soccer < Request
|
4
4
|
attr_accessor :league, :access_level
|
5
|
-
def initialize(league =
|
5
|
+
def initialize(league = "na", access_level = "t")
|
6
6
|
raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
|
7
7
|
raise Sportradar::Api::Error::InvalidLeague unless allowed_leagues.include? league
|
8
8
|
@league = league
|
@@ -10,53 +10,62 @@ module Sportradar
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def schedule
|
13
|
-
get request_url("matches/schedule")
|
13
|
+
response = get request_url("matches/schedule")
|
14
|
+
Sportradar::Api::Soccer::Schedule.new response
|
14
15
|
end
|
15
16
|
|
16
17
|
def daily_schedule(date = Date.today)
|
17
|
-
get request_url("matches/#{date_path(date)}/schedule")
|
18
|
+
response = get request_url("matches/#{date_path(date)}/schedule")
|
19
|
+
Sportradar::Api::Soccer::Schedule.new response
|
18
20
|
end
|
19
21
|
|
20
22
|
def daily_summary(date = Date.today)
|
21
|
-
get request_url("matches/#{date_path(date)}/summary")
|
23
|
+
response = get request_url("matches/#{date_path(date)}/summary")
|
24
|
+
Sportradar::Api::Soccer::Summary.new response
|
22
25
|
end
|
23
26
|
|
24
27
|
def daily_boxscore(date = Date.today)
|
25
|
-
get request_url("matches/#{date_path(date)}/boxscore")
|
28
|
+
response = get request_url("matches/#{date_path(date)}/boxscore")
|
29
|
+
Sportradar::Api::Soccer::Boxscore.new response
|
26
30
|
end
|
27
31
|
|
28
32
|
# match_id = "357607e9-87cd-4848-b53e-0485d9c1a3bc"
|
29
33
|
def match_summary(match_id)
|
30
|
-
get request_url("matches/#{match_id}/summary")
|
34
|
+
response = get request_url("matches/#{match_id}/summary")
|
35
|
+
Sportradar::Api::Soccer::Summary.new response
|
31
36
|
end
|
32
37
|
|
33
38
|
# match_id = "357607e9-87cd-4848-b53e-0485d9c1a3bc"
|
34
39
|
def match_boxscore(match_id)
|
35
|
-
get request_url("matches/#{match_id}/boxscore")
|
36
|
-
|
37
|
-
|
38
|
-
def team_hierarchy
|
39
|
-
get request_url("teams/hierarchy")
|
40
|
+
response = get request_url("matches/#{match_id}/boxscore")
|
41
|
+
Sportradar::Api::Soccer::Boxscore.new response
|
40
42
|
end
|
41
43
|
|
42
44
|
# team_id = "b78b9f61-0697-4347-a1b6-b7685a130eb1"
|
43
45
|
def team_profile(team_id)
|
44
|
-
get request_url("teams/#{team_id}/profile")
|
46
|
+
response = get request_url("teams/#{team_id}/profile")
|
47
|
+
Sportradar::Api::Soccer::Team.new response["profile"]["team"] if response.success?
|
45
48
|
end
|
46
49
|
|
47
|
-
def team_standings
|
48
|
-
get request_url("teams/standing")
|
49
|
-
end
|
50
50
|
|
51
51
|
# player_id = "2aeacd39-3f9c-42af-957e-9df8573973c4"
|
52
52
|
def player_profile(player_id)
|
53
|
-
get request_url("players/#{player_id}/profile")
|
53
|
+
response = get request_url("players/#{player_id}/profile")
|
54
|
+
Sportradar::Api::Soccer::Player.new response["profile"]["player"] if response.success? && response["profile"] && response["profile"]["player"]
|
54
55
|
end
|
55
56
|
|
56
57
|
def player_rankings
|
57
58
|
get request_url("players/leader")
|
58
59
|
end
|
59
60
|
|
61
|
+
def team_hierarchy
|
62
|
+
get request_url("teams/hierarchy")
|
63
|
+
end
|
64
|
+
|
65
|
+
def team_standings
|
66
|
+
get request_url("teams/standing")
|
67
|
+
end
|
68
|
+
|
60
69
|
private
|
61
70
|
|
62
71
|
def request_url(path)
|
@@ -68,15 +77,15 @@ module Sportradar
|
|
68
77
|
end
|
69
78
|
|
70
79
|
def version
|
71
|
-
Sportradar::Api.version(
|
80
|
+
Sportradar::Api.version("soccer")
|
72
81
|
end
|
73
82
|
|
74
83
|
def allowed_access_levels
|
75
|
-
[
|
84
|
+
["p", "t"]
|
76
85
|
end
|
77
86
|
|
78
87
|
def allowed_leagues
|
79
|
-
[
|
88
|
+
["eu", "na", "sa", "wc", "as", "af"]
|
80
89
|
end
|
81
90
|
end
|
82
91
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Sportradar
|
2
|
+
module Api
|
3
|
+
class Soccer::Boxscore
|
4
|
+
attr_accessor :response, :updated_at, :matches
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@updated_at = data["boxscore"]["generated"]
|
8
|
+
@response = data
|
9
|
+
set_matches
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def set_matches
|
14
|
+
if response["boxscore"]["matches"]["match"]
|
15
|
+
if response["boxscore"]["matches"]["match"].is_a?(Array)
|
16
|
+
@matches = response["boxscore"]["matches"]["match"].map {|x| Sportradar::Api::Soccer::Match.new x }
|
17
|
+
elsif response["boxscore"]["matches"]["match"].is_a?(Hash)
|
18
|
+
@matches = [ Sportradar::Api::Soccer::Match.new(response["boxscore"]["matches"]["match"]) ]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Sportradar
|
2
|
+
module Api
|
3
|
+
class Soccer::Match
|
4
|
+
|
5
|
+
attr_accessor :id, :status, :scheduled, :scratched, :season_id, :reference_id, :category, :tournament_group, :tournament, :home, :away, :venue, :round, :coverage, :period, :clock, :referee, :facts, :response
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@id = data["id"]
|
9
|
+
@reference_id = data["reference_id"]
|
10
|
+
@scheduled = Date.parse data["scheduled"]
|
11
|
+
@scratched = data["scratched"] == "true"
|
12
|
+
@season_id = data["season_id"]
|
13
|
+
@status = data["status"]
|
14
|
+
@category = OpenStruct.new data["category"]
|
15
|
+
@coverage = OpenStruct.new data["coverage"]
|
16
|
+
@round = OpenStruct.new data["round"]
|
17
|
+
@tournament = OpenStruct.new data["tournament"]
|
18
|
+
@tournament_group = OpenStruct.new data["tournament_group"]
|
19
|
+
|
20
|
+
@away = Sportradar::Api::Soccer::Team.new data["away"]
|
21
|
+
@home = Sportradar::Api::Soccer::Team.new data["home"]
|
22
|
+
@venue = Sportradar::Api::Soccer::Venue.new data["venue"] if data["venue"]
|
23
|
+
|
24
|
+
# Actual stats from match summary
|
25
|
+
@period = data["period"]
|
26
|
+
@clock = data["clock"]
|
27
|
+
@referee = OpenStruct.new data["referee"] if data["referee"]
|
28
|
+
@facts = data["facts"]["fact"].map {|fact| OpenStruct.new fact } if data["facts"]
|
29
|
+
@response = data
|
30
|
+
end
|
31
|
+
|
32
|
+
def period_name
|
33
|
+
period_names = {"P1" => "Period one", "H" => "Halftime", "P2" => "Period two", "PX1" => "Pre-extra time one", "X1" => "Extra time one", "PX2" => "Pre-extra time two", "X2" => "Extra time two", "PP" => "Pre-penalty", "P" => "Penalty"}
|
34
|
+
period_names[period] if period
|
35
|
+
end
|
36
|
+
|
37
|
+
def status_description
|
38
|
+
status_descriptions = {"scheduled" => "The match is scheduled to be played", "inprogress" => "The match is currently in progress", "postponed" => "The match has been postponed to a future date", "delayed" => "The match has been temporarily delayed and will be continued", "canceled" => "The match has been canceled and will not be played", "closed" => "The match is over"}
|
39
|
+
status_descriptions[status] if status
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Sportradar
|
2
|
+
module Api
|
3
|
+
class Soccer::Player
|
4
|
+
|
5
|
+
attr_accessor :id, :first_name, :last_name, :country_code, :country, :reference_id, :full_first_name, :full_last_name, :position, :started, :jersey_number, :tactical_position, :tactical_order, :statistics, :preferred_foot, :birthdate, :height_in, :weight_lb, :height_cm, :weight_kg, :teams, :response
|
6
|
+
|
7
|
+
|
8
|
+
def initialize(data)
|
9
|
+
@id = data["id"]
|
10
|
+
@first_name = data["first_name"]
|
11
|
+
@last_name = data["last_name"]
|
12
|
+
@country_code = data["country_code"]
|
13
|
+
@country = data["country"]
|
14
|
+
@reference_id = data["reference_id"]
|
15
|
+
@full_first_name = data["full_first_name"]
|
16
|
+
@full_last_name = data["full_last_name"]
|
17
|
+
@position = data["position"]
|
18
|
+
@started = data["started"]
|
19
|
+
@jersey_number = data["jersey_number"]
|
20
|
+
@tactical_position = data["tactical_position"]
|
21
|
+
@tactical_order = data["tactical_order"]
|
22
|
+
|
23
|
+
# profile
|
24
|
+
@preferred_foot = data["preferred_foot"]
|
25
|
+
@birthdate = data["birthdate"]
|
26
|
+
@height_in = data["height_in"]
|
27
|
+
@weight_lb = data["weight_lb"]
|
28
|
+
@height_cm = data["height_cm"]
|
29
|
+
@weight_kg = data["weight_kg"]
|
30
|
+
@teams = data["teams"]["team"].map {|team| Sportradar::Api::Soccer::Team.new team } if data["teams"]
|
31
|
+
|
32
|
+
@statistics = OpenStruct.new data["statistics"] if data["statistics"]
|
33
|
+
@response = data
|
34
|
+
end
|
35
|
+
|
36
|
+
def position_name
|
37
|
+
positions = {"G" => "Goalie", "D" => "Defender", "M" => "Midfielder", "F" => "Forward"}
|
38
|
+
positions[position] if position
|
39
|
+
end
|
40
|
+
|
41
|
+
def tactical_position_name
|
42
|
+
tactical_positions = { "0" => "Unknown", "1" => "Goalkeeper", "2" => "Right back", "3" => "Central defender", "4" => "Left back", "5" => "Right winger", "6" => "Central midfielder", "7" => "Left winger", "8" => "Forward" }
|
43
|
+
tactical_positions[tactical_position] if tactical_position
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Sportradar
|
2
|
+
module Api
|
3
|
+
class Soccer::Schedule
|
4
|
+
attr_accessor :response, :updated_at, :matches
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@updated_at = data["schedule"]["generated"]
|
8
|
+
@matches = data["schedule"]["matches"]["match"].map {|x| Sportradar::Api::Soccer::Match.new x } if data["schedule"]["matches"]["match"]
|
9
|
+
@response = data
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Sportradar
|
2
|
+
module Api
|
3
|
+
class Soccer::Summary
|
4
|
+
attr_accessor :response, :updated_at, :matches
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@updated_at = data["summary"]["generated"]
|
8
|
+
@response = data
|
9
|
+
set_matches
|
10
|
+
|
11
|
+
end
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_matches
|
15
|
+
if response["summary"]["matches"]["match"]
|
16
|
+
if response["summary"]["matches"]["match"].is_a?(Array)
|
17
|
+
@matches = response["summary"]["matches"]["match"].map {|x| Sportradar::Api::Soccer::Match.new x }
|
18
|
+
elsif response["summary"]["matches"]["match"].is_a?(Hash)
|
19
|
+
@matches = [ Sportradar::Api::Soccer::Match.new(response["summary"]["matches"]["match"]) ]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Sportradar
|
2
|
+
module Api
|
3
|
+
class Soccer::Team
|
4
|
+
|
5
|
+
attr_accessor :id, :name, :full_name, :alias, :country_code, :country, :type, :reference_id, :formation, :score, :regular_score, :penalty_score, :winner, :scoring, :statistics, :first_half_score, :second_half_score, :players, :manager, :roster, :jersey_number, :position, :is_player, :is_manager, :response
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@id = data["id"]
|
9
|
+
@reference_id = data["reference_id"]
|
10
|
+
@id = data["id"]
|
11
|
+
@name = data["name"]
|
12
|
+
@full_name = data["full_name"]
|
13
|
+
@alias = data["alias"]
|
14
|
+
@country_code = data["country_code"]
|
15
|
+
@country = data["country"]
|
16
|
+
@type = data["type"]
|
17
|
+
@reference_id = data["reference_id"]
|
18
|
+
@formation = data["formation"]
|
19
|
+
@score = data["score"]
|
20
|
+
@regular_score = data["regular_score"]
|
21
|
+
@penalty_score = data["penalty_score"]
|
22
|
+
@winner = data["winner"]
|
23
|
+
@scoring = OpenStruct.new data["scoring"]
|
24
|
+
@first_half_score = data["scoring"]["half"].find {|x| x["number"] == "1"}["points"] if data["scoring"]
|
25
|
+
@second_half_score = data["scoring"]["half"].find {|x| x["number"] == "2"}["points"] if data["scoring"]
|
26
|
+
@statistics = OpenStruct.new data["statistics"] if data["statistics"]
|
27
|
+
@players = data["players"]["player"].map {|player| Sportradar::Api::Soccer::Player.new player } if data["players"]
|
28
|
+
|
29
|
+
@players = data["roster"]["player"].map {|player| Sportradar::Api::Soccer::Player.new player } if data["roster"]
|
30
|
+
@manager = Sportradar::Api::Soccer::Player.new data["manager"] if data["manager"]
|
31
|
+
|
32
|
+
# player teams info
|
33
|
+
@jersey_number = data["jersey_number"]
|
34
|
+
@position = data["position"]
|
35
|
+
@is_player = data["is_player"]
|
36
|
+
@is_manager = data["is_manager"]
|
37
|
+
|
38
|
+
@response = data
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :roster, :players
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sportradar
|
2
|
+
module Api
|
3
|
+
class Soccer::Venue
|
4
|
+
|
5
|
+
attr_accessor :id, :name, :country_code, :country, :city, :capacity, :coordinates, :reference_id, :response
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@id = data["id"]
|
9
|
+
@name = data["name"]
|
10
|
+
@country_code = data["country_code"]
|
11
|
+
@country = data["country"]
|
12
|
+
@city = data["city"]
|
13
|
+
@capacity = data["capacity"]
|
14
|
+
@coordinates = data["coordinates"]
|
15
|
+
@reference_id = data["reference_id"]
|
16
|
+
@response = data
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportradar-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Eggett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -220,6 +220,13 @@ files:
|
|
220
220
|
- lib/sportradar/api/odds.rb
|
221
221
|
- lib/sportradar/api/request.rb
|
222
222
|
- lib/sportradar/api/soccer.rb
|
223
|
+
- lib/sportradar/api/soccer/boxscore.rb
|
224
|
+
- lib/sportradar/api/soccer/match.rb
|
225
|
+
- lib/sportradar/api/soccer/player.rb
|
226
|
+
- lib/sportradar/api/soccer/schedule.rb
|
227
|
+
- lib/sportradar/api/soccer/summary.rb
|
228
|
+
- lib/sportradar/api/soccer/team.rb
|
229
|
+
- lib/sportradar/api/soccer/venue.rb
|
223
230
|
- lib/sportradar/api/version.rb
|
224
231
|
- sportradar-api.gemspec
|
225
232
|
homepage: https://github.com/beneggett/sportradar-api
|