fotmob 0.0.1 → 0.1.0
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 +4 -4
- data/CHANGELOG.md +55 -0
- data/LICENSE +21 -0
- data/README.md +209 -0
- data/lib/fotmob/client.rb +157 -0
- data/lib/fotmob/error.rb +29 -0
- data/lib/fotmob/version.rb +5 -0
- data/lib/fotmob.rb +16 -43
- metadata +67 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc5115b39ae5263043d1efc3a66205b9e005c978c442d7aa9c246065b80fdbfb
|
|
4
|
+
data.tar.gz: 02461ba1b0750f0614df5ad2baf18eba734deb810da9a6f99619c0dfa61fefe0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cfe6fc4a515cb3ef0431a3c7d62ce94227c2c4eb78d925489e2051e1f8fe3b0af84ad399a845272860e5449a868e991e54058dc6a6393934fbf9c2d8e3ca000
|
|
7
|
+
data.tar.gz: 82c1c31b13f588eff307b5283f1b6fb9c571bf2ae5e3844f6feb0a296fd51bcbff9940aff9f185d6a4c939be76f3fe62c9a65ed05eed8004c1fcde7c7cc55901
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-01-15
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Version bump for first stable release
|
|
12
|
+
- Repository cleanup (removed build artifacts and test files)
|
|
13
|
+
- Added MIT LICENSE file
|
|
14
|
+
- Added CI status badge to README
|
|
15
|
+
|
|
16
|
+
## [0.0.1] - 2026-01-15
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- Initial release of modernized fotmob gem
|
|
20
|
+
- Modern project structure with separate modules
|
|
21
|
+
- Custom error classes (Error, APIError, NotFoundError, RateLimitError, TimeoutError, InvalidResponseError)
|
|
22
|
+
- URI.open-based HTTP client with timeout support
|
|
23
|
+
- Comprehensive error handling with proper HTTP status codes
|
|
24
|
+
- YARD documentation for all public methods
|
|
25
|
+
- RSpec test suite with VCR for API response recording
|
|
26
|
+
- RuboCop linting with sensible defaults
|
|
27
|
+
- GitHub Actions CI for automated testing
|
|
28
|
+
- Gemfile and Rakefile for development workflow
|
|
29
|
+
- Comprehensive README with examples and badges
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- Refactored from single-file to modular structure
|
|
33
|
+
- Improved from basic API wrapper to production-ready gem
|
|
34
|
+
- Switched to symbolized JSON keys for better Ruby idioms
|
|
35
|
+
- Added timeout configuration support
|
|
36
|
+
|
|
37
|
+
### API Methods
|
|
38
|
+
- `get_team(team_id)` - Get team information and statistics
|
|
39
|
+
- `get_match_details(match_id)` - Get detailed match information
|
|
40
|
+
- `get_player(player_id)` - Get player profile and stats
|
|
41
|
+
- `get_league(league_id)` - Get league standings and details
|
|
42
|
+
- `get_matches(date)` - Get matches by date (limited availability)
|
|
43
|
+
|
|
44
|
+
### Technical Details
|
|
45
|
+
- Requires Ruby >= 2.7.0
|
|
46
|
+
- Uses standard library only (no runtime dependencies)
|
|
47
|
+
- Tested on Ruby 2.7, 3.0, 3.1, 3.2, 3.3
|
|
48
|
+
- Bot protection handling via URI.open
|
|
49
|
+
- Configurable timeout (default: 10 seconds)
|
|
50
|
+
|
|
51
|
+
### Known Limitations
|
|
52
|
+
- `get_matches` endpoint requires special authentication headers and may not work reliably
|
|
53
|
+
- API is unofficial and may change without notice
|
|
54
|
+
|
|
55
|
+
[0.0.1]: https://github.com/bjrsti/fotmob/releases/tag/v0.0.1
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Stian Bjørkelo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Fotmob Ruby Gem
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/fotmob)
|
|
4
|
+
[](https://github.com/bjrsti/fotmob/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.ruby-lang.org/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
An unofficial Ruby wrapper for the [FotMob](https://www.fotmob.com/) API. Get football/soccer data including team stats, match details, player information, and league standings.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- 🏆 **Team Data** - Get comprehensive team information and statistics
|
|
13
|
+
- ⚽ **Match Details** - Detailed match information and live scores
|
|
14
|
+
- 👤 **Player Stats** - Player profiles and performance data
|
|
15
|
+
- 📊 **League Standings** - League tables and competition data
|
|
16
|
+
- 🛡️ **Error Handling** - Custom error classes for different scenarios
|
|
17
|
+
- ⏱️ **Timeout Support** - Configurable request timeouts
|
|
18
|
+
- 📝 **Well Documented** - YARD documentation included
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Add to your Gemfile:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
gem 'fotmob'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or install directly:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
gem install fotmob
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
require 'fotmob'
|
|
38
|
+
|
|
39
|
+
# Create a client
|
|
40
|
+
client = Fotmob.new
|
|
41
|
+
|
|
42
|
+
# Get team information
|
|
43
|
+
team = client.get_team("8540") # Palermo
|
|
44
|
+
puts team[:details][:name]
|
|
45
|
+
|
|
46
|
+
# Get match details
|
|
47
|
+
match = client.get_match_details("4193741")
|
|
48
|
+
puts "#{match[:general][:homeTeam][:name]} vs #{match[:general][:awayTeam][:name]}"
|
|
49
|
+
|
|
50
|
+
# Get player data
|
|
51
|
+
player = client.get_player("961995") # Mbappé
|
|
52
|
+
puts player[:name]
|
|
53
|
+
|
|
54
|
+
# Get league standings
|
|
55
|
+
league = client.get_league("47") # Premier League
|
|
56
|
+
puts league[:details][:name]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## API Methods
|
|
60
|
+
|
|
61
|
+
### `get_team(team_id)`
|
|
62
|
+
|
|
63
|
+
Get comprehensive team information.
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
team = client.get_team("8540")
|
|
67
|
+
# Returns: Hash with team details, fixtures, squad, etc.
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### `get_match_details(match_id)`
|
|
71
|
+
|
|
72
|
+
Get detailed match information.
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
match = client.get_match_details("4193741")
|
|
76
|
+
# Returns: Hash with match details, lineups, events, stats
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `get_player(player_id)`
|
|
80
|
+
|
|
81
|
+
Get player profile and statistics.
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
player = client.get_player("961995")
|
|
85
|
+
# Returns: Hash with player info and stats
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### `get_league(league_id)`
|
|
89
|
+
|
|
90
|
+
Get league/competition information.
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
league = client.get_league("47")
|
|
94
|
+
# Returns: Hash with league details and standings
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### `get_matches(date)` ⚠️
|
|
98
|
+
|
|
99
|
+
**Note:** This endpoint currently requires special authentication headers and may not work reliably.
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
matches = client.get_matches("20250114")
|
|
103
|
+
# Returns: Hash with matches for the specified date
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
### Custom Timeout
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
# Default timeout is 10 seconds
|
|
112
|
+
client = Fotmob.new(timeout: 30)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Error Handling
|
|
116
|
+
|
|
117
|
+
The gem includes custom error classes for different scenarios:
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
begin
|
|
121
|
+
team = client.get_team("invalid_id")
|
|
122
|
+
rescue Fotmob::NotFoundError => e
|
|
123
|
+
puts "Team not found: #{e.message}"
|
|
124
|
+
rescue Fotmob::RateLimitError => e
|
|
125
|
+
puts "Rate limit exceeded: #{e.message}"
|
|
126
|
+
rescue Fotmob::TimeoutError => e
|
|
127
|
+
puts "Request timed out: #{e.message}"
|
|
128
|
+
rescue Fotmob::APIError => e
|
|
129
|
+
puts "API error: #{e.message} (Status: #{e.status_code})"
|
|
130
|
+
rescue Fotmob::Error => e
|
|
131
|
+
puts "Error: #{e.message}"
|
|
132
|
+
end
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Error Classes
|
|
136
|
+
|
|
137
|
+
- `Fotmob::Error` - Base error class
|
|
138
|
+
- `Fotmob::APIError` - API returned an error response
|
|
139
|
+
- `Fotmob::NotFoundError` - Resource not found (404)
|
|
140
|
+
- `Fotmob::RateLimitError` - Rate limit exceeded (429)
|
|
141
|
+
- `Fotmob::TimeoutError` - Request timed out
|
|
142
|
+
- `Fotmob::InvalidResponseError` - Invalid JSON response
|
|
143
|
+
|
|
144
|
+
## Development
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Clone the repository
|
|
148
|
+
git clone https://github.com/bjrsti/fotmob.git
|
|
149
|
+
cd fotmob
|
|
150
|
+
|
|
151
|
+
# Install dependencies
|
|
152
|
+
bundle install
|
|
153
|
+
|
|
154
|
+
# Run tests
|
|
155
|
+
bundle exec rspec
|
|
156
|
+
|
|
157
|
+
# Run linter
|
|
158
|
+
bundle exec rubocop
|
|
159
|
+
|
|
160
|
+
# Open console
|
|
161
|
+
bundle exec rake console
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Testing
|
|
165
|
+
|
|
166
|
+
The gem uses RSpec for testing with VCR for recording API responses:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
bundle exec rspec
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Contributing
|
|
173
|
+
|
|
174
|
+
1. Fork it
|
|
175
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
176
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
177
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
178
|
+
5. Create a Pull Request
|
|
179
|
+
|
|
180
|
+
## Finding IDs
|
|
181
|
+
|
|
182
|
+
To use the API, you need IDs for teams, players, matches, and leagues:
|
|
183
|
+
|
|
184
|
+
- **Teams**: Visit [fotmob.com](https://www.fotmob.com/), search for a team, the ID is in the URL
|
|
185
|
+
- Example: `fotmob.com/teams/8540/overview/palermo` → Team ID: `8540`
|
|
186
|
+
- **Players**: Search for a player, ID is in the URL
|
|
187
|
+
- Example: `fotmob.com/players/961995/kylian-mbappe` → Player ID: `961995`
|
|
188
|
+
- **Matches**: Browse matches, ID is in the match URL
|
|
189
|
+
- Example: `fotmob.com/match/4193741` → Match ID: `4193741`
|
|
190
|
+
- **Leagues**: Browse leagues, ID is in the league URL
|
|
191
|
+
- Example: `fotmob.com/leagues/47/overview/premier-league` → League ID: `47`
|
|
192
|
+
|
|
193
|
+
## Disclaimer
|
|
194
|
+
|
|
195
|
+
This is an unofficial API wrapper and is not affiliated with FotMob. Use at your own risk and be mindful of rate limits.
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
200
|
+
|
|
201
|
+
## Author
|
|
202
|
+
|
|
203
|
+
[Stian Bjørkelo](https://github.com/bjrsti)
|
|
204
|
+
|
|
205
|
+
## Links
|
|
206
|
+
|
|
207
|
+
- [RubyGems](https://rubygems.org/gems/fotmob)
|
|
208
|
+
- [GitHub](https://github.com/bjrsti/fotmob)
|
|
209
|
+
- [Issues](https://github.com/bjrsti/fotmob/issues)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open-uri"
|
|
4
|
+
require "json"
|
|
5
|
+
require "uri"
|
|
6
|
+
require "timeout"
|
|
7
|
+
|
|
8
|
+
module Fotmob
|
|
9
|
+
# Main client for interacting with the FotMob API
|
|
10
|
+
class Client
|
|
11
|
+
BASE_URL = "http://www.fotmob.com/api"
|
|
12
|
+
DEFAULT_TIMEOUT = 10 # seconds
|
|
13
|
+
|
|
14
|
+
attr_reader :timeout
|
|
15
|
+
|
|
16
|
+
# Initialize a new FotMob API client
|
|
17
|
+
#
|
|
18
|
+
# @param timeout [Integer] Request timeout in seconds (default: 10)
|
|
19
|
+
def initialize(timeout: DEFAULT_TIMEOUT)
|
|
20
|
+
@timeout = timeout
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Get league/competition data
|
|
24
|
+
#
|
|
25
|
+
# @param league_id [String] The league ID
|
|
26
|
+
# @return [Hash] League data with symbolized keys
|
|
27
|
+
# @raise [Fotmob::Error] If the request fails
|
|
28
|
+
def get_league(league_id)
|
|
29
|
+
get("/leagues", id: league_id)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Get matches for a specific date
|
|
33
|
+
#
|
|
34
|
+
# @param date [String] Date in YYYYMMDD format (e.g., "20221030")
|
|
35
|
+
# @return [Hash] Match data with symbolized keys
|
|
36
|
+
# @raise [Fotmob::Error] If the request fails
|
|
37
|
+
def get_matches(date)
|
|
38
|
+
get("/matches", date: date)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Get detailed information about a specific match
|
|
42
|
+
#
|
|
43
|
+
# @param match_id [String] The match ID
|
|
44
|
+
# @return [Hash] Match details with symbolized keys
|
|
45
|
+
# @raise [Fotmob::Error] If the request fails
|
|
46
|
+
def get_match_details(match_id)
|
|
47
|
+
get("/matchDetails", matchId: match_id)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Get player data and statistics
|
|
51
|
+
#
|
|
52
|
+
# @param player_id [String] The player ID
|
|
53
|
+
# @return [Hash] Player data with symbolized keys
|
|
54
|
+
# @raise [Fotmob::Error] If the request fails
|
|
55
|
+
def get_player(player_id)
|
|
56
|
+
get("/playerData", id: player_id)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Get team data and statistics
|
|
60
|
+
#
|
|
61
|
+
# @param team_id [String] The team ID
|
|
62
|
+
# @return [Hash] Team data with symbolized keys
|
|
63
|
+
# @raise [Fotmob::Error] If the request fails
|
|
64
|
+
def get_team(team_id)
|
|
65
|
+
get("/teams", id: team_id)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
# Make a GET request to the FotMob API
|
|
71
|
+
#
|
|
72
|
+
# @param path [String] API endpoint path
|
|
73
|
+
# @param params [Hash] Query parameters
|
|
74
|
+
# @return [Hash] Parsed JSON response with symbolized keys
|
|
75
|
+
# @raise [Fotmob::Error] If the request fails
|
|
76
|
+
def get(path, **params)
|
|
77
|
+
uri = build_uri(path, params)
|
|
78
|
+
response_body = fetch_with_timeout(uri)
|
|
79
|
+
parse_json(response_body)
|
|
80
|
+
rescue OpenURI::HTTPError => e
|
|
81
|
+
handle_http_error(e)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Build URI with query parameters
|
|
85
|
+
def build_uri(path, params)
|
|
86
|
+
# Use string concatenation like old version - URI.join doesn't work with /api/path
|
|
87
|
+
url = BASE_URL + path
|
|
88
|
+
uri = URI(url)
|
|
89
|
+
uri.query = URI.encode_www_form(params) unless params.empty?
|
|
90
|
+
uri
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Fetch URL with timeout using URI.open (avoids bot detection)
|
|
94
|
+
def fetch_with_timeout(uri)
|
|
95
|
+
Timeout.timeout(@timeout) do
|
|
96
|
+
URI.open(uri.to_s).read
|
|
97
|
+
end
|
|
98
|
+
rescue Timeout::Error => e
|
|
99
|
+
raise TimeoutError, "Request timed out after #{@timeout} seconds: #{e.message}"
|
|
100
|
+
rescue OpenURI::HTTPError
|
|
101
|
+
# Let HTTP errors bubble up to be handled by the caller
|
|
102
|
+
raise
|
|
103
|
+
rescue StandardError => e
|
|
104
|
+
raise Error, "Network error: #{e.message}"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Handle HTTP errors from URI.open
|
|
108
|
+
def handle_http_error(error)
|
|
109
|
+
status = error.io.status[0].to_i
|
|
110
|
+
body = begin
|
|
111
|
+
error.io.read
|
|
112
|
+
rescue StandardError
|
|
113
|
+
""
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
case status
|
|
117
|
+
when 404
|
|
118
|
+
raise NotFoundError.new(
|
|
119
|
+
"Resource not found",
|
|
120
|
+
status_code: 404,
|
|
121
|
+
response_body: body
|
|
122
|
+
)
|
|
123
|
+
when 429
|
|
124
|
+
raise RateLimitError.new(
|
|
125
|
+
"Rate limit exceeded. Please try again later.",
|
|
126
|
+
status_code: 429,
|
|
127
|
+
response_body: body
|
|
128
|
+
)
|
|
129
|
+
when 400..499
|
|
130
|
+
raise APIError.new(
|
|
131
|
+
"Client error: #{status}",
|
|
132
|
+
status_code: status,
|
|
133
|
+
response_body: body
|
|
134
|
+
)
|
|
135
|
+
when 500..599
|
|
136
|
+
raise APIError.new(
|
|
137
|
+
"Server error: #{status}",
|
|
138
|
+
status_code: status,
|
|
139
|
+
response_body: body
|
|
140
|
+
)
|
|
141
|
+
else
|
|
142
|
+
raise APIError.new(
|
|
143
|
+
"HTTP Error: #{status}",
|
|
144
|
+
status_code: status,
|
|
145
|
+
response_body: body
|
|
146
|
+
)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Parse JSON response with symbolized keys
|
|
151
|
+
def parse_json(body)
|
|
152
|
+
JSON.parse(body, symbolize_names: true)
|
|
153
|
+
rescue JSON::ParserError => e
|
|
154
|
+
raise InvalidResponseError, "Failed to parse response: #{e.message}"
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
data/lib/fotmob/error.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fotmob
|
|
4
|
+
# Base error class for all Fotmob errors
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
7
|
+
# Raised when the API returns an error response
|
|
8
|
+
class APIError < Error
|
|
9
|
+
attr_reader :status_code, :response_body
|
|
10
|
+
|
|
11
|
+
def initialize(message, status_code: nil, response_body: nil)
|
|
12
|
+
@status_code = status_code
|
|
13
|
+
@response_body = response_body
|
|
14
|
+
super(message)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Raised when a resource is not found (404)
|
|
19
|
+
class NotFoundError < APIError; end
|
|
20
|
+
|
|
21
|
+
# Raised when rate limit is exceeded (429)
|
|
22
|
+
class RateLimitError < APIError; end
|
|
23
|
+
|
|
24
|
+
# Raised when the request times out
|
|
25
|
+
class TimeoutError < Error; end
|
|
26
|
+
|
|
27
|
+
# Raised when the response cannot be parsed or is invalid
|
|
28
|
+
class InvalidResponseError < Error; end
|
|
29
|
+
end
|
data/lib/fotmob.rb
CHANGED
|
@@ -1,45 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
require 'json'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def get_matches(match_date)
|
|
19
|
-
json = URI.open(MATCHES_URL+match_date).read
|
|
20
|
-
symbolize_json(json)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def get_match_details(match_id)
|
|
24
|
-
json = URI.open(MATCH_DETAILS_URL+match_id).read
|
|
25
|
-
symbolize_json(json)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def get_player(player_id)
|
|
29
|
-
json = URI.open(PLAYER_URL+player_id).read
|
|
30
|
-
symbolize_json(json)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def get_team(team_id)
|
|
34
|
-
json = URI.open(TEAMS_URL+team_id).read
|
|
35
|
-
symbolize_json(json)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
def symbolize_json(json)
|
|
42
|
-
JSON.parse(json, :symbolize_names => true)
|
|
3
|
+
require_relative "fotmob/version"
|
|
4
|
+
require_relative "fotmob/error"
|
|
5
|
+
require_relative "fotmob/client"
|
|
6
|
+
|
|
7
|
+
# FotMob API wrapper for Ruby
|
|
8
|
+
module Fotmob
|
|
9
|
+
class << self
|
|
10
|
+
# Create a new client instance
|
|
11
|
+
#
|
|
12
|
+
# @param options [Hash] Client options
|
|
13
|
+
# @return [Fotmob::Client] A new client instance
|
|
14
|
+
def new(**options)
|
|
15
|
+
Client.new(**options)
|
|
16
|
+
end
|
|
43
17
|
end
|
|
44
|
-
|
|
45
|
-
end
|
|
18
|
+
end
|
metadata
CHANGED
|
@@ -1,67 +1,108 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fotmob
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stian Bjørkelo
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: rake
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0
|
|
20
|
-
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: 0.2.0
|
|
23
|
-
type: :runtime
|
|
18
|
+
version: '13.0'
|
|
19
|
+
type: :development
|
|
24
20
|
prerelease: false
|
|
25
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
22
|
requirements:
|
|
27
23
|
- - "~>"
|
|
28
24
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '0
|
|
30
|
-
|
|
25
|
+
version: '13.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rspec
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
32
|
+
version: '3.12'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.12'
|
|
33
40
|
- !ruby/object:Gem::Dependency
|
|
34
|
-
name:
|
|
41
|
+
name: rubocop
|
|
35
42
|
requirement: !ruby/object:Gem::Requirement
|
|
36
43
|
requirements:
|
|
37
44
|
- - "~>"
|
|
38
45
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
40
|
-
|
|
46
|
+
version: '1.50'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
41
52
|
- !ruby/object:Gem::Version
|
|
42
|
-
version:
|
|
43
|
-
|
|
53
|
+
version: '1.50'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: vcr
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '6.1'
|
|
61
|
+
type: :development
|
|
44
62
|
prerelease: false
|
|
45
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
46
64
|
requirements:
|
|
47
65
|
- - "~>"
|
|
48
66
|
- !ruby/object:Gem::Version
|
|
49
|
-
version: '
|
|
50
|
-
|
|
67
|
+
version: '6.1'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: webmock
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '3.18'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
51
80
|
- !ruby/object:Gem::Version
|
|
52
|
-
version:
|
|
53
|
-
description:
|
|
81
|
+
version: '3.18'
|
|
82
|
+
description: A simple Ruby gem for accessing football/soccer data from the FotMob
|
|
83
|
+
API. Get team stats, match details, player data, league tables, and more.
|
|
54
84
|
email: stianbj@gmail.com
|
|
55
85
|
executables: []
|
|
56
86
|
extensions: []
|
|
57
87
|
extra_rdoc_files: []
|
|
58
88
|
files:
|
|
89
|
+
- CHANGELOG.md
|
|
90
|
+
- LICENSE
|
|
91
|
+
- README.md
|
|
59
92
|
- lib/fotmob.rb
|
|
93
|
+
- lib/fotmob/client.rb
|
|
94
|
+
- lib/fotmob/error.rb
|
|
95
|
+
- lib/fotmob/version.rb
|
|
60
96
|
homepage: https://github.com/bjrsti/fotmob
|
|
61
97
|
licenses:
|
|
62
98
|
- MIT
|
|
63
|
-
metadata:
|
|
64
|
-
|
|
99
|
+
metadata:
|
|
100
|
+
homepage_uri: https://github.com/bjrsti/fotmob
|
|
101
|
+
source_code_uri: https://github.com/bjrsti/fotmob
|
|
102
|
+
bug_tracker_uri: https://github.com/bjrsti/fotmob/issues
|
|
103
|
+
changelog_uri: https://github.com/bjrsti/fotmob/blob/main/CHANGELOG.md
|
|
104
|
+
documentation_uri: https://github.com/bjrsti/fotmob#readme
|
|
105
|
+
rubygems_mfa_required: 'true'
|
|
65
106
|
rdoc_options: []
|
|
66
107
|
require_paths:
|
|
67
108
|
- lib
|
|
@@ -69,15 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
69
110
|
requirements:
|
|
70
111
|
- - ">="
|
|
71
112
|
- !ruby/object:Gem::Version
|
|
72
|
-
version:
|
|
113
|
+
version: 2.7.0
|
|
73
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
115
|
requirements:
|
|
75
116
|
- - ">="
|
|
76
117
|
- !ruby/object:Gem::Version
|
|
77
118
|
version: '0'
|
|
78
119
|
requirements: []
|
|
79
|
-
rubygems_version:
|
|
80
|
-
signing_key:
|
|
120
|
+
rubygems_version: 4.0.3
|
|
81
121
|
specification_version: 4
|
|
82
|
-
summary: An unofficial
|
|
122
|
+
summary: An unofficial FotMob API wrapper for Ruby
|
|
83
123
|
test_files: []
|