-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleagues_data.ex
43 lines (30 loc) · 1.79 KB
/
leagues_data.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
defmodule LeaguesData.LeaguesData do
@moduledoc """
Routes data requests to data provider agents depending on the requested output format
Data services with different output formats can be easily added, only requiring the module implements the behaviour LeaguesData.LeaguesDataBehavior and added to the `data_modules:` map in the file config.exs.
"""
@data_services Application.get_env(:leagues_web, :data_modules)
@doc """
Returns a JSON string with a list of all leagues-season pairs.
## Parameters
- format: could be `"json"` or `"protobuff"`, but easily extensible adding more agents and registering them in `data_modules:` map.
## Example
iex> LeaguesData.LeaguesData.leagues("json")
~s([{"season":"201617","league":"D1"},{"season":"201617","league":"E0"},{"season":"201516","league":"SP2"},{"season":"201617","league":"SP2"},{"season":"201516","league":"SP1"},{"season":"201617","league":"SP1"}])
"""
@spec leagues(format :: String.t) :: leagues_season :: any()
def leagues(format), do: @data_services[format].leagues()
@doc """
Returns a JSON string with all the results for a given pair of `league` and `season`.
## Parameters
- format: could be `"json"` or `"protobuff"` string, but easily extensible adding more agents and registering them in `@data_services`
- league: string
- season: string
## Example
iex> res = LeaguesData.LeaguesData.matches("json", "SP1", "201617")
iex> String.slice(res,0,129)
~s([{"homeTeam":"La Coruna","date":"19/08/2016","awayTeam":"Eibar","HTR":"D","HTHG":"0","HTAG":"0","FTR":"H","FTHG":"2","FTAG":"1"},)
"""
@spec matches(format :: String.t, league :: String.t, season :: String.t) :: matches :: any()
def matches(format, league, season), do: @data_services[format].matches(league, season)
end